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.



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.