BAISHUN AHT21 High Precision Digital Temperature and Humidity Sensor

hippy

Technical Support
Staff member
I haven't used the sensor myself and couldn't find any PICAXE code which has used it but it does look like it can be used with a PICAXE.

It is different to I2C Eeprom in that it uses 'commands' rather than 'register addresses' but I believe it should be usable with standard PICAXE HI2C commands, and, if not, then via I2C bit-banging.

It looks easy enough to extract the humidity and temperature from the returned data. Both are linear values so should be easy to convert to real world representations.

There are a couple of details I am not clear on from the datasheet 'papaof2' linked to; 7.4.1 initialisation and calibration, and 7.4.3 where it's not clear if the full data can be read while status shows busy.

That might mean some experimentation, trial and error, digging for clarification, but there does seem to be example code for other microcontrollers which may give enough of an insight for getting it done.
 

hippy

Technical Support
Staff member
Found an older AHT21 manual which add more detail on commands, and more detail on initialisation -

$BE - Initialization
$AC - Trigger Reading
$BA - Soft Reset

Wait 40ms after power-on. Before reading the temperature and humidity values, first check whether the calibration enable bit Bit [3] of the status word is 1 (you can get a byte of status word by sending 0x71). If not 1, need to send 0xbe command (for initialization), this command parameter has two bytes, the first byte is 0x08, the second byte is 0x00, and then wait for 10ms.

There's also a note saying a 100nF decoupling capacitor must be fitted near the chip - YMMV.

This looks like simple enough driver code to base PICAXE code on - https://github.com/etno712/aht/blob/main/aht.py

That seems to reflect the above datasheet information. The 8-bit Device ID for PICAXE would be $70 rather than 0x38 or the mis-stated 0x3B
 
Top