Reading temperature from Temperature and Humidity Sensor


#1

Hi,

It’s me again. :slight_smile:

Got GrovePi working nice today with Your help, relays are switching and some other sensors are read fine, but I can’t seem to get temperature sensor working.

Raw value of sensor seems to be always 1023 and when trying to read temperature with t=grovepi.temp(1) i get math domain error:

analog pin 1 raw value: 1023

Traceback (most recent call last):
File “test.py”, line 36, in <module>
t=grovepi.temp(a1)
File “/home/pi/work/GrovePi/Software/Python/grovepi.py”, line 52, in temp
t=(float)(1/(math.log(resistance/10000)/3975+1/298.15)-273.15)
ValueError: math domain error

Well, that’s of course what you get when trying to calculate (1023-1023)*10000/1023, so the question is; Why the raw value is always 1023?

I use DHT11 based Grove Temperature and Humidty Sensor, which is in the supported sensor list, but obviously i’m missing something here. Maybe it’s because this is my first python project and I haven’t used grove sensors or even arduino before either…
Am I trying to use even right function?


#2

Hi,
The Temperature and Humidity sensor uses another library called DHT.h with Arduino. The code that you have been trying is for the analog temperature sensor which gives an analog reading. We are working on the getting the functions included in the firmware and software and would send a software update this week which will solve the problem and add other features too.

Sorry for the inconvenience.


#3

Hello,

I actually came into same conclusion later yesterday when I googled that sensor of mine some more, read some of dht.h and realized that the sensor is digital, not analog :smiley:

I got mixed up with this because same sensor was in the supported list, so I imagined somehow that the libraries, functions etc are already there.

I’ll wait for the update, thanks again :slight_smile:


#4

Hi,
The firmware and software update is out along with documentation related to the working of the GrovePi http://www.dexterindustries.com/forum/?topic=grovepi-firmware-update-v1-1 .

The DHT sensor is now supported.


#5

Hi,

I also try to read the dht sensor. I have updated the firmware, in grovepi.py is dht defined. I am not familiar with arduino and a beginner in python programming. My (simple) program is like this:

import smbus
import time
import grovepi
bus = smbus.SMBus(0)
address = 0x04
pin=4
module_type=0
print dht(pin,module_type)

The error I get is this:

    print dht(pin,module_type)
NameError: name &#039;dht&#039; is not defined

I thought the dht is defined in grovepi.py ??
What did I mis?


#6

Hi arne,

you need to call the function this way:

grovepi.dht(pin,module_type)

Greetings
Falco


#7

Hi arne,
To use the “dht” function, either import the grovePi library like:
from grovepi import *
or use
print grovepi.dht(pin,module_type)


#8

Thank you for the help guys! No errors in the code anymore.

but… nothing sensible comes from the sensor:

[nan, 0.0]

My code:


import smbus
import time
import grovepi

bus = smbus.SMBus(0)

address = 0x04

pin=4
module_type=2

print grovepi.dht(pin,module_type)

I have a temperature humidity sensor pro. I have searched for tutorials to get it worked but no satisfying results yet.
My final goal is to get temperature readings on a website, I managed getting a website running on the raspberry pi. I am stuck with:

  • Getting sensor readings
  • Showing them on the website (using python)

#9

Hi Arne,
Sorry for all the troubles. Just wanted to check that if you have update the firmware on the GrovePi too. Changes were made to the firmware so do update the firmware too to get the DHT working.

Please follow the guide here to update the firmware: http://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/updating-firmware/

If it still does not work, please post again on the forums.

Thanks,
Karan


#10

Hello, also new to the GrovePi and trying to do almost the exact same thing as Arne. I have the DHT pro connected to D4.

Every time I run the grove_dht_pro.py file, all I get is a IOError: [Errno 13] Permission denied

pi@raspberrypi ~/GrovePi/Software/Python $ python grove_dht_pro.py
Traceback (most recent call last):
  File &quot;grove_dht_pro.py&quot;, line 4, in &lt;module&gt;
    import grovepi
  File &quot;/home/pi/GrovePi/Software/Python/grovepi.py&quot;, line 21, in &lt;module&gt;
    bus = smbus.SMBus(1)
IOError: [Errno 13] Permission denied

I can’t tell if the GrovePi is even seeing the sensors, the i2cdetect is below. The firmware has been updated as well

pi@raspberrypi ~/GrovePi/Software/Python $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- 04 -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

I am running the following code:

# GrovePi + Grove Temperature &amp; Humidity Sensor Pro
# http://www.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro

import grovepi

# Connect the Grove Temperature &amp; Humidity Sensor Pro to digital port D4
# SIG,NC,VCC,GND
sensor = 4

while True:
    try:
        [temp,humidity] = grovepi.dht(sensor,1)
        print &quot;temp =&quot;, temp, &quot; humidity =&quot;, humidity

    except IOError:
        print &quot;Error&quot;


#11

I have tried running via sudo too:

pi@raspberrypi ~/GrovePi/Software/Python $ sudo grove_dht_pro.py
sudo: grove_dht_pro.py: command not found


#12

Seems like something related to the smbus.SMBus(1)

pi@raspberrypi ~/GrovePi/Software/Python $ python grovepi.py
Traceback (most recent call last):
  File &quot;grovepi.py&quot;, line 21, in &lt;module&gt;
    bus = smbus.SMBus(1)
IOError: [Errno 13] Permission denied

Any suggestions?


#13

Ummm so yeah… I re-ran the install.sh script and now I’m reporting out of the grove_dht_pro.py script!

Of course…


#14

You should try using sudo python grove_dht_pro.py . This should solve the problem.

-Karan


#15