ESP32-C6 Wi-Fi Weather on an LCD: Wiring, Code and Simulator
To build this ESP32-C6 Wi-Fi Weather on an LCD project you need an ESP32-C6 DevKitC-1 and a 16x2 LCD. The emulated ESP32-C6 joins the virtual Wi-Fi, sets its clock by NTP, fetches live weather with urequests and shows it on an I2C LCD. Make the 4 connections in the wiring table, upload the MicroPython code, and watch the Network tab: the join, the NTP time and the HTTP request. Change the latitude and longitude to your city.
Open this circuit in the free ESP32-C6 DevKitC-1 simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | ESP32-C6 DevKitC-1 | the microcontroller board |
| 1 | 16x2 LCD | Character LCD (HD44780). Wiring "full": RS, E and D4–D7 to pins (LiquidCrystal). Wiring "i2c": SDA to A4, SCL to A5 (LiquidCrystal_I2C, address 0x27). |
Wiring
| # | From | To |
|---|---|---|
| 1 | ESP32-C6 DevKitC-1 IO6 | 16x2 LCD SDA |
| 2 | ESP32-C6 DevKitC-1 IO7 | 16x2 LCD SCL |
| 3 | ESP32-C6 DevKitC-1 5V | 16x2 LCD VCC |
| 4 | ESP32-C6 DevKitC-1 GND | 16x2 LCD GND |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the ESP32-C6 DevKitC-1. No install or account is needed.
- Add the parts. Add a 16x2 LCD from the parts palette.
- Wire 1. Connect ESP32-C6 DevKitC-1 IO6 to 16x2 LCD SDA.
- Wire 2. Connect ESP32-C6 DevKitC-1 IO7 to 16x2 LCD SCL.
- Wire 3. Connect ESP32-C6 DevKitC-1 5V to 16x2 LCD VCC.
- Wire 4. Connect ESP32-C6 DevKitC-1 GND to 16x2 LCD GND.
- Paste the MicroPython code. Paste the MicroPython code below into the code editor.
- Run it. Press Run. Watch the Network tab: the join, the NTP time and the HTTP request. Change the latitude and longitude to your city.
MicroPython code
# ESP32-C6: a Wi-Fi weather station.
# The chip is emulated; its radio is virtual: network, urequests and ntptime
# are carried out by your browser (watch the Network tab).
# LCD 16x2 with an I2C backpack on SDA=IO6, SCL=IO7 (the C6's hardware I2C).
import network, urequests, ntptime, time
from machine import Pin, I2C
i2c = I2C(0, scl=Pin(7), sda=Pin(6), freq=100000)
def nib(v, rs):
d = (v << 4) | 0x08 | rs
i2c.writeto(0x27, bytes([d | 0x04, d]))
def send(v, rs=0):
nib(v >> 4, rs)
nib(v & 15, rs)
def lcd_line(text, row):
send(0x80 | (0x40 * row))
for ch in "{:<16}".format(text)[:16]:
send(ord(ch), 1)
time.sleep_ms(50)
for _ in range(3):
nib(3, 0)
time.sleep_ms(5)
nib(2, 0)
for c in (0x28, 0x0C, 0x06, 0x01):
send(c)
time.sleep_ms(2)
lcd_line("Joining Wi-Fi..", 0)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("BFB-Lab", "")
while not wlan.isconnected():
time.sleep_ms(200)
print("IP:", wlan.ifconfig()[0])
ntptime.settime() # the clock, from the network
URL = ("https://api.open-meteo.com/v1/forecast"
"?latitude=12.97&longitude=77.59¤t=temperature_2m,relative_humidity_2m")
while True:
try:
now = urequests.get(URL).json()["current"]
t, h = now["temperature_2m"], now["relative_humidity_2m"]
y, mo, d, hh, mm = time.localtime()[:5]
print("Bengaluru %.1f C, %d%% humidity at %02d:%02d UTC" % (t, h, hh, mm))
lcd_line("Bengaluru %.1fC" % t, 0)
lcd_line("%d%%RH %02d:%02d UTC" % (h, hh, mm), 1)
except OSError as e:
print("request failed:", e)
lcd_line("request failed", 1)
time.sleep(30)
What to try
Watch the Network tab: the join, the NTP time and the HTTP request. Change the latitude and longitude to your city.
Frequently asked questions
How do I wire the Wi-Fi Weather on an LCD project on an ESP32-C6 DevKitC-1?
Make 4 connections: ESP32-C6 DevKitC-1 IO6 to 16x2 LCD SDA; ESP32-C6 DevKitC-1 IO7 to 16x2 LCD SCL; ESP32-C6 DevKitC-1 5V to 16x2 LCD VCC; ESP32-C6 DevKitC-1 GND to 16x2 LCD GND.
What parts do I need for this ESP32-C6 project?
An ESP32-C6 DevKitC-1 and a 16x2 LCD.
Can I simulate this ESP32-C6 project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and MicroPython code in your browser for free, with no install and no hardware. The ESP32-C6 is emulated instruction by instruction on its RISC-V core, running its own ROM and the official MicroPython firmware.
What does the code do?
The emulated ESP32-C6 joins the virtual Wi-Fi, sets its clock by NTP, fetches live weather with urequests and shows it on an I2C LCD.
More ESP32-C6 DevKitC-1 projects
- ESP32-C6 RGB LED, Blink and Button Interrupt: Wiring, Code and Simulator
- ESP32-C6 ADC Knob Dims an LED (PWM): Wiring, Code and Simulator
- ESP32-C6 I2C LCD: Wiring, Code and Simulator
- ESP32-C6 SPI MAX7219 LED Matrix: Wiring, Code and Simulator
- ESP32-C6 nRF24L01 Receiver: Wiring, Code and Simulator
- ESP32-C6 HC-05 Bluetooth LED Control: Wiring, Code and Simulator