-
Notifications
You must be signed in to change notification settings - Fork 0
AHT20 ‐ BMP280 usage
This Wiki page documents the library details for the AHT20 and BMP280 sensors, which are integrated into the sensor shield for the ATTiny84. The libraries are designed to provide easy access to environmental data, specifically humidity and temperature from the AHT20 sensor and pressure and temperature from the BMP280 sensor.
The AHT20 sensor library is structured for the ATTiny84 microcontroller and uses TinyWireM for I2C communication.
The AHT20 class provides functions to initialize, read, and interpret data from the AHT20 sensor. This class handles low-level communication with the sensor, making it simple to retrieve temperature and humidity measurements.
-
Constructor:
AHT20();Initializes the AHT20 instance.
-
begin():
bool begin();Initializes the I2C TWI and calibrates the AHT20 sensor. Returns 1 is successful.
-
readData():
bool readData();Reads raw humidity and temperature values. Returns 1 if 6 bytes are correctly read
-
getTemperature():
float getTemperature();Returns the temperature in Celsius as a float.
-
getHumidity():
float getHumidity();Returns relative humidity as a percentage (float).
-
reset():
void reset();Resets the AHT20 sensor and releases the I2C USI, which can be useful for reinitializing the I2C communication.
These are internal functions not intended for direct user interaction but crucial for the library's functionality:
-
initialize():
bool initialize();Writes initialization sequence {0xBE, 0x08, 0x00} to calibrate the sensor.
-
triggerMeasurement():
bool triggerMeasurement();Starts a humidity and temperature measurement. After 80 ms data will be available inside user registers.
-
readStatus():
uint8_t readStatus();Reads and returns the status register of the AHT20 sensor (0x71).
- bit7:BusyIndication (0 = free, 1 = busy in measurement mode)
- bit6:Remained
- bit5:Remained
- bit4:Remained
- bit3:CalibrationEnabled (1 = enabled,0 = uncalibrated)
- bit2:Remained
- bit1:Remained
- bit0:Remained
- Address: The I2C address for the AHT20 sensor is 0x38.
Basic setup, initialization, and data retrieval for the AHT20 sensor are demonstrated in the aht20_example folder.
IMPORTANT In this example, the AHT20 is used with the RFM95 module (SPI-based). Since the ATtiny84 shares I2C and SPI lines, all connected devices must actively drive the lines to avoid interference. We found that if the AHT20 enters a reset state, it disrupts SPI communication with the RFM95.
The BMP280 sensor library is structured for the ATTiny84 microcontroller and uses TinyWireM for I2C communication.
The BMP280 class provides functions to initialize, read, and interpret data from the BMP280 sensor. This class handles low-level communication with the sensor, making it simple to retrieve temperature and pressure measurements.
-
Constructor:
Initializes the AHT20 instance.
AHT20();
These are internal functions not intended for direct user interaction but crucial for the library's functionality:
-
initialize():
Writes initialization sequence {0xBE, 0x08, 0x00} to calibrate the sensor.
bool initialize();
- Address: The I2C address for the BMP280 can be either 0x76 (if SDO is connected to Vdd) or 0x77 (if SDO is connected to GND). In the Aht20-BMP280 shield the SDO line was connected to GND, therefore 0x77 must be used.