Skip to content

Latest commit

 

History

34 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

micropython_sensnode

CI

Sensor nodes using micropython with GC9A01 display support

Overview

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.

Features

  • 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

Hardware Requirements

  • ESP32 or ESP8266 microcontroller
  • Sensors: DHT22, BME280, or other supported sensors
  • GC9A01 round LCD display (240x240 pixels)
  • WiFi network access
  • MQTT broker

GC9A01 Display Integration

Relevant Files

  • gc9a01.py: Display driver with SPI communication and graphics support
  • test_display.py: Standalone test script for display functionality
  • wifi.dat.example: Example configuration file

Display Features

  • 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)

Wiring

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()

Pin Configuration

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

Display Output

The display shows:

  • Temperature readings in red text
  • Humidity readings in green text
  • Clear, easy-to-read format
  • Automatic updates with sensor readings

Configuration

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

Usage

Full System

  1. Configure your wifi.dat file
  2. Upload all files to your ESP32/ESP8266
  3. Connect sensors and display according to pin configuration
  4. Run main.py for complete sensor node with MQTT and display

Display Testing

  1. Run test_display.py to test display functionality independently
  2. Verify sensor readings and display output
  3. Adjust pin configurations as needed

Sensor Support

  • DHT22: Temperature and humidity sensor
  • BME280: Temperature, humidity, and pressure sensor
  • Switch sensors: Digital input monitoring

Dependencies

  • MicroPython firmware
  • Built-in libraries: machine, network, time, framebuf
  • Custom modules: umqttsimple, bme280, sensor-specific modules

Uploading

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

Development

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.

License

MIT - see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages