Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Raspberry Pi GPIO17 with DHT22 no longer working #63
I have a few raspberry pi's wired with DHT22 sensors. It would be very expensive for me to wire them all back up.
This is a working raspberry pi with raspbian:
The non working raspberry pi with rasbian is:
The only difference between the two Raspberry Pis is that I ran rpi-update on one, which is now not working. The are both wired up identically, have the identical image (however I updated one).
My Wiring looks like this:
Hey, The reason for updating was because I wanted to be able to use the Raspberry Pi 2 v1.2, Is there a version that works both on the Raspberry Pi 2 v1.2 and will allow me to use this library on GPIO 17?
I tried dropping back to this version
Which still gives me an error, but it's different again.
referenced this issue
Mar 9, 2017
Ok, so I figured out the answer. This should allow the GPIO port 17 to work with the DHT sensor and the image to be used on the Raspberry Pi 2 v1.2
Downgrade the version to 4.4.50-v7+:
Then when the Pi is back online make sure the build packages are up to date:
Uninstall the DHT Package:
Remove all cached DHT Packages
And reinstall the DHT Package:
Hey! I've intensively searched for information and such for these errors and I've come to a conclusion that this library doesn't work correctly in Raspberry Pi 3, right?
I tried dowgrading its version as kowenhouston suggested, but I still get Raspberry_PI_2_Driver erro, within or without examples folder.
I found this issue was happening to every GPIO on the latest RPi3 version - got the RPi3 a month ago, and today tried to hook up 4 AM2302 sensors to every GPIO I could - none of them would work. But after following @kowenhouston 's advice, they're all working perfectly. Hopefully these keywords help the next person find this issue on Google!
I have the same issue I believe.
The DHT22.py file reports this error: ...Non-ASCII character '\xa3'... (related to line 86)
line 86 of DHT22.py: temperature = int_t #dht11 0..50*C
How can I resolve this issue? I had a few other errors which were resolved with proper indentation
...I took down all the comments.
...I get different code when I open the file from my windows computer than I do when open it from the raspi ?!? It's the same zip file from the same url address ?!?
@Twisis what DHT22.py file are you using? There is no DHT22.py file in this repository so I don't know which repo you got your file from. If you can give me the link to the file's repository I can take a look at the original code. But without seeing that, there's not much to work with since as I said yesterday the error refers to the # symbol but your response then goes on to talk about an error referring pyb or a micropython file that is again not within this repository.
If you can point me in the direction of the files you are using here on github I'd be happy to take a look at them and see if I can be of more help.
This is the address of the file used: http://abyz.me.uk/rpi/pigpio/code/DHT22_py.zip
When I used the link through the Raspberry Pi, opened the zip file and then opened the DHT22.py text file I got the following code:
We need to use global properties here as any allocation of a memory (aka declaration of a variable)
during the read cycle causes non-acceptable delay and we are loosing data than
data = None
FALL_EDGES = 42 # we have 42 falling edges during data receive
times = list(range(FALL_EDGES))
The interrupt handler
def init(timer_id = 2, data_pin = 'Y2', the_dhttype='DHT22'):
Parse the data read from the sensor
When I opened the same link on my Windows 10 PC, the DHT22.py file contained the following code:
The sensor can be powered from the Pi 3V3 or the Pi 5V rail.
Powering from the 3V3 rail is simpler and safer. You may need
For 3V3 operation connect pin 1 to 3V3 and pin 4 to ground.
Connect pin 2 to a gpio.
For 5V operation connect pin 1 to 5V and pin 4 to ground.
The following pin 2 connection works for me. Use at YOUR OWN RISK.
def init(self, pi, gpio, LED=None, power=None):
def _cb(self, gpio, level, tick):
if name == "main":
Intervals of about 2 seconds or less will eventually hang the DHT22.
pi = pigpio.pi()
s = DHT22.sensor(pi, 22, LED=16, power=8)
r = 0
next_reading = time.time()
These are the two different DHT22.py files.…
On Wed, Mar 21, 2018 at 12:14 PM, Geof Baum ***@***.***> wrote: @Twisis <https://github.com/twisis> what DHT22.py file are you using? There is no DHT22.py file in this repository so I don't know which repo you got your file from. If you can give me the link to the file's repository I can take a look at the original code. But without seeing that, there's not much to work with since as I said yesterday the error refers to the # symbol but your response then goes on to talk about an error referring pyb or a micropython file that is again not within this repository. If you can point me in the direction of the files you are using here on github I'd be happy to take a look at them and see if I can be of more help. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#63 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/Aj2fssHnKF4v-b2L_46L_5Maxh6-CG73ks5tgnxRgaJpZM4MYr3w> .
First thing of note, that file is not from github, as you said in your initial post.
Secondly, if you are posting python code you should use the Markdown styling:
With your code in between it.
Thirdly the first of the two files you copied and pasted the code above are not from that link you shared. Even if you think it's the same file and it is what you see on your Raspberry Pi there's no way it is from the same link. There are references of the dht11 in the first set of code while there is nothing in the second version that you say is the same file opened in Windows. That first set of code once again refers to the Micropython project library and if you are trying to run code from that you should try running it with the Adafruit MicroPython tool.
I'm pretty sure this mix up and blending of code is where you're problem is stemming from. You are somehow mixing multiple files that are not alike and expecting them to run through a regular python build. This would make sense since you received an error about pyb, especially since you probably don't have that library installed or if you do it's not within your regular python lib directory.
I am at Wits end.. HELP. I have tried everything to get a DHT22/AM2302 working on a Pi 3B+ with latest Stretch loaded. I have not downgraded as mentioned above yet and that will be next if someone says it will work on latest Pi. I followed Tony D video and code from https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git.
2.7 and 3.5 return same results " Failed to get reading. Try Again!"
@jevescio So you are using the code from this repository since the link you shared is to the outdated Adafruit Repo that links to this one?
Also you aren't getting an error like what folks above were getting. The library is working correctly as it was written, you are just not catching a reading which is why it's giving you that result. Can you post the exact code that you are using?
@geofbaum I am not getting same error seems to be beyond the above issues but still not reading sensor. I am just using the example code now to try simple read to see if working.
i even tried the http://abyz.me.uk/rpi/pigpio/examples.html#Python%20code before i formatted and started over.
@jevescio I can confirm it works on a RaspPi3 with Stretch as I just double checked it with one of mine this morning. It should work with either Python 2 or Python 3 if they are set up properly and the Adafruit_DHT is setup for both properly as well. Open a Python 2.7 or Python 3.4 terminal window and test this code.
import sys import RPi.GPIO as GPIO import Adafruit_DHT RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 23) # 23 in the last line of code referring to GPIO 23 which is pin 16 I believe # Make sure to comment out the print line that does not apply to the version your testing # for Python 2 print str(RH), str(T) # for Python 3 print(str(RH), str(T))
Before you say anything yes, I know this isn't any of the examples from this library but it's the code that I've used personally before so I know it works. It will work in a script and it can be used in conjunction if you want with other code to send data to something like ThingSpeak. I can also confirm that this works with both the older version of the AM2301/DHT21, AM2302/DHT22, a breakout board version of the DHT22, and the new version the AM2320.