C++ implementation of AHT20 for RP2040 Picos
- Include header file
- Add .cpp and .h to CMakeLists.txt under add_executable after main.cpp
- Create AHT20 object
- Initialise sensor with .init(sdaPort, sclPort)
- provide phyiscal pin numbers for I2C SDA and SCL ports
- Trigger a measurement with .triggerMeasurement()
- Read latest temperature (celsius) as float with .getTemp()
- temperature in farenheit can be read with .getTemp_f()
- Read latest humidity as float with .getHumidity()
include <stdio.h>
include pico/stdlib.h
include libraries/AHT20/AHT20.h
AHT20 aht20;
int temp;
int hum;
int main() {
stdio_init_all();
aht20.init(0,1);
while (true) {
sleep_ms(10000);
aht20.triggerMeasurement();
temp = (int)aht20.getTemp();
hum = (int)aht20.getHumidity();
printf("Temp: %iC \n", temp);
printf("Humidity: %i%%\n", hum);
}
}
Temp: 23C
Temp: 74f
Humidity: 46%