This project demonstrates how to use the AHT20 temperature and humidity sensor with the CH32V003 microcontroller with CH32fun framework. The project includes initialization of the I2C bus, reading data from the AHT20 sensor, and printing the temperature and humidity values to the console.
- Temperature and humidity measurement using AHT20 sensor
- I2C communication with the AHT20 sensor
- Periodic data reading and console output
- CH32V003 microcontroller
- AHT20 temperature and humidity sensor module
- Connect PC1 to module SDA pin
- Connect PC2 to module SCL pin
- Connect VDD to power supply (3.3 to 5V)
- Connect GND to common ground
- Init I2C bus with
i2c_init() - Declare variable of
AHT20Datato store result - Run
AHT20_read()to fetch sensor data
The main application code, including initialization, data reading, and console output.
// filepath: /home/pavlo/Documents/PlatformIO/Projects/AHT20-driver/src/main.c
#include "ch32fun.h"
#include "aht20.h"
int main() {
AHT20Data data;
SystemInit();
i2c_init();
while (1)
{
if(AHT20_read(&data) == AHT20_OK) {
printf("Temperature: %d Humidity: %d\n", (int)data.temperature, (int)data.humidity);
}
else {
printf("Error reading AHT20 sensor\n");
}
Delay_Ms(1000);
}
}This project is licensed under the MIT License.