I am using the AM2302 Temp/Humidity Sensor. I start with

sudo apt-get update && sudo apt-get -y install git python-dev
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT/
sudo python setup.py install

and I connected the sensor:

  1. "-" to GND (pin 6)
  2. "+" to 3V3 (pin 1)
  3. "S" (signal) to GPIO4 (pin 7)

enter image description here

I run the following code :

import os
import time
import sys
import Adafruit_DHT as dht
import json

while True:
    h,t = dht.read_retry(dht.DHT22, 4)
    msg = json.JSONEncoder().encode({'tem' : round(t,3),'hum' : round(h,3)})
    print msg

I got

Traceback (most recent call last):
  File "tem_hum.py", line 9, in <module>
    msg = json.JSONEncoder().encode({'tem' : round(t,3),'hum' : round(h,3)})
TypeError: a float is required

which means there is no data it just returns none.

I already tried these in the below links:

https://github.com/adafruit/Adafruit_Python_DHT/issues/63 https://github.com/adafruit/Adafruit_Python_DHT/issues/73 https://github.com/adafruit/Adafruit_Python_DHT/issues/44

Any suggestion to make it read both Temp/Humidity.

Thanks in Advance.

  • What do you get if you print(h,t) after 'read_retry'? – CoderMike Jan 5 at 19:02
  • only (none,none) – i_th Jan 5 at 19:04
  • Example suggests setting sensor=Adafruit_DHT.AM2302 and passing sensor into read_entry github.com/adafruit/Adafruit_Python_DHT/blob/master/examples/… – CoderMike Jan 5 at 19:45
  • @CoderMike The same result. – i_th Jan 5 at 19:54
  • 1
    The 1-wire interface MUST NOT be enabled with the default GPIO 4 if you are using the AM2302 on GPIO 4. – joan Jan 6 at 0:04

Your Answer

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

Browse other questions tagged or ask your own question.