Temp Humidity Sensor


#1

I’ve been struggling to get this program working. I’m using a humidity sensor to turn a fogger on and off through a relay for an aeroponics project. First, I was getting “0” as the reading because the firmware hadn’t been upgraded. I updated the firmware after numerous failed attempts. Then, I got error messages, so I reinstalled the software. Now, it freezes up when I run the program. It just sits there with a gray cursor.

Here’s the program I’m running. I’m using a RPi B+ with a GrovePi running Raspbian, the digital temp/humidity sensor, and the Grove Relay. The relay worked fine when the sensor reading was coming out “0”. And I wrote a separate program just to turn the relay off and it worked.

Here is the program:

import time
import grovepi
import sys

sensor=7
relay=4

while True:
try:
sys.stderr.write(“x1b[2Jx1b[H”)
[temp, humidity]=grovepi.dht(sensor,1)
print humidity
if humidity < 80:
grovepi.digitalWrite(relay,1)
time.sleep(5)
else:
grovepi.digitalWrite(relay,0)
except IOError:
print “Error”

I’ve rebooted the Pi multiple times. I put several print commands in and it appears to be freezing at the [temp, humidity]=grovepi.dht(sensor,1) line. It prints just before that but does not print just after that. The sensor is plugged into port D7 and the relay is plugged into D4.

Thanks in advance.


#2

When I ^C break the program, it always seems to be on line 248 in dht “time.sleep(.6)”. I don’t know if that helps.


#3

Hey,
Can you run sudo i2cdetect -y 1 and paste what you see here. Also, does the standalone program to print the temp and humidity values work?

-Karan


#4

i2cdetect shows a 04 in the (00,4) cell. I can post a picture if it helps. When I run the program, grove_dht_pro.py, I just get temp = nan and humidity = 0.0.


#5

I’ve been having issues updating the firmware also. Yesterday, I got it to (appear to) work once, but it never asked me the question about I2C Search or Direct upload. It did say “Fuses OK” at the end.
Today, I’m trying to run it again and I just get,
“Cloning into ‘GrovePi’…
error: gnutls_handshake() failed: A TLS packet with unexpected length was received. while accessing https://github.com/DexterInd/GrovePi/info/refs
fatal: HTTP request failed” It kept giving me that message yesterday also. I downloaded the files directly from github and that didn’t work either. Finally, it simply worked, but maybe not completely.

Is there another way to update the firmware? When I run the program to check the firmware, it says, “GrovePi has firmware version: 1.2.2”

Any help would be appreciated. Tomorrow is the last day of school for these students and their project was featured on the instructables website. People are waiting for the updated code. Thanks!


#6

I rebooted the Pi and then ran the firmware update again. Once again, it appears to work, but it didn’t ask me the question about Direct upload or I2C search like the instructions say. Here’s how the install went:

Updating the GrovePi firmware

Do you want to update the firmware? [y,n]y
Make sure that GrovePi is connected to Raspberry Pi
Firmware found
Connect the jumper to the Reset pin and Press any key to start firmware update
. . .
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "grove_pi_firmware.hex"
avrdude: input file grove_pi_firmware.hex auto detected as Intel Hex
avrdude: writing flash (14480 bytes):

Writing | ################################################## | 100% 13.86s

avrdude: 14480 bytes of flash written
avrdude: verifying flash memory against grove_pi_firmware.hex:
avrdude: load data flash data from input file grove_pi_firmware.hex:
avrdude: input file grove_pi_firmware.hex auto detected as Intel Hex
avrdude: input file grove_pi_firmware.hex contains 14480 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 12.54s

avrdude: verifying …
avrdude: 14480 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.


#7

OK, it seems to be mostly working now. I used a new sensor, a new raspberry pi, I updated the firmware about 10 times, and put new wires. I don’t know which one fixed it. Two issues now. 1- The humidity isn’t coming out as a number from 0-100 like I’ve seen in the examples. It’s coming out in the range of 1500-3000. Not the end of the world.

2- The program crashes with an IOError after about 10 minutes. The error reads:
IOError
Traceback (most recent call last):
File “aero.py”, line 12, in <module>
[temp, humidity]=grovepi.dht(sensor,1)
TypeError: ‘int’ object is not iterable

I put an error-catching line in my program, but this appears to be happening in the dht module or grovepi module. Any way to keep it from crashing when this error occurs?


#8

Hey,
For the wrong reading, can you check this forum response http://www.dexterindustries.com/forum/?topic=537-6c-displayed-in-home-weather-project/#post-4485 to make sure that you are running the right code.

There is no way around the exception handling, the GrovePi is sometimes unable to read the values from the sensors and gives out an IO Error but it should be pretty easy to catch it and resolve the problem.

-Karan


#9

Hi guys,
I have a probleme with my temperature sensor:
the script worked fine, but one day one bug
now the temperature block to 30° always !

temperature = grovepi.temp(sensor, ‘1.1’)
print “temperature=”, temperature

I try with ‘1.0’ ‘1.1’ ‘1.2’ and only (sensor) and nothing:

temperature= 30.25566
I have try with an other sensor of temperature and same problem.
Any idea ? I don’t understand before this sensor worked fine.
http://www.gotronic.fr/art-capteur-de-temperature-grove-sen23292p-18965.htmtemperature_sensor


#10

I’ve had the same issue on and off. There are many things that could be causing it. Make sure to update the firmware on your GrovePi if you haven’t already. The old firmware does not support dht. Also, I found that the temp/humidity sensors are not stainless steel and they corrode in the fog. That’s a pretty huge design flaw.