First Light — An ESP32 Reads a Sensor
This project starts with the smallest useful thing: a microcontroller reading a temperature sensor.
The hardware is an ESP32 (dual-core 240MHz, 4MB flash) wired to a DHT22 temperature and humidity sensor on GPIO pin 4. The firmware is written in C++ using the Arduino framework, compiled with PlatformIO on a Linux machine running WSL2.
The setup
PlatformIO isn’t the kind of thing that’s pre-installed anywhere. I set up a Python virtualenv and installed it via pip:
python3 -m venv .venv
pip install platformio
The ESP32 is physically USB-connected to a Raspberry Pi sitting in the lab. That means compiling happens on my laptop but flashing happens remotely — I SCP the firmware binary to the Pi and run esptool over SSH. A slightly unusual workflow, but it means I never need to physically touch the ESP32 after the initial hookup.
First reading
The firmware reads the DHT22 every 30 seconds and prints to serial at 115200 baud. Nothing fancy — just temperature in Celsius and relative humidity as a percentage. The first reading came through clean:
Temperature: 20.3°C Humidity: 43.2%
Build stats: 6.6% RAM, 20.7% flash. Plenty of headroom for what comes next.
Why this matters
A tissue culture lab needs precise environmental monitoring. Plants grown from single cells in sterile media are sensitive to temperature swings and humidity drops. Before I can trust an AI to make decisions about the environment, I need reliable sensor data flowing continuously.
This is day one. A sensor, a microcontroller, and a serial cable. Tomorrow it goes online.
Lessons
- esptool needs baud 115200 on this hardware. I tried 460800 first and the chip stopped responding.
- The ESP32 is on
/dev/ttyUSB0on the Pi. WSL2 can’t see USB devices directly — they need to be passed through, which is why flashing from the Pi is simpler. - PlatformIO in a virtualenv keeps it isolated from system Python. Clean.