Grove- Temperature and Humidity Sensor - Nan Value


#1

I have connected Grove Light, Sound and Temperature/Humidity sensor to GrovePi and running separate python scripts to fetch the sensors every 1/2 second.

Observed that whenever any other script is running with Temperature/Humidity script, the Temperature/Humidity script outputs “Nan”. If Temperature/Humidity script is running alone then it reports correct values.

Is there any issue with the simultaneously Temp/Humidity data?

Light Sensor is connected to A0, Sound to A1 and Temp/Humdity to D6. GrovePi firmware is latest 1.1.

Any help?


#2

After reading all the posts in the forum, I have some doubts:

  1. Does DHT sensor needs to be connected to D4 only? I am using A6.

  2. Is it ok to use adjusent connectors? I am using A0 and A1 for light and sound. Also have A6 DHT and A5 Buzzer.


#3

HI,
The DHT sensor can be connected to any port for D2 to D6. Please check the port diagram here to see if you are connecting it right: http://www.dexterindustries.com/GrovePi/engineering/port-description/ .

There is no A6, A5 port on the GrovePi so just double check the connections in the program.

If this does not help, can you post a picture of your setup and the program code that you are using .

-Karan


#4

Sorry I meant D5 and D6. I have removed all the sensors now and have only temperature/Humidity - D4 and Button - D1. When I am polling (Pything script) D1 for Button status, I start getting Nan in temperature script. As soon as I stop the Button Script, I get correct temperature and humidity values.


#5

Hi,
Try this, poll the DHT sensor twice to see if the error you get any correct values.

If it still does not work, can you paste your code here.

-Karan


#6

Attaching two files:
temperature/humidity - hnt.py - D4
button - btn.py - D1

Output when I run both scripts:

hnt.py output

temperature nan humidity nan
temperature nan humidity nan
temperature nan humidity nan
temperature nan humidity nan

btn.py output

Value 0
Value 0
Value 0
Value 0

Above is a sample output. Both the scripts are continuously running.


#7

#hnt.py

import grovepi
import time
import sys,getopt
import json
import math

Connect the Grove Temperature & Humidity Sensor Pro to digital port D4

SIG,NC,VCC,GND

sensor = 4

while True:
try:
[temp,humidity] = grovepi.dht(sensor,0)
print 'temperature ',temp, 'humidity ',humidity

if math.isnan(temp) or  math.isnan(humidity):
	[temp,humidity] = grovepi.dht(sensor,0)
	print 'temperature ',temp, 'humidity ',humidity

time.sleep(.5)

except KeyboardInterrupt:
	print "Bye bye"
	break
except IOError:
	print ""

#btn.py
import time
import grovepi
import sys
import json

Connect the Grove Button to digital port D1

SIG,NC,VCC,GND

button = 1

grovepi.pinMode(button,“INPUT”)

while True:
try:
val = grovepi.digitalRead(button)
print 'Value ',val

    time.sleep(.5)

#except KeyboardInterrupt:
#print ""
except IOError:
   print ""

`


#8

Hi,
Can you try using 1 as the argument in the command that asks for temperature, e.g: [temp,humidity] = grovepi.dht(sensor,1) instead of [temp,humidity] = grovepi.dht(sensor,0).

Let me know if this helps.

-Karan


#9

1 does not work. Its not a pro sensor.


#10

Hi,
Sorry for that.

have you been able to get the sensor to work at all in any case?

-Karan


#11

YES the Temperature/Humidity sensor works if there is no other script running to read status of any other sensor. Is there any issue with python libraries? May be while the python script is running to process the temperature/humidity data, if any other sensor data is read, it corrupts the temperature/humidity data. This is just a guess.

Is there any other library c/c++/or java to use with raspberrypi+groovepi? I tried to compile arduino based c/c++ library but can’t get them to work.


#12

Hi,
Sorry but there is no other language which supports the GrovePi completely.

How the GrovePi works is that, the Raspberry Pi sends a command to the GrovePi. The GrovePi runs that command and stores the result back into a message buffer. The RaspberryPi then requests it to send the data back after some time (there has top be a small delay between the two so that we are sure that the data is loaded into the buffer), the GrovePi sends the data that is in the buffer.

Your hunch might be right, that the data in the buffer might be getting corrupted. You should put sufficient delay before and after the read.

Also, are you running the two scripts simultaneously?

-Karan


#13

yes I am running both scripts simultaneously.

What is the best way to handle button press event? I am just polling the sensor with sleep of 500ms. Is this correct way?

Are you suggesting not to run scripts simultaneously?

Why is the problem with Temperature/Humidity sensor only? When I run sound, light, button scripts simultaneously, all of them work without any issues.


#14

Hi,
You should not run the scripts simultaneously and should only run one script. We would recommend you to put all your logic in one code itself. The reason being that the input data is loaded into a buffer and the GrovePi waits for a command. When you run two scripts together, the timing can be a mismatch, also there is a sleep command in the GrovePi library, so that may also cause a conflict.

Now the reason that I suspect that other sensors work and the DHT sensor does not, might be that that other sensors are very fast and complete their operations instantaneously whereas the DHT sensor takes some time to read the values back and it might be causing a conflict there.

I would recommend you to not run multiple programs simultaneously.

-Karan


#15

Ok. Thanks for help.

How do you recommended capturing button press event?


#16

Hi,
If you want to do something such as read the DHT sensor when the button is pressed, use an If statement. We have a couple of projects on the GrovePi site that should help you.

You can have a look at the code here and understand how to use the GrovePi inputs to do other things: http://www.dexterindustries.com/GrovePi/projects-for-the-raspberry-pi/raspberry-pi-motion-sensing/

Thanks,
-Karan


#17

Thanks for info and help.


#18

Hi,

I am also facing the same problem, though I am not running simultaneous scripts for the dht sensor. I tried changing the pins but still no improvement. I have many other sensors -that work fine but dht script only gives nan values. Any suggestions? The version of the grovepi firmware is 1.1 (which I guess is up-to-date).

Cheers,
Khattak


#19

Hi Khattak,
Can you describe the problem in a bit more detail. It’ll help us a lot in finding a solution for it .

Thanks,
Karan


#20

Hi,
So I will try to write all my confusions point-by-point. I hope it is clear enough.
1. I have a temperature and humidity sensor pro, that I connect to one of the digital pins (say D4). When I run the example script, it prints Nan for both sensors. The same value is printed if I probe the port when nothing is connected. So basically, it looks like the sensor is not getting recognized.
I have the same problem with Ultrasonic ranger sensor as well. It gives out the max value (65535), which I get if nothing is connected to the port at all.
2. I have tried both dht and ultrasonic ranger sensors one by one without connected any other sensor, to avoid the problem of buffer being overwritten but that has not helped. I have analogue sensors (air quality, sound, light) that are working just fine, even if connected simultaneously and read through multiple scripts.
3. I tried to see if i2cdetect registers any sensors butI can only see the grovespi at 0x04 and nothing else.I am a little confused if these sensors should be shown by i2cdetect as they are not directly connected to Raspberry Pi.
4. Is there any way I can find out the current firmware version of the grovepi apart from looking at the version number in the grovepi repo. It could be that the grovepi shield has been flashed before and the repo is a new download? The repo shows a version of 1.1, which I guess is the up-to-date version.