Temperature and Humidity (HDC1000) Reporting Problems


#1

Help with python script reporting temperature and humidity from the sensor and displays. Grove – Temperature&Humidity Sensor Pro SKU: SEN51035P from SeedStudio

Issue - py script reporting temp = nan F humidity = nam % (It works about half the time)

Requesting additional help or suggestions to modify python script, I would like to not report the temp = nan F humidity = nan %

Listed below the py script output report.

temp = 78.8 F humidity = 34.4 %
temp = nan F humidity = nan %
temp = nan F humidity = nan %
temp = nan F humidity = nan %
temp = nan F humidity = nan %

Listed below the py script report that’s running.

display_temp.py

This scripts access the temperature and humidity from the sensor and displays on the screen (updated every few seconds)

import time

from grovepi import *
from grove_rgb_lcd import *

dht_sensor_port = 7 # Connect the DHt sensor to port 7
dht_sensor_type = 1

setRGB(51,102,153)

while True:
try:
[ temp,hum ] = dht(dht_sensor_port,dht_sensor_type)
currTime=time.strftime(“%I:%M%p”)
currDay=time.strftime(“%D”)
temp = round(temp * 9/5 + 32,1)
print “temp =”, temp, “F\thumidity =”,hum,”%”
t = str(temp)
h = str(hum)
setText(“SmartKeg ” + currTime + t + “F ” + currDay)
time.sleep(1)
except (IOError,TypeError) as e:
print “Error”


#2

After reading the temperature and humidity, you can check the temperature and humidity values and make sure that they are not a nan. If they are nan, just throw an exception and catch them with a try,catch block. Here is an example on how to do it:

import math
while True:
    try:
        [ temp,hum ] = dht(dht_sensor_port,dht_sensor_type)
        if math.isnan(temp) or math.isnan(hum):
            raise ValueError('nan found')
        print temp,hum #Normal program here
    except (IOError,TypeError,ValueError) as e:
        print "Error"

Do let us know if this helps.


#3

Hi Karan, Thank you again for your help and support.
I made the changes to the zz.py prg and I’m receiving the following error message. Do you have any suggestion to correct the py codding error?
24.1 48.1
Error
Traceback (most recent call last):
File “zz.py”, line 22, in <module>
raise ValueError(‘nan found’)
ValueError: nan found


listed beloy the zz.py prg.

zz.py

This scripts access the tempeture and humidity from the sensor and displays on the screen (updated every few seconds)

import time
import math

from grovepi import *
from grove_rgb_lcd import *

dht_sensor_port = 4 # Connect the DHt sensor to port 7
dht_sensor_type = 1

#setRGB(51,102,153)

while True:
try:
[ temp,hum ] = dht(dht_sensor_port,dht_sensor_type)
if math.isnan(temp) or math.isnan(hum):
raise ValueError(‘nan found’)
print temp,hum
currTime=time.strftime("%I:%M%p")
currDay=time.strftime("%D")
temp = round(temp * 9/5 + 32,1)
t = str(temp)
h = str(hum)
setText("SmartKeg " + currTime + t + "F " + currDay)
time.sleep(1)
except (IOError,TypeError) as e:
print “Error”


#4

Hi Billh,
Can you change your second last line with the except block and add a statement to catch the Value error. It should look like this: except (IOError,TypeError,ValueError) as e:.


#5

Hi Karan, Thank you. Your suggestion addressed and corrected the Traceback error.

Yes, that worked. I’m now receiving the following Error message (listed below the py output message).

Question - how can I not print the Error message and only print the tem and hum reading?

24.7 47.5
Error
Error
Error
24.8 47.5
Error
Error
Error
24.7 47.5
Error
Error
24.8 47.5
Error
24.8 47.5
Error
Error
24.7 47.4
Error
Error
Error
24.8 47.5


#6

If you don;t want an error message at all, you should replace the print in the except to pass. So, except (IOError,TypeError,ValueError) as e: print "Error" becomes except (IOError,TypeError,ValueError) as e: pass. That should suppress the error messages.


#7

Karan, Outstanding Job and Thank You! The error message now suppresses. Can you please don’t close this form. I need to now start to re-install everything we had connected to the grovepi.

Thanks again for all your help and outstanding support.


#8

Hey billh,
Great to hear that the problem is solved. I think you had posted the problem on stackoverflow too. It would be great if you could close the problem and mark it as solved and post a link to this discussion. Sorry for closing the thread early last time. I’ll keep it open this time.

-Karan