User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more DHT22 sensor code

Sat Aug 16, 2014 9:30 pm

sloughin wrote:You say you connect the sensor to GPIO.8 however, gpio readall doesn't seem to show a GPIO.8. I tried it connected to physical pin 7 (thinking perhaps you start labeling your GPIO pins at 1 instead of 0) and using 3.3V with a 5K pull up resistor, and I got -999 for my readings. Noticing that your gpio argument is 22, and the gpio readall has BCM 22 on physical pin 15 which is GPIO.3, I tried that instead.

Code: Select all

s = DHT22.sensor(pi, 22, LED=16, power=8) # as code was supplied

Code: Select all

+-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 0 | IN   | CE1     | 11  | 7   |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |  28 |  17 | GPIO.17 | ALT2 | 0 | 51 || 52 | 0 | ALT2 | GPIO.18 | 18  | 29  |
 |  30 |  19 | GPIO.19 | ALT2 | 0 | 53 || 54 | 0 | ALT2 | GPIO.20 | 20  | 31  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
And that works! Thanks.
There are several gpio numbering schemes in common use. pigpio only uses Broadcom gpio numbering. So gpio 8 refers to Broadcom gpio 8 (SPI channel select 0) which wiringPi (gpio readall) refers to as gpio number 10.

danjperron
Posts: 3072
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more DHT22 sensor code

Sat Aug 16, 2014 11:03 pm

Hi sloughin,

There is commonly 2 ways the specify GPIO,

By the connector pin number or
mostly by the BCM gpio number.

The latest is the most used.

if you used the GPIO8, pin 24, please be sure that the SPI driver is not enabled.

http://www.raspberrypi.org/forums/viewt ... 78&t=82397


Daniel

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more DHT22 sensor code

Fri Aug 29, 2014 3:46 pm

As far as I can tell (without waiting an eternity) the code no longer causes the DHT22 to hang.

Apparently I was just trying to drive it too fast at a reading once every 2 seconds. Since changing to a reading every 3 seconds I have not had any problems.

After 34 days and a million readings I think I'll count this as tested.
million.png
A million DHT22 readings at 3 second intervals.
million.png (30.05 KiB) Viewed 4581 times
A total of 11 checksum errors and 4 no response for 15 errors in a million.

umar372
Posts: 1
Joined: Sun Jun 22, 2014 8:08 am

Re: Yet more DHT22 sensor code

Sun Aug 31, 2014 9:12 pm

Hi Everyone,
I am newbie to Raspberry Pi. I tried the code given here. It is giving some errors "can't connect to pigio on locahost (8888)" and many more lines. I have attached the screenshot of errors. Can anyone please help me regarding this issue. I am using Pidora and Python 2.7.

Thanks
Attachments
screen.png
Output error while running Code
screen.png (63.62 KiB) Viewed 4531 times

Nige C
Posts: 46
Joined: Thu Jul 19, 2012 12:22 am
Location: Hadleigh, Suffolk

Re: Yet more DHT22 sensor code

Mon Sep 01, 2014 12:50 am

Well done Joan. Glad you sorted this DHT22 issue. It was a matter of time :)
Retired power engineer with a lot of real life experience. Life is an adventure again :)

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more DHT22 sensor code

Mon Sep 01, 2014 7:15 am

umar372 wrote: ...
Can anyone please help me regarding this issue. I am using Pidora and Python 2.7.
...
It uses my pigpio library.

Massi
Posts: 1679
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: Yet more DHT22 sensor code

Wed Oct 15, 2014 5:02 pm

my dht22 seems to be stuck on 99.9% humidity
did it ever happened to any of you?
really strange because temp reading is perfect and "randomly" the humidity goes down to something like 90%

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more DHT22 sensor code

Wed Oct 15, 2014 5:21 pm

pattagghiu wrote:my dht22 seems to be stuck on 99.9% humidity
did it ever happened to any of you?
really strange because temp reading is perfect and "randomly" the humidity goes down to something like 90%
It's not something I've experienced myself or noticed a post about before.

I had a quick look at the code but couldn't see anything special about a (near) 100% relative humidity.

Massi
Posts: 1679
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: Yet more DHT22 sensor code

Wed Oct 15, 2014 5:28 pm

joan wrote:
pattagghiu wrote:my dht22 seems to be stuck on 99.9% humidity
did it ever happened to any of you?
really strange because temp reading is perfect and "randomly" the humidity goes down to something like 90%
It's not something I've experienced myself or noticed a post about before.

I had a quick look at the code but couldn't see anything special about a (near) 100% relative humidity.
i checked the output and it was a REALLY 99.9 (3 and 231, shifting 3 is 768, so 999)
But now it has just died, with your code i've entered the "missing response" way..
so i think it's just broken :(

damn :(

have no idea about dx.com RMA..

wonx
Posts: 22
Joined: Tue Aug 07, 2012 11:00 am
Location: Barcelona

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 1:17 am

I recently bought one of these DHT22 sensors. Actually, it's the one which came inside a larger "case" (https://www.adafruit.com/product/393) but which uses the DHT22 internally. I first followed Adafruit's instructions (https://learn.adafruit.com/dht-humidity ... ing/wiring) and their script, with no luck. It wasn't after trying a lot of different pin configurations that their script started working. I connected the red cable to the 5v instead of the 3v3 pin, the black cable to the ground and the yellow one (data cable) to the GPIO 4, and left the white one disconnected. It had been working for a couple of days, until now that I had to restart my rpi to configure a wifi dongle and the sensor stopped working again.

If I run your script, but all I get is :

Code: Select all

[email protected] ~ $ sudo python DHT22.py
1 -999 -999 -999.00 0 0 0 0
2 -999 -999 -999.00 1 0 0 0
I tried changing the output pin, with no luck. I also tried using the 3v3 pin with the same results. How can I be sure if it's a hardware or a software problem? Is there any way to troubleshoot it? I don't know if it stopped working for good, or if there's still a chance of reviving the sensor.

Thanks in advance

danjperron
Posts: 3072
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 2:45 am

The DHT22 is very touchy when you power it up!

The data pin needs to be high at least 2 seconds after power up otherwise it won't work at all.

Changing the wiring to figure it out what is wrong still need to keep the sensor with power and output signal high for at least 2 seconds. If you power it up and the data pin is low, it won't work.

On Joan's pigpio webpage you have code to use another GPIO to power it up. It is very handy.


Daniel

wonx
Posts: 22
Joined: Tue Aug 07, 2012 11:00 am
Location: Barcelona

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 7:57 am

danjperron wrote:On Joan's pigpio webpage you have code to use another GPIO to power it up. It is very handy.
Could you please point me to said code? I guess you are referring to this website http://abyz.co.uk/rpi/pigpio/examples.html but I can't find the script you mean.

I am sorry, I am still quite a beginner when it comes to physically wiring and controlling stuff.

BTW: my data pin is connected to the physical pin 15, which corresponts to the GPIO22 (http://www.raspberrypi-spy.co.uk/wp-con ... sion-1.png). I think this is what joan's script uses by default. Is that correct?

Thanks in advance

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 8:02 am

@wonx

Could you detail your wiring or even better post a photo?

The DHT22 does seem to be temperamental.

danjperron
Posts: 3072
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 1:26 pm

Could you please point me to said code? I guess you are referring to this website http://abyz.co.uk/rpi/pigpio/examples.html but I can't find the script you mean.
It is there! in the python version
DHT22 AM2302 Sensor

Check this post , maybe from the beginning, I explain taht I do have problem with it and I fix it using a GPIO on the power pin.

http://www.raspberrypi.org/forums/viewt ... 63#p675263

@Joan could you add in your example the modification to make it DHT11 compatible

Daniel

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 1:36 pm

danjperron wrote: ...
@Joan could you add in your example the modification to make it DHT11 compatible

Daniel
I meant to ask you if I could host your code or a link to your code on the examples page.

I'd be happy to do either at your preference.

Massi
Posts: 1679
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 1:45 pm

wonx wrote:I connected the red cable to the 5v instead of the 3v3 pin, the black cable to the ground and the yellow one (data cable) to the GPIO 4
This sounds bad.

danjperron
Posts: 3072
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 1:54 pm

@Joan you have my permission to host my DHT11 modification and maybe also you could add the method to create a service with pigpiod. Hey I use your code a lot. Or even the full way to create the chart on a webpage. This is the least I can do.


5V on the DHT11 power won't create a problem on the data pin. The DHT22 is a open collector system with a pull-up resistor. The pull up is high enough that it won't corrupt (increase) the 3.3V power via the GPIO.

Daniel

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 2:27 pm

danjperron wrote:@Joan you have my permission to host my DHT11 modification and maybe also you could add the method to create a service with pigpiod. Hey I use your code a lot. Or even the full way to create the chart on a webpage. This is the least I can do.


5V on the DHT11 power won't create a problem on the data pin. The DHT22 is a open collector system with a pull-up resistor. The pull up is high enough that it won't corrupt (increase) the 3.3V power via the GPIO.

Daniel
Thanks.

Are you sure about the data line? There presumably is a 4k7 pull-up to the source voltage internally in that Adafruit module. So if the source voltage is 5V won't there be 5V on the data line? I'd always assumed that won't be safe for a Pi gpio.

danjperron
Posts: 3072
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 2:57 pm

(5V-3.3)/ 4K7 = 0.3 mA

Injecting 0.3mA into one GPIO won't change the 3.3V stability and won't cause damage on the GPIO.

CMOS chip have protection diode to prevent static charge and the problem is they are link to the power. Increasing the current too much will definitively increase the 3.3V and you don't want that. You could assume that the 3.3V regulator will deal with it.

Daniel

paulv
Posts: 546
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Yet more DHT22 sensor code

Sat Feb 07, 2015 4:14 pm

If you put up to 1K in series of the GPIO pins, as a matter of precaution, you will even have more protection.

wonx
Posts: 22
Joined: Tue Aug 07, 2012 11:00 am
Location: Barcelona

Re: Yet more DHT22 sensor code

Sun Feb 08, 2015 6:30 pm

Daniel, I couldn't understand what exactly I had to do according to the post you linked. It seems that the readTemp.py is no longer found on the website and it also seems to be programmed for the DHT11 not the DHT22. Sorry, I am confused.

I am using the wired version of the DHT22, the AM2302B, which according to adafruit (https://www.adafruit.com/product/393), it already includes a 5.1K resistor inside the sensor connecting VCC and DATA. This is why I wired it directly to the GPIO pins in my raspberry pi without any other resistors. The specifications also say that it's both compatible with 3v and 5v. I am using a Rev1 256MB Raspberry Pi.

My wiring is the following:

- Power cable (Red): 5V (Pin 2)
- Ground cable (Black): Ground (Pin 6)
- Data cable (Yellow): GPIO 4 (Pin 7)
- White cable: (Disconnected)

I used this command to get the readings:

Code: Select all

[email protected] ~/Adafruit_Python_DHT/examples $ sudo python AdafruitDHT.py 22 4
With this configuration, it worked for two days without any problems, getting the data using Adafruit's script. It stopped working after I rebooted it to change some unrelated network configuration. Now it only shows "Failed to get reading. Try again!". Of course, I first tried to plug the power cable to the 3v (Pin 1), but that never worked.

Here's a picture:
Image
(Ignore the soldering job, it's only temporary and should work anyway)

Any ideas on how I can make my DHT22 come back to life?

thanks in advance.

danjperron
Posts: 3072
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more DHT22 sensor code

Sun Feb 08, 2015 6:41 pm

Why not trying directly Joan pigpio example.

It is by default for the DHT22.

His example uses

GPIO 22 => DHT22 data with a pull-up resistor
GPIO 8 => DHT22 POWER
GPIO 16 => LED indicator

you need to get pigpio, run pigpiod and run the code in sudo mode.

Daniel

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more DHT22 sensor code

Sun Feb 08, 2015 6:52 pm

danjperron wrote: ...
you need to get pigpio, run pigpiod and run the code in sudo mode.

Daniel
Only pigpiod needs sudo. pigpio Python scripts can be run without sudo.

wonx
Posts: 22
Joined: Tue Aug 07, 2012 11:00 am
Location: Barcelona

Re: Yet more DHT22 sensor code

Sun Feb 08, 2015 6:53 pm

Power cable: GPIO8 (pin 24)
Data cable: GPIO22 (pin 15)
Ground cable: Ground (Pin 6)

Code: Select all

[email protected] ~ $ sudo pigpiod
[email protected] ~ $ python DHT22.py
1 -999 -999 -999.00 0 0 0 0
2 -999 -999 -999.00 1 0 0 0
3 -999 -999 -999.00 1 0 0 0
Should I be getting a reading, or this is just to "restart" the sensor?

danjperron
Posts: 3072
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more DHT22 sensor code

Sun Feb 08, 2015 10:42 pm

Hum ??

This get me a chance to check my new Raspberry Pi A+ board.

1 - I download the new Raspbian sd 2015-01-31. Put it on an microSd and add my wifi setup.
2 - I download and install pigpio

Code: Select all

sudo apt-get update
cd ~
wget abyz.co.uk/rpi/pigpio/pigpio.zip
unzip pigpio.zip
cd PIGPIO
make
sudo make install
3 - I physically install the DHT22 sensor exactly like yours. But I use pin 25 for ground. It is easier to see in the picture this way.

Image

4- And ran the code (with sudo only on pigpiod ;-) Thank's Joan).

Code: Select all

[email protected] ~ $ sudo pigpiod
[email protected] ~ $ python DHT22.py
1 -999 -999 -999.00 1 0 0 0
2 20.2 22.4 0.19 1 0 0 0
3 19.8 22.4 0.18 1 0 0 0
4 20.4 22.3 0.19 1 0 0 0

**** here I took it out and re-install it with the raspberry Pi still on ***

[email protected] ~ $ python DHT22.py
1 39.3 28.1 0.19 0 0 0 0
2 22.7 28.2 0.19 0 0 0 0
3 21.3 28.1 0.18 0 0 0 0
4 20.8 28.0 0.19 0 0 0 0
On the first run , the DHT22 power reset and return back on its feet.

On the second run , as expected the first data is wrong since the DHT22 report the last data its got.
it was in my hand so it heats up. This is something that I don't like about that sensor. You read the data and then it convert a new value.

So looks like your sensor is burst or something not obvious because mine work all the time and with no pull-up resistor.

B.T.W. I tried another sensor and still working.



P.S. I hope your SPI system is disable because GPIO8 is SPI CE0.

Daniel

Return to “Automation, sensing and robotics”