Skip to content

Instantly share code, notes, and snippets.

@christianhent
Last active November 15, 2022 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianhent/35749db334b14a221fd9d6f8debf4021 to your computer and use it in GitHub Desktop.
Save christianhent/35749db334b14a221fd9d6f8debf4021 to your computer and use it in GitHub Desktop.

ESP32.LINKSTATION 2

linkstation.mp4

What it is and how it works

An ESP32 WiFi cryptomonitor to display cryptocurrency prices based on quotes obtained via cryptocompare.com API. The code built on top of the Arduino framework is even for beginners easy to customize.

TOC

Features overview

main
  • real-time quotes for cryptocurrencies
    • BTC, ETH, LINK, ADA (default values)
    • 24h price change in %
  • current date and time
  • graphical logos in 3 sizes (only for Chainlink implemented)
code
  • factored, easy to extend
  • every displayed page is a own function
  • static defined text strings
  • 2 text sizes

Components and supplies

IDE and libraries

Code was written with platformIO/Atom, this means you have to alter the provided code before you can compile it using the Arduino IDE. Here is a quick guide on how to install the PlatformIO IDE package for Atom. It is assumed in this tutorial that you have installed platformIO/Atom and that your board is supported.

Regardless of your IDE you also have to install some additional libraries:

Project setup

Before you explore the hardware components, breadboard arrangement and wiring, set up as first the code barebone of the project:

  1. Click on the PlatformIO Home button on the PlatformIO toolbar
  2. Click on New Project
  3. Name your project
  4. Search/Select your board
  5. Select Arduino framework
  6. Hit the Finish button

projekt wizzard

That's a empty but basically working project that you can upload to your board. Next you will add the required libraries to your project:

  1. Click on the PlatformIO Home button on the PlatformIO Toolbar
  2. Click on Libraries to open the library manager and search for Adafruit GFX
  3. Click the result Adafruit GFX library
  4. Click on the Installation tab
  5. Hit the Add to project button

install_lib

Repeat the steps 2. - 4. To add the libraries Adafruit SSD1306 and ArduinoJson.

Your platformio.ini project file should now look like this:

[env:az-delivery-devkit-v4]
platform = espressif32
board = az-delivery-devkit-v4
upload_port = /dev/ttyUSB0
framework = arduino
lib_deps =
	adafruit/Adafruit GFX Library@^1.10.12
	adafruit/Adafruit SSD1306@^2.4.7
	bblanchon/ArduinoJson@^6.18.5

It's still a empty project but everything further is just to copy & paste the content of the attached main.cpp file and to adjust some variable values. Stick to the code later. Focus now on hardware components, breadboard arrangement and wiring.

Breadboard and wires

ESP32 boards have many outstanding features, but the dimensions are known to be not one of them. Many people consider them to be breadboard unfriendly because when prototyping they only leaves 1 row of available pinholes on the board. But that's not a big issue for this project. Just do the wiring first and then add the components to the breadboard. Use a half-size breadboard because it fits nearly perfect. The double-strip in the middle is ideal to hide the display wires. Pull of the power rails on both sides to make it as thin as possible.

You can try dozens of different types of wire, but you will end up coming to the same conclusion as most users: The best wire for breadboards is simple solid core wire, like the ordinary bell wire listet in the components list.

I2C OLED display

There are some benefits using a OLED display:

  • I2C needs only 4 wires (GND, VCC, SCL, SDA)
  • graphic displays, not limited to text
  • high resolution and very legible
  • low power, no backlight needed
  • useable without external power supply (3.3V)
  • fast refresh rates
  • space-saving and not bulky
  • popular Adafruit SSD1306 library

The ESP32 has two I2C bus interfaces. Using I2C communication protocol, wiring is as simple as connecting GND to GND, SDA to SDA, SCL to SCL and a positive power supply to a peripheral, usually 3.3V:

OLED Pin ESP32 Pin
GND GND
VCC 3V3
SCL 22
SDA 21

ESP32_OLED

Wiring

You know enough about connecting the ESP32 and the OLED display. Start now wiring the breadboard. Try bell wire to achieve this and stick to the wiring sketch exactly, the colors of the wires are of course irrelevant.

breadboard_ESP32_SSD1306_OLED

Then plug the display and the ESP32 into the breadboard. Be sure to use the correct pinholes:

  • Display: a1 - a4
  • ESP32: a30 - a12 and i30 - i12

breadboard_ESP32_SSD1306_OLED_2

Connect the ESP32 to your computer using the usual USB cable. Congrats, you are done with the hardware part.

Setup WiFi & API, upload

To bring your new cryptostation to life, you have to add some code to it. You already created the project and installed all the necessary libraries. Now copy & paste the attached code into your main.cpp file, adjust the values for your WiFi connection (line 89-90) & cryptocompare API key (line 103) and upload the project to your ESP32 board.

const char *SSID = "xxx";
const char *PASSWORD = "xxx";

String apiKey = "xxx";

main.cpp is stored inside the src directory of your project. When you create a project, platformIO automatically adds some required definitions and functions to main.cpp, remove these before pasting the code. Compile and upload task can take a while. If everything goes right, you will soon see the Chainlink logo.

Customization

If you get past the hurdle of installing the IDE and libraries, customization will not be a hard challenge. Following happens inside the Arduino main loop:

  1. setup() configs the data filter
  2. update() loads data from API
  3. setData() prepares data for rendering
  4. displayPages(), showPage__CRYPTO() displays data, e.g. showPage__BTC()

The display output is implemented inside displayPages() (line 271-283). Within a for loop which defines the number of repetitions shown on the OLED display, separate functions are called for each cryptocurrency to display their data on a individual "page". This means more code, but it's easier to maintain.

// Display loop
  for (int count = 0; count <= 1; count++) //2
  {
    if (cryptocompare_httpCode == 200)
    {
      showPage_BTC();
      showPage_ETH();
      showPage_LINK();
      showPage_ADA();
      
    }
  }

This is what you have to keep in mind if you want to customize the program:

Customize Variables Functions
URL-Endpoint String apiSyms, line 102
Data e.g. double price_BTC, line 107 setup(), line 326 - 333
Data setData(), line 286 - 305
Display e.g. const char *CRYPTO_BTC, line 18 displayPages(), line 271 - 283
Display e.g. showPage_BTC(), line 174 - 195

Graphical logos

When you turn on your ESP32 you will see a big Chainlink logo and also a small one on the LINK page. This "images" are stored in flash memory (PROGMEM) (line 26, 57, 68). You can delete the corresponding code or replace the code with your desired graphic.

Read more about the used Adafruit GFX library function and feel encouraged to learn more about the graphics library to get more out of your OLED display. Use image2cpp to convert an image into Arduino C code, it's the best tool you will find.

Code example to output a graphic: (line 228):

...
display_1.drawBitmap(105, 0, logo_link_xs, 12, 13, WHITE);
...

Acrylic case

A simple case can be put together quickly. You need two acrylic sheets with 3mm holes and some color anodized M3 screws & spacers. The acrylic sheets can be ordered online (German supplier, good quality), cut to size and drilled. Make sure that the sheets are laser cut and properly deburred. Nice spacers and screws of decent quality you will find at a well-sorted RC helicopter and drone shop.

The rear of most breadboards is self-adhesive. Simply stick the pre-wired breadboard to the rear acrylic sheet, plug the components into the breadboard and screw finally both sheets tightly using the screws and spacers.

acryl

Case components

  • 1x acrylic sheet 10mm (back)
    • 120mm x 60mm x 3mm
    • 3mm holes, 5mm between center of hole and edge
  • 1x acrylic plate 3mm (front)
    • 120mm x 60mm x 3mm
    • 3mm holes, 5mm between center of hole and edge
  • 4x color anodized M3 spacers 20mm
  • 8x color anodized M3 screws 16mm (M3x16)

Thank you

Thank you for reading this very long tutorial. Hope you enjoyed it to built your own cryptostation. If you have code reladed questions, comment here or contact me on twitter.

#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#include "time.h"
#include <HTTPClient.h>
#include <ArduinoJson.h>
/* Display texts */
const char *NAME = "ESP.LINKSTATION 2";
const char *VERSION = "2.10";
const char *INFORMATION = "cryptocompare.com";
const char *CONNECT = "connect to WiFi";
const char *CONNECTED = "connected to WiFi";
const char *UPDATE = "load data";
const char *CRYPTO_BTC = "BTC/USD";
const char *CRYPTO_ETH = "ETH/USD";
const char *CRYPTO_LINK = "LINK/USD";
const char *CRYPTO_ADA = "ADA/USD";
const char *CHANGE24H = "Change 24h";
const char *PERCENT = " %";
/* Chainlink logos*/
const unsigned char PROGMEM logo_link_m[] = {
// 55x64px
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff,
0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xf8, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x07, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x3f, 0xff,
0xff, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x03, 0xff, 0xff, 0xc7, 0xff,
0xff, 0x80, 0x07, 0xff, 0xff, 0x83, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xfe, 0x00, 0xff, 0xff, 0xf0,
0x7f, 0xff, 0xf8, 0x00, 0x3f, 0xff, 0xfc, 0x7f, 0xff, 0xe0, 0x00, 0x0f, 0xff, 0xfc, 0x7f, 0xff,
0xc0, 0x00, 0x07, 0xff, 0xfc, 0x7f, 0xff, 0x00, 0x00, 0x01, 0xff, 0xfc, 0x7f, 0xfc, 0x00, 0x00,
0x00, 0x7f, 0xfc, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f,
0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f,
0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00,
0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00,
0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc,
0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0,
0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00,
0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f,
0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f,
0xe0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x7f, 0xfc, 0x00,
0x00, 0x00, 0x7f, 0xfc, 0x7f, 0xff, 0x00, 0x00, 0x01, 0xff, 0xfc, 0x7f, 0xff, 0xc0, 0x00, 0x07,
0xff, 0xfc, 0x7f, 0xff, 0xe0, 0x00, 0x0f, 0xff, 0xfc, 0x7f, 0xff, 0xf8, 0x00, 0x3f, 0xff, 0xfc,
0x1f, 0xff, 0xfe, 0x00, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0x83, 0xff, 0xff, 0xc0, 0x03, 0xff,
0xff, 0xc7, 0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff,
0xff, 0xf8, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xc0,
0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00,
0x00, 0x3f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x03,
0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0
};
const unsigned char PROGMEM logo_link_s[] = {
// 25x29px
0x00, 0x1c, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0xff, 0x80, 0x00, 0x01, 0xff, 0xc0, 0x00,
0x07, 0xff, 0xf0, 0x00, 0x1f, 0xff, 0xfc, 0x00, 0x7f, 0xf7, 0xff, 0x00, 0xff, 0xc1, 0xff, 0x80,
0xff, 0x80, 0xff, 0x80, 0xfe, 0x00, 0x3f, 0x80, 0xf8, 0x00, 0x0f, 0x80, 0xf8, 0x00, 0x0f, 0x80,
0xf8, 0x00, 0x0f, 0x80, 0xf8, 0x00, 0x0f, 0x80, 0xf8, 0x00, 0x0f, 0x80, 0xf8, 0x00, 0x0f, 0x80,
0xf8, 0x00, 0x0f, 0x80, 0xf8, 0x00, 0x0f, 0x80, 0xf8, 0x00, 0x0f, 0x80, 0xfe, 0x00, 0x3f, 0x80,
0xff, 0x80, 0xff, 0x80, 0xff, 0xc1, 0xff, 0x80, 0x7f, 0xf7, 0xff, 0x00, 0x1f, 0xff, 0xfc, 0x00,
0x07, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0x3e, 0x00, 0x00,
0x00, 0x1c, 0x00, 0x00
};
const unsigned char PROGMEM logo_link_xs[] = {
// 12x13px
0x06, 0x00, 0x1f, 0x80, 0x7f, 0xe0, 0xf9, 0xf0, 0xe0, 0x70, 0xc0, 0x30, 0xc0, 0x30, 0xc0, 0x30,
0xe0, 0x70, 0xf9, 0xf0, 0x7f, 0xe0, 0x1f, 0x80, 0x06, 0x00
};
/* Time */
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 3600;
const int daylightOffset_sec = 3600;
struct tm timeinfo;
/* Display & I2C setup */
#define SDA1 21
#define SCL1 22
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
TwoWire I2Cone = TwoWire(0);
Adafruit_SSD1306 display_1(SCREEN_WIDTH, SCREEN_HEIGHT, &I2Cone, -1);
/* WiFi */
const char *SSID = "*******";
const char *PASSWORD = "******";
unsigned long previousMillis = 0;
unsigned long interval = 10000;
/* cryptocompare.com, HTTP & JSON */
HTTPClient cryptocompare_http;
int cryptocompare_httpCode;
StaticJsonDocument<300> cryptocompare_filter;
StaticJsonDocument<500> cryptocompare_doc;
/* API endpoints */
String apiURL = "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=";
String apiSyms = "BTC,ETH,LINK,ADA";
String apiKey = "";
String apiEndpoint = apiURL + apiSyms + String("&tsyms=USD") + String("&api_key=") + apiKey;
/* Data */
double price_BTC;
double change24h_BTC;
double price_ETH;
double change24h_ETH;
double price_LINK;
double change24h_LINK;
double price_ADA;
double change24h_ADA;
/* Display functions */
void showPage_Logo()
{
// custom splash for 3 sec.
display_1.display();
display_1.clearDisplay();
display_1.drawBitmap(33, 0, logo_link_m, 55, 64, WHITE);
display_1.display();
display_1.clearDisplay();
delay(3000);
}
void showPage_About()
{
display_1.clearDisplay();
display_1.setTextSize(1);
display_1.setCursor(10,0);
display_1.print(NAME);
display_1.setCursor(10,15);
display_1.print(INFORMATION);
display_1.setCursor(80,45);
display_1.print("Ver.");
display_1.print(VERSION);
display_1.display();
delay(2500);
}
void showPage_Connect2Wifi()
{
display_1.clearDisplay();
display_1.setTextSize(1);
display_1.setCursor(10,0);
display_1.print(NAME);
display_1.setCursor(10,15);
display_1.print(CONNECT);
display_1.display();
delay(1000);
}
void showPage_Update()
{
display_1.clearDisplay();
display_1.setTextSize(1);
display_1.setCursor(10,0);
display_1.print(NAME);
display_1.setCursor(10,15);
display_1.print(UPDATE);
// Chainlink logo, date & time
display_1.drawBitmap(100, 15, logo_link_s, 25, 29, WHITE);
display_1.setCursor(80,50);
display_1.print(&timeinfo, "%d-%m-%y");
display_1.setCursor(10,50);
display_1.setTextSize(2);
display_1.print(&timeinfo, "%H:%M");
display_1.display();
delay(1500);
}
void showPage_BTC()
{
display_1.clearDisplay();
display_1.setTextSize(1);
display_1.setCursor(10,0);
display_1.print(CRYPTO_BTC);
display_1.setTextSize(2);
display_1.setCursor(10,12);
display_1.print(price_BTC, 0);
display_1.setTextSize(1);
display_1.setCursor(10, 35);
display_1.print(CHANGE24H);
display_1.setTextSize(2);
display_1.setCursor(10, 47);
display_1.print(change24h_BTC);
display_1.setTextSize(1);
display_1.print(PERCENT);
display_1.display();
delay(4000);
display_1.clearDisplay();
display_1.display();
delay(250);
}
void showPage_ETH()
{
display_1.clearDisplay();
display_1.setTextSize(1);
display_1.setCursor(10,0);
display_1.print(CRYPTO_ETH);
display_1.setTextSize(2);
display_1.setCursor(10,12);
display_1.print(price_ETH, 0);
display_1.setTextSize(1);
display_1.setCursor(10, 35);
display_1.print(CHANGE24H);
display_1.setTextSize(2);
display_1.setCursor(10, 47);
display_1.print(change24h_ETH);
display_1.setTextSize(1);
display_1.print(PERCENT);
display_1.display();
delay(4000);
display_1.clearDisplay();
display_1.display();
delay(250);
}
void showPage_LINK()
{
display_1.clearDisplay();
display_1.setTextSize(1);
display_1.setCursor(10,0);
display_1.print(CRYPTO_LINK);
display_1.drawBitmap(105, 0, logo_link_xs, 12, 13, WHITE);
display_1.setTextSize(2);
display_1.setCursor(10,12);
display_1.print(price_LINK, 2);
display_1.setTextSize(1);
display_1.setCursor(10, 35);
display_1.print(CHANGE24H);
display_1.setTextSize(2);
display_1.setCursor(10, 47);
display_1.print(change24h_LINK);
display_1.setTextSize(1);
display_1.print(PERCENT);
display_1.display();
delay(4000);
display_1.clearDisplay();
display_1.display();
delay(250);
}
void showPage_ADA()
{
display_1.clearDisplay();
display_1.setTextSize(1);
display_1.setCursor(10,0);
display_1.print(CRYPTO_ADA);
display_1.setTextSize(2);
display_1.setCursor(10,12);
display_1.print(price_ADA, 2);
display_1.setTextSize(1);
display_1.setCursor(10, 35);
display_1.print(CHANGE24H);
display_1.setTextSize(2);
display_1.setCursor(10, 47);
display_1.print(change24h_ADA);
display_1.setTextSize(1);
display_1.print(PERCENT);
display_1.display();
delay(4000);
display_1.clearDisplay();
display_1.display();
delay(250);
}
void displayPages()
{
// Display loop
for (int count = 0; count <= 1; count++) //2
{
if (cryptocompare_httpCode == 200)
{
showPage_BTC(); // BTC
showPage_ETH(); // ETH
showPage_LINK(); // LINK
showPage_ADA(); // ADA
}
}
}
void setData()
{
DeserializationError error = deserializeJson(
cryptocompare_doc,
cryptocompare_http.getString(),
DeserializationOption::Filter(cryptocompare_filter)
);
if (error) {
return;
}
price_BTC = cryptocompare_doc["RAW"]["BTC"]["USD"]["PRICE"];
change24h_BTC = cryptocompare_doc["RAW"]["BTC"]["USD"]["CHANGEPCT24HOUR"];
price_ETH = cryptocompare_doc["RAW"]["ETH"]["USD"]["PRICE"];
change24h_ETH = cryptocompare_doc["RAW"]["ETH"]["USD"]["CHANGEPCT24HOUR"];
price_LINK = cryptocompare_doc["RAW"]["LINK"]["USD"]["PRICE"];
change24h_LINK = cryptocompare_doc["RAW"]["LINK"]["USD"]["CHANGEPCT24HOUR"];
price_ADA = cryptocompare_doc["RAW"]["ADA"]["USD"]["PRICE"];
change24h_ADA = cryptocompare_doc["RAW"]["ADA"]["USD"]["CHANGEPCT24HOUR"];
}
void update()
{
showPage_Update();
cryptocompare_http.begin(apiEndpoint);
cryptocompare_httpCode = cryptocompare_http.GET();
if (cryptocompare_httpCode == 200 )
{
setData();
}
cryptocompare_http.end();
}
void setup()
{
//Serial.begin(115200);
// cryptocompare.com filter
cryptocompare_filter["RAW"]["BTC"]["USD"]["PRICE"] = true;
cryptocompare_filter["RAW"]["BTC"]["USD"]["CHANGEPCT24HOUR"] = true;
cryptocompare_filter["RAW"]["ETH"]["USD"]["PRICE"] = true;
cryptocompare_filter["RAW"]["ETH"]["USD"]["CHANGEPCT24HOUR"] = true;
cryptocompare_filter["RAW"]["LINK"]["USD"]["PRICE"] = true;
cryptocompare_filter["RAW"]["LINK"]["USD"]["CHANGEPCT24HOUR"] = true;
cryptocompare_filter["RAW"]["ADA"]["USD"]["PRICE"] = true;
cryptocompare_filter["RAW"]["ADA"]["USD"]["CHANGEPCT24HOUR"] = true;
// I2C
I2Cone.begin(SDA1,SCL1,400000); //display_1
// Display
display_1.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display_1.setTextColor(WHITE);
// Logo splash
showPage_Logo();
// About page
showPage_About();
// Connect to WiFi
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
showPage_Connect2Wifi();
}
// WiFi connected, init time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
void loop()
{
unsigned long currentMillis = millis();
if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval))
{
WiFi.disconnect();
WiFi.reconnect();
previousMillis = currentMillis;
}
if ((WiFi.status() == WL_CONNECTED))
{
if(!getLocalTime(&timeinfo))
{
return;
}
update();
displayPages();
}
}
[env:az-delivery-devkit-v4]
platform = espressif32
board = az-delivery-devkit-v4
upload_port = /dev/ttyUSB0
framework = arduino
lib_deps =
adafruit/Adafruit GFX Library@^1.10.12
adafruit/Adafruit SSD1306@^2.4.7
bblanchon/ArduinoJson@^6.18.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment