I’m using a GrovePi on a Raspberry PI 3 running the latest raspbian (Jessie) with python code to measure values from a Temperature and Humidity Sensor Pro (white DHT22 / AM2302 version) every ten seconds and log the readings to a file. The code is based on the dht example, and appears to be working fine. Here is the relevant part of the code:
sensor = 4 # The Sensor goes on digital port 4.
# temp_humidity_sensor_type
blue = 0 # The Blue colored sensor.
white = 1 # The White colored sensor.
f = open ('/home/rsh/dht.csv',mode='a',buffering=1)
while True:
time.sleep(10)
try:
# The first parameter is the port, the second parameter is the type of sensor.
[temp,humidity] = grovepi.dht(sensor,white)
except IOError:
print ("Error")
if math.isnan(temp) == False and math.isnan(humidity) == False:
print('{},{:.01f},{:.01f}' .format(strftime("%Y-%m-%d %H:%M:%S"), temp, humidity),file=f)
I logged temperature and humidity overnight in a sheltered outdoor location. Here is a gnuplot graph showing temperature against time:
The data is mostly believable, but there are occasional spurious readings: see the occasional anomalous single readings on the graph. Looking at a couple of these in the underlying data:
The high temp value just after 3.00 am. Note that 18.2 is exactly twice 9.1:
2017-04-29 03:04:26,9.1,81.7
2017-04-29 03:04:36,18.2,81.7
2017-04-29 03:04:46,9.1,81.8
The low temp value just before 6.00 am. The absolute value is correct, but the sign is wrong:
2017-04-29 05:51:11,5.6,88.8
2017-04-29 05:51:21,-5.5,88.8
2017-04-29 05:51:31,5.5,88.8
I believe the output from the underlying AM2302 / DHT22 measurement chip includes a checksum, which should catch these sorts of errors. So I wonder if it’s something in the library or perhaps the GrovePi firmware. Or perhaps it’s a faulty sensor?
I’m seeing similar issues with the humidity readings as well, but I can’t include the graph as the forum software only lets me post one image. I may include it in a follow-up if it helps.
Has anyone seen anything similar to this? I can try a different language if that would help narrow down the problem.