ESP32-C3 TFT Display
--------- -------------
GND → GND
3.3V → VCC
GPIO 4 → SCL
GPIO 6 → SDA
GPIO 8 → RES
GPIO 9 → DC
GPIO 10 → CS
3.3V → BLK
CODE
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
// TFT Pins (adjust if needed)
#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
// WiFi
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";
// OpenWeather
String apiKey = "YOUR_API_KEY";
String city = "London";
String countryCode = "GB";
String weatherURL;
// Colors
#define BLACK 0x0000
#define BLUE 0x001F
#define WHITE 0xFFFF
#define YELLOW 0xFFE0
#define GREEN 0x07E0
#define RED 0xF800
// Variables
String weatherMain;
float temp;
int humidity;
float windSpeed;
void setup() {
Serial.begin(115200);
tft.initR(INITR_MINI160x80);
tft.setRotation(1);
tft.fillScreen(BLACK);
WiFi.begin(ssid, password);
tft.setTextColor(WHITE);
tft.setCursor(10, 30);
tft.print("Connecting WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
tft.fillScreen(BLACK);
tft.setCursor(10, 30);
tft.print("Connected!");
delay(1000);
}
void loop() {
getWeather();
displayWeather();
delay(10000); // refresh every 10 sec
}
void getWeather() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
weatherURL = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + countryCode + "&appid=" + apiKey + "&units=metric";
http.begin(weatherURL);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
DynamicJsonDocument doc(2048);
deserializeJson(doc, payload);
weatherMain = doc["weather"][0]["main"].as<String>();
temp = doc["main"]["temp"];
humidity = doc["main"]["humidity"];
windSpeed = doc["wind"]["speed"];
} else {
Serial.println("Error fetching weather");
}
http.end();
}
}
void displayWeather() {
tft.fillScreen(BLACK);
// City + Day
tft.setTextSize(1);
tft.setTextColor(WHITE);
tft.setCursor(5, 5);
tft.print(city);
tft.setCursor(80, 5);
tft.print("Friday");
// Weather Type
tft.setCursor(5, 20);
tft.print(weatherMain);
// Date
tft.setCursor(80, 20);
tft.print("13/03/2026");
// Time (Fake for now)
tft.setTextSize(2);
tft.setTextColor(YELLOW);
tft.setCursor(10, 40);
tft.print("12:00");
// Wind
tft.setTextSize(1);
tft.setTextColor(WHITE);
tft.setCursor(5, 65);
tft.print("Wind:");
tft.print(windSpeed);
tft.print("m/s");
// Temp
tft.setCursor(70, 65);
tft.setTextColor(RED);
tft.print("Temp:");
tft.print(temp);
tft.print("C");
// Humidity
tft.setCursor(70, 75);
tft.setTextColor(GREEN);
tft.print("Humi:");
tft.print(humidity);
tft.print("%");
}