Displays
Wide stats display
A wide screen with six live numbers side by side: temperature, feels-like, humidity, wind, rain and pressure.
- Medium
- about 45 min
- ESP32-S3
- 5 parts
- 7 wires
- 94 lines of code
- Uses Wi-Fi
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
One function draws a tile, and it is called six times with different numbers. Change what the tiles show and you have a dashboard for anything a web service can tell you.
What you learn
Laying out a screen as a grid, writing one function and reusing it, and reading several values from JSON.
How it works
input
Weather from the internet
decides
ESP32-S3 · Wi-Fi
output
TFT 2.0 in
Powered with 5 V through the board's USB-C port.
It joins your home Wi-Fi. You type the network name and password into the sketch before uploading; they stay on the board.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 5 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step, with the USB cable unplugged. Several wires may share 3V3, 5V or GND: the expansion board or breadboard gives each its own pin.
Step 0 of 7
Lay out the parts
Seat the board on its expansion board or breadboard and lay the modules out round it. Nothing is connected yet.
All connections
stats-bar.ino
// Wide stats display
// A row of live numbers for your town: temperature, feels-like, humidity,
// wind and rain.
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
// Your town. These are for Ho Chi Minh City.
const float LATITUDE = 10.82;
const float LONGITUDE = 106.63;
const unsigned long REFRESH_MS = 10UL * 60UL * 1000UL;
const int PIN_TFT_SCL = 12;
const int PIN_TFT_SDA = 11;
const int PIN_TFT_RES = 14;
const int PIN_TFT_DC = 13;
const int PIN_TFT_CS = 10;
Adafruit_ST7789 tft(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RES);
unsigned long lastFetch = 0;
bool haveData = false;
void tile(int col, int row, const char* label, float value, const char* unit, uint16_t colour) {
int x = col * 160 + 6;
int y = row * 80 + 6;
tft.fillRoundRect(x, y, 148, 68, 8, 0x18E3);
tft.setTextColor(0xBDF7);
tft.setTextSize(1);
tft.setCursor(x + 10, y + 8);
tft.print(label);
tft.setTextColor(colour);
tft.setTextSize(3);
tft.setCursor(x + 10, y + 28);
tft.print(value, 1);
tft.setTextSize(1);
tft.print(" ");
tft.print(unit);
}
bool fetchStats() {
WiFiClientSecure client;
client.setInsecure();
HTTPClient http;
String url = "https://api.open-meteo.com/v1/forecast?latitude=" + String(LATITUDE, 2) + "&longitude=" + String(LONGITUDE, 2) +
"¤t=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,precipitation,surface_pressure";
if (!http.begin(client, url)) return false;
bool ok = false;
if (http.GET() == 200) {
JsonDocument doc;
if (!deserializeJson(doc, http.getString())) {
JsonObject now = doc["current"];
tft.fillScreen(ST77XX_BLACK);
tile(0, 0, "TEMPERATURE", now["temperature_2m"], "C", ST77XX_ORANGE);
tile(1, 0, "FEELS LIKE", now["apparent_temperature"], "C", ST77XX_YELLOW);
tile(0, 1, "HUMIDITY", now["relative_humidity_2m"], "%", ST77XX_CYAN);
tile(1, 1, "WIND", now["wind_speed_10m"], "km/h", ST77XX_WHITE);
tile(0, 2, "RAIN", now["precipitation"], "mm", 0x5D1F);
tile(1, 2, "PRESSURE", now["surface_pressure"], "hPa", ST77XX_GREEN);
ok = true;
}
}
http.end();
return ok;
}
void setup() {
SPI.begin(PIN_TFT_SCL, -1, PIN_TFT_SDA, PIN_TFT_CS);
tft.init(240, 320);
tft.setRotation(1); // landscape: 320 wide, 240 high
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.setCursor(20, 110);
tft.print("Wi-Fi...");
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(250);
}
void loop() {
if (!haveData || millis() - lastFetch > REFRESH_MS) {
if (fetchStats()) haveData = true;
lastFetch = millis();
if (!haveData) delay(10000);
}
delay(200);
}
Libraries
- ArduinoJson: install it from Sketch > Include Library > Manage Libraries.
- Adafruit GFX Library: install it from Sketch > Include Library > Manage Libraries.
- Adafruit ST7735 and ST7789 Library: install it from Sketch > Include Library > Manage Libraries.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Before uploading, type your Wi-Fi name and password into WIFI_SSID and WIFI_PASS at the top of the sketch.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32S3 Dev Module, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.