d2r2 / go-dht

Golang library to interact with DHT11/DHT22/DHT12 temperature and humidity sensors from Raspberry PI.
MIT License
135 stars 53 forks source link

AM2301 support? #28

Open hakwik opened 3 years ago

hakwik commented 3 years ago

Would it be possible to add support for the AM2301 (DHT21)? That would be much appreciated since it is one of the easiest available DHT sensors to me.

Datasheet is available here: http://www.haoyuelectronics.com/Attachment/AM2301/AM2301.pdf

d2r2 commented 3 years ago

@hakwik, did you try to use DHT22 or AM2302 setting to communicate with DHT21/AM2301 sensor?

I don't have this sensor in my assortment and I never test it, but what I see in this pdf looks very similar to what we have in AM2302/DHT22 docs: same 0 bit spec (26-28 microseconds 50 microseconds low plus high), same 1 bit spec (50 microseconds low to 70 microseconds high), and also data high level specs (2 bytes of humidity, 2 bytes of temperature, plus 1 byte control sum).

Can you try to test it in this way?

hakwik commented 3 years ago

Thank you. It appears you're right, it is almost identical it seems. Still I can't make it work with these tools:

2021-02-13T10:43:53.807 [     dht] WARN  Can't decode pulse array received from DHTxx sensor, since incorrect length: 124
2021-02-13T10:43:55.343 [     dht] WARN  Can't decode pulse array received from DHTxx sensor, since incorrect length: 132
2021-02-13T10:43:56.879 [     dht] WARN  Can't decode pulse array received from DHTxx sensor, since incorrect length: 130

This sensor does work with Python and their deprecated Adafruit_DHT package, although I take it they use some other approach? My sensor here is old and perhaps it's time for me to move on from it anyway, it does not seem to be as accurate as it once were.

d2r2 commented 3 years ago

@hakwik, I can only recommend that you change the code yourself trying to make this sensor working... Additionally you can modify GetHandshakeDuration() function timeouts, probably this may help. Sorry, that I can't test it and fix the code myself.