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

QtyPartWhat it does
1ESP32-C6 DevKitC-1the microcontroller board
116x2 LCDCharacter 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

#FromTo
1ESP32-C6 DevKitC-1 IO616x2 LCD SDA
2ESP32-C6 DevKitC-1 IO716x2 LCD SCL
3ESP32-C6 DevKitC-1 5V16x2 LCD VCC
4ESP32-C6 DevKitC-1 GND16x2 LCD GND

Step by step

  1. 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.
  2. Add the parts. Add a 16x2 LCD from the parts palette.
  3. Wire 1. Connect ESP32-C6 DevKitC-1 IO6 to 16x2 LCD SDA.
  4. Wire 2. Connect ESP32-C6 DevKitC-1 IO7 to 16x2 LCD SCL.
  5. Wire 3. Connect ESP32-C6 DevKitC-1 5V to 16x2 LCD VCC.
  6. Wire 4. Connect ESP32-C6 DevKitC-1 GND to 16x2 LCD GND.
  7. Paste the MicroPython code. Paste the MicroPython code below into the code editor.
  8. 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&current=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