go-dht icon indicating copy to clipboard operation
go-dht copied to clipboard

AM2301 support?

Open hakwik opened this issue 4 years ago • 3 comments

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

hakwik avatar Feb 11 '21 20:02 hakwik

@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?

d2r2 avatar Feb 13 '21 04:02 d2r2

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.

hakwik avatar Feb 13 '21 10:02 hakwik

@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.

d2r2 avatar Feb 17 '21 03:02 d2r2