5

I have a raspberry pi running pipgio and am using the provided code under the python section to get the temperature and humidity reading from the AM2302 (http://www.adafruit.com/products/393). If I connect: Pi <--> breadboard wires <--> AM2302 it will work fine. However that means the sensor has to be 6 inches away from the pi. I really need the sensor about 3 feet away from the pi so it is in a good location to get temperature and humidity. So I connected it like: Pi <--> breadboard wires <--> alarm wire similar gauge to breadboard wires <--> AM2302 and I only get -999 back. In both cases I am connecting to GPIO 17 and using the 3.3 volts to power the sensor.

   3.3V ----- Red wire

 Ground ----- Black wire

GPIO 17 ----- Yellow wire

So the question is two-fold:

1. Is the alarm wire type causing issues? If so what is the recommended wire to use for this scenerio?

2. Is using the 3.3v over a longer distance causing the issue? If so, can I use 5v to solve the issue? The datasheet (http://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf) says it can accept 3.3 - 5.5v. However, the script says to connect to 5v the below is required but use at your own risk. Is this the best way to connect through 5v? I am not understanding why all that is necessary if the sensor accepts 5v (unless because the pi gpio is not 5v?)

   5V--5K_resistor--+--10K_resistor--Ground

                    |
   DHT22 pin 2 -----+

                    |
   gpio ------------+ 
2

You will almost certainly need to use 5V for any sort of distance.

From an AM2302 pdf (Special instructions of the single bus communication)

  1. Typical application circuit recommended in the short cable length of 30 meters on the 5.1K pull-up resistor pull-up resistor according to the actual situation of lower than 30 m
  2. With 3.3V supply voltage, cable length shall not be greater than 100cm. Otherwise, the line voltage drop will lead to the sensor power supply, resulting in measurement error.
  3. Read the sensor minimum time interval for the 2S; read interval is less than 2S, may cause the temperature and humidity are not allowed or communication is unsuccessful, etc.
  4. Temperature and humidity values are each read out the results of the last measurement For real- time data that need continuous read twice, we recommend repeatedly to read sensors, and each read sensor interval is greater than 2 seconds to obtain accurate the data.

I don't know if any of the wires should be twisted for best performance. The pdf only says to use high quality shielded cable.

When powered from 5V the output pin will be at 5V. The voltage divider is needed to cut the 5V data output to a Pi gpio safe 3V3.

  • Thanks! I am reading once every 5 seconds and am still getting the error. Is the diagram shown in my question the proper way to implement the voltage divider? – Elmer Jan 28 '15 at 17:59
  • Yes. Measure the voltage at the output pin if you can. It should be 3V3. Are you getting any data? You could use piscope to see if data bits are being transmitted. – joan Jan 28 '15 at 18:06
  • OK. I will definitely check out piscope! Reason I am asking about the voltage divider is because it is not making sense how to actually wire it up. I have the 5V raspberry pi pin and the 5v pin on the sensor, but on the diagram I only see one spot for 5v. Same issue for ground. – Elmer Jan 28 '15 at 18:18
  • The diagram doesn't show the pin 1 (5V) and pin 4 (ground) connections. – joan Jan 28 '15 at 18:29
  • So in addition to the voltage divider diagram I will still have 5V --- Red Wire and Ground --- Black wire? And the 5V and Ground mentioned in the voltage divider diagram are both raspberry pi pins? – Elmer Jan 28 '15 at 19:06
1

I had similar problem. First as per advice from Raspberry Pi Tutorial 26 - GPIO DHT22 Digital Temperature + Humidity Sensor, I made a loop to read until it is different to -999:

while ( humidity == "-999.00" ):
        increment += 1
        sleep(sleepTime)
        humidity, temperature = readDHT22()

After two or three readings in most cases it was OK. A good idea would be to extend it with limit to the increments, otherwise it might go on indefinitely.

Then, when I played with two sensors on different GPIO, I extended my code with a function to which I passed sensor objects. The problem has gone and now every first reading is OK. Don't ask me why ;)

pi = pigpio.pi()

s1 = DHT22.sensor(pi,4)
s1.trigger()

s2 = DHT22.sensor(pi, 17)
s2.trigger()

sleepTime = 3
increment = 0

def readDHT22(s):
        s.trigger()
        humidity = '%.2f' % (s.humidity())
        temp = '%.2f' % (s.temperature())
        return (humidity, temp)

hum1, temp1 = readDHT22(s1)
hum2, tem2 = readDHT22(s2)
  • Whats the different between pigpio DHT library and Adafruit_DHT library ? – Ciasto piekarz Oct 21 '17 at 18:54
0

There should be no problem, although I don't know what you mean by "alarm wire". I would have used a section of ribbon cable, and wouldn't have bothered with a breadboard.

This uses a 1-wire interface, which should work over reasonable distances.

The problem may where it is connected. You say GPIO 17 (there is no such pin). Do you mean BMC 17 (GPIO 0) physical pin 17?

My understanding is 1-wire only works on physical pin 4 (unless you compile your own kernel module).

  • By alarm wire I am referring to the wire used for a home alarm system. It has 4 wires wrapped in a white sheath. This sensor does not use the 1 wire interface. I am referring to the pin numbers by the broadcom numbering because that is how pigpio references them.elinux.org/… – Elmer Jan 28 '15 at 5:15
0

First on the breadboard I get a slightly different temperature running the AM2302 on 3.3 vs 5.0 volts. I use a level shifter chip when running on 5V. When you move the sensor off the board it is imperative that you run it on 5 volts with either a level shifter or a voltage divider to limit the voltage on the Pi GPIO at 3v3. The AM2302/DHT22 is NOT a 1 wire device. It will work on any GPIO. I have run up to ten at a time, each connected to a different GPIO pin. In my experience, even running the sensor at 5 volts and using shielded twisted wire, the distance is limited to about 6 meters. I've purchased about 20 of these sensors and the quality varies greatly, especially the RH reading. Buy from a reputable source and buy a few and compare them. If you want accurate temperature use the DS18B20 which is a true 1 wire device. The 5V --- 5K ---GPIO--- 10K --- Ground resistor divider will limit the GPIO pin voltage to a safe value. In theory this is OK, but it ignores the internal impedance of the sensor, and the voltage on the GPIO pin is higher than the allowed 3v3. A level shifter is the best solution.

0

I have connected an AM2302 with about 20m of cable. It's a 4 pair cable, with a global shield. There is no voltage divider or additional resistor involved.

enter image description here

It's connected to 3.3V, and it works (mostly) fine:

root@raspi:~# while sleep 5; do ./rht 15; echo ; done
21.60,38.80
21.60,38.90
21.60,38.90
21.60,39.00
21.60,39.00
21.60,39.10
21.60,39.10
21.50,39.10
21.50,39.10                                                                                                                                                                                  
21.50,39.20                                                                                                                                                                                  
21.50,39.20                                                                                                                                                                                  
21.50,39.20                                                                                                                                                                                  
21.50,39.20                                                                                                                                                                                  
21.50,39.30                                                                                                                                                                                  
21.50,39.30                                                                                                                                                                                  
21.50,39.30                                                                                                                                                                                  
21.40,39.30                                                                                                                                                                                  
21.40,39.30                                                                                                                                                                                  
21.40,39.40                                                                                                                                                                                  
21.40,39.40                                                                                                                                                                                  
21.40,39.40                                                                                                                                                                                  
21.40,39.40                                                                                                                                                                                  
21.40,39.50                                                                                                                                                                                  
21.40,39.50                                                                                                                                                                                  
21.40,39.60                                                                                                                                                                                  
21.40,39.70                                                                                                                                                                                  
21.30,39.60
21.30,39.60
21.30,39.70
21.30,39.70
21.30,39.70
21.30,39.70
21.30,39.70
error
21.30,39.80
21.30,39.80
21.30,39.90
error
21.30,40.00
21.20,39.90
21.30,40.00
21.20,39.90
21.20,39.90
21.20,40.00
21.20,40.00
21.20,40.00
21.20,40.00
21.20,40.00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.