d2r2 / go-dht

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

RPI Zero-W using pin 5.. #5

Closed WadeJA closed 5 years ago

WadeJA commented 7 years ago

First time posting so hopefully properly. Am experimenting w/RPI3s + several Zero Ws. Using DS18B20s on pin 4 (GPIO4) so DHT22 is connected to pin 5. Code snippet is: humSensor := dht.DHT22 dht22Temp, dht22Humidity, _, err := dht.ReadDHTxxWithRetry (humSensor, 5, false, 10)

Code runs fine in RPI3 but errors on Zero. have swapped Zeros, 22s, all connector wires betw RPIs & breadboards, tried several resistor values. Errors I see are: Failed to open gpio direction for writing! 2017-08-13T04:36:51.860 [dht] WARN Error during call C.dial_DHTxx_and_read() 2017-08-13T04:36:54.080 [dht] WARN Can't decode pulse array received from DHTxx sensor, since incorrect length: 79 2017-08-13T04:36:56.293 [dht] WARN High edge value duration 100µs exceed expected maximum amount 97µs 2017-08-13T04:36:58.502 [dht] WARN Control sum 221 doesn't match 115 (130+235+1+5) 2017-08-13T04:37:00.719 [dht] WARN Control sum 220 doesn't match 141 (129+214+17+37) 2017-08-13T04:37:02.937 [dht] WARN Humidity value exceed 100%: 149.4 2017-08-13T04:37:05.154 [dht] WARN High edge value duration 107µs exceed expected maximum amount 97µs 2017-08-13T04:37:07.361 [dht] WARN Control sum 158 doesn't match 0 (3+247+1+5)

Have lotsa experience w/various languages, etc, etc. But do not understand what the problem w/the Zeros is. Both Zeros do the same thing, so I'd guess it's cockpit error or (perhaps?) difference in Zero using the lib. Thanks in advance for your help and kindness.

d2r2 commented 6 years ago

Hi, sorry for later response. I not sure, that DS18B20s is compatible in "1-wire protocol" with DHT sensors. It's pity, that I have no such device on my hands, so I can't verify how it works with this library. May be latter I will get one, but it take additionally month or so. If you still need a help with this, please, let me know. Best regards, Denis

WadeJA commented 6 years ago

First, thank you for your response. While you may not appreciate it, I’d be quite happy to send you one each of the items I am currently using. I am using golang for my main local controller software and forking of a command to get data via Python for what I cannot get via go (your lib). So go for the DS18B20s and a forked Python script for the DTH22 and an AM2315. For that matter, I also have to use Python to drive the HD44780 16x2 (or 20x4 - they’re the same) as well. I would much rather not have to use Python. Right now, while the go code (& the Python scripts) are identical on my RPI-3s and the Zero-Ws, the Python libraries must be different between them. I only have to reinstall the Python library on the Zero-W but that’s a pain. Having to reinstall is the only thing different and it stops me from simply duplicating the micro-SD card to move from the RPI-3 to the Zero-W. I’d have to check exports, but I’d be happy to send you a couple of DS18B20s,, a DHT22, an AM2315 & a Zero-W, if that’d help. John

On Nov 30, 2017, at 2:29 AM, Denis Dyakov notifications@github.com wrote:

Hi, sorry for later response. I not sure, that DS18B20s is compatible in "1-wire protocol" with DHT sensors. It's pity, that I have no such device on my hands, so I can't verify how it works with this library. May be latter I will get one, but it take additionally month or so. If you still need a help with this, please, let me know. Best regards, Denis

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/d2r2/go-dht/issues/5#issuecomment-348105413, or mute the thread https://github.com/notifications/unsubscribe-auth/AJFIeS-bMY7lO3iKVC1T7aH9pvl-yX5Xks5s7llXgaJpZM4O1on3.

d2r2 commented 6 years ago

Hi John! Thank you for your kindness to send me DS18B20s and other hardware, but I guess this is a long way from you (Kazakhstan located between Russia and China), so better I will order these set from Aliexpress :)

Honestly speaking, working with GPIO in this way is a pain, especially when you move from one device to another, since on the lower layer all these devices have their own incompatible register set to access GPIO pins. That's why sometimes you need to find specific python library to operate on specific device. So, perhaps there is some incompatibility exists for device that I didn't test (I think it's better in the future move to other type of temperature sensors, which use for instance i2c interface).

It's funny, but in my github repository I have go-adaptation for HD44780 device as well: [go-hd44780] (https://github.com/d2r2/go-hd44780). I don't know have you tried it, but let you know in any case.

d2r2 commented 6 years ago

@WadeJA John, did you find the root cause of issue with RPI Zero? I will close this thread in a week, since, as I understand, the issue is not directly related to the library. If you have any thoughts on this please let me know during a week.

WadeJA commented 6 years ago

I DID make some changes to the software, then decided to run it thru a fair amount of time over a fair amount of real condition temperature variations. Am not able to get the code change snippet but can do so w/in the next week. Will be happy to share w/you. Since I haven't done this before, If you would help by suggesting a mechanism to share, I'd appreciate it. Thank you.

d2r2 commented 6 years ago

Hi @WadeJA! As I know DS18B20s has its own "1-wire protocol", and if DHT sensor protocol gives milliseconds between signals, DS18B20s require microseconds. So, microsecond delays are not compatible with Linux User space (because Linux is not a real time OS). But, still you able to read data from DS18B20s, but using specific kernel module, which can process microsecond delays (even 2 modules: w1-gpio, w1-therm). I guess, you should read tutorial here.