cobaltowl

We'll cross that bridge when we find it

I2C communication quirks with AM2320 temperature and humidity sensor

22-07-2024


I've made a library for reading AM2320 temperature and humidity data, but I came across a few small caveats:

Baudrate

This sensor does not work particularly well at higher I2C speeds. Low (100 KHz) speed works fine (and it is in fact the maximum supported speed, as per the datasheet), 400 KHz causes the CRC16 bytes to magically dissapear from the packet sent back by the sensor, which means we cannot verify temperature/humidity readings, which also seem to vary wildly at times at higher I2C speeds.

Pull up resistors

Pullup resistors are a must, even if you enable the internal pull ups on startup. This is because in order for the sensor to enter the "enabled" state, it requires the pull ups to be present on power up. In some cases, the Pico might not be able to do that quickly enough, especially with USB/UART standard I/O init.

Wake up

On every write, the sensor needs to be woken up. This can be done by sending an empty I2C write to the sensor, and waiting roughly 1.5 ms (2ms to be on the safe side).

Precision

The datasheet mentions the sensor has an accuracy of +/- 0.5C for temperature and +/- 3% for relative humidity. That doesn't seem correct, though as the PiHut mentions: Temperature is probably correct to 2-3 degrees Celsius. Humidity is probably within 5-10%

Over 500 reads, captured at 10 Hz, the temperature oscillated between 26.2C and 26.9C, and humidity varied between 57.3% and 55.5%. Repeatibility for temperature and humidity should be +/-0.2C and +/-0.1%, respectively.

This was captured with a VDD of 3.3V.

Reading

Reading can be done reliably at a max rate of 13.3 Hz (period of 75 ms), otherwise, only half the reads go through. The sensor has an acquisition time of two seconds.