Overview
This project implements a real-time temperature and humidity sensing system using the RT-Thread RT-Spark development board, the AHT21 sensor, and a 240×240 ST7789 LCD. The system reads environmental data via I²C and displays it on the LCD using embedded C code written in STM32CubeIDE. It was developed as part of Laboratory Activity No. 4 for BCA152 Microcontrollers at Mindanao State University – Iligan Institute of Technology.
Objectives
- Interface the AHT21 sensor with STM32 via I²C.
- Display temperature and humidity readings on the ST7789 LCD using FSMC parallel communication.
- Implement the system using embedded C in STM32CubeIDE.
- Verify correct output and hardware configuration.
LCD Display Output
Real-time temperature and humidity readings displayed on the ST7789 LCD using data from the AHT21 sensor.
STM32CubeIDE Configuration
STM32CubeIDE .ioc configuration showing I²C1 enabled (PF0 = SCL, PF1 = SDA) and FSMC interface for LCD.
CubeIDE Configuration
Step-by-Step Implementation
1️⃣ Configure STM32CubeIDE Project
- Create a new STM32 project targeting STM32F407ZGTx.
- Enable I²C1 and assign PF0 (SCL) and PF1 (SDA) for AHT21.
- Enable FSMC and assign data/control lines for ST7789 LCD.
2️⃣ Initialize Peripherals
- Use HAL drivers to initialize I²C and FSMC.
- Port AHT21 and ST7789 driver libraries to STM32CubeIDE.
3️⃣ Read Sensor Data
- Send measurement command to AHT21.
- Read raw temperature and humidity values.
- Convert raw data to °C and %RH.
4️⃣ Display on LCD
- Format readings into strings.
- Use LCD driver to render text on screen.
- Refresh display every second.
5️⃣ Verify Output
- Confirm LCD shows correct values.
- Test across different environments for stability.
Final Output
RT-Spark LCD Display
Successful output showing Temp: 30.91°C, Hum: 71.18%, Sensor: AMT21.
Future Improvements
- Add SD card logging for historical data.
- Integrate Wi-Fi (RW007 module) for cloud upload.
- Add graphical UI (charts, icons).
- Expand to multiple sensors or remote monitoring.




Comments