Sensor nodes using micropython with GC9A01 display support
This project provides a complete MicroPython-based sensor node system that can read environmental data from various sensors and publish it via MQTT. The system includes support for the GC9A01 round LCD display to show real-time sensor readings.
- Multi-sensor support: DHT22, BME280, and switch sensors
- MQTT integration: Automatic publishing of sensor data
- Visual display: Real-time sensor data on GC9A01 round LCD
- WiFi connectivity: Automatic connection and reconnection
- Watchdog protection: System reliability with automatic recovery
- Configurable: Easy setup via configuration file
- ESP32 or ESP8266 microcontroller
- Sensors: DHT22, BME280, or other supported sensors
- GC9A01 round LCD display (240x240 pixels)
- WiFi network access
- MQTT broker
gc9a01.py: Display driver with SPI communication and graphics supporttest_display.py: Standalone test script for display functionalitywifi.dat.example: Example configuration file
- Resolution: 240x240 pixels round display
- Color support: 16-bit RGB565 color format
- Real-time updates: Temperature and humidity displayed with color coding
- Error handling: Graceful fallback when display updates fail
- SPI interface: High-speed communication (40MHz baudrate)
| Signal | ESP32 pin (default) | Notes |
|---|---|---|
| VCC | 3V3 | Power |
| GND | GND | Ground |
| SCK | GPIO 18 | SPI clock |
| MOSI | GPIO 23 | SPI MOSI |
| CS | GPIO 15 | Chip select |
| DC | GPIO 5 | Data/command |
| RST | GPIO 0 | Reset |
| BL | GPIO 2 | Backlight (optional) |
Minimal usage example:
from machine import SPI, Pin
from gc9a01 import GC9A01
spi = SPI(1, baudrate=40_000_000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(23))
disp = GC9A01(spi, cs=15, dc=5, rst=0, bl=2)
disp.text("Hello", 60, 120, 0xFFFF)
disp.show()Default pin assignments (configurable in code):
SPI CS: GPIO 15
SPI DC: GPIO 5
SPI RST: GPIO 0
SPI BL: GPIO 2 (backlight)
DHT Sensor: GPIO 4
The display shows:
- Temperature readings in red text
- Humidity readings in green text
- Clear, easy-to-read format
- Automatic updates with sensor readings
Create a wifi.dat file with the following format:
your_wifi_ssid
your_wifi_password
your_mqtt_server_ip
your_node_name
30
dht22 4
- Configure your
wifi.datfile - Upload all files to your ESP32/ESP8266
- Connect sensors and display according to pin configuration
- Run
main.pyfor complete sensor node with MQTT and display
- Run
test_display.pyto test display functionality independently - Verify sensor readings and display output
- Adjust pin configurations as needed
- DHT22: Temperature and humidity sensor
- BME280: Temperature, humidity, and pressure sensor
- Switch sensors: Digital input monitoring
- MicroPython firmware
- Built-in libraries:
machine,network,time,framebuf - Custom modules:
umqttsimple,bme280, sensor-specific modules
On Windows, upload.bat uploads all firmware files (core, sensor modules, display driver) plus a generated wifi.dat to the board via ampy:
upload.bat COM3 your_node_identifier
Where COM3 is your ESP32/ESP8266 serial port and your_node_identifier replaces the IDENT placeholder in wifi.txt to produce wifi.dat.
On macOS/Linux, use the CMake target instead (also uses ampy under the hood):
cmake -B build -DPORT=/dev/cu.usbserial-0001 -DIDENT=your_node_identifier
cmake --build build --target upload
This repo targets MicroPython, so the code can't be executed directly under CPython, but static checks and the pure-logic unit tests can run locally:
pip install -r requirements-dev.txt
python -m py_compile *.py # syntax check
ruff check . # undefined names / unused imports
pytest # unit tests (mqtt_sens, mqtt_status)
These three checks also run in CI on every push and pull request.
MIT - see LICENSE.