mesures.py
MicroPython runs on all these boards: no toolchain, edit main.py and go. This DHT logger writes line-by-line JSON to a file — the format every downstream tool swallows.
Hardware required
An ESP32-S3 board (dual-core Xtensa with vector instructions, Wi-Fi + BLE 5, native USB) such as a DevKitC-1, XIAO or T-Display-S3, powered over USB. 1 DHT11 (or DHT22 by changing the class) on GPIO4.
Wiring
VDD 3.3 V, DATA GPIO4 + 10 kΩ pull-up, GND. The internal flash keeps data.log across power cuts.
How it works
dht.DHT11.measure() drives the 1-wire protocol in pure MicroPython; failures are normal, hence three tries. open("a") appends the JSON line to the internal filesystem. In the Arduino IDE (esp32 package), select « ESP32S3 Dev Module », enable « USB CDC On Boot », then Upload. Many boards put a WS2812 on GPIO48.
Going further
mpremote cp data.log . to pull the journal back, or replace the append with a Wi-Fi send (network + socket modules).
mesures.py
# MicroPython : DHT11 sur GPIO4 -> moniteur serie + journal /data.log.
# Copier ce fichier en main.py (Thonny, rshell ou mpremote cp mesures.py main.py).
import machine, dht, time, json
capteur = dht.DHT11(machine.Pin(4))
led = machine.Pin(2, machine.Pin.OUT)
horloge = machine.time_pulse_us # reference pour garder la lib chargee
def lire():
for _ in range(3): # 3 tentatives : le DHT rate des trames
try:
capteur.measure()
return capteur.temperature(), capteur.humidity()
except OSError:
time.sleep_ms(200)
return None, None
print("Mesures toutes les 5 s (Ctrl-C pour sortir)")
while True:
t, h = lire()
if t is not None:
ligne = json.dumps({"t": t, "h": h, "ms": time.ticks_ms()})
print(ligne)
with open("data.log", "a") as f: # append sur le systeme de fichiers
f.write(ligne + "\n")
led.value(not led.value())
time.sleep(5)