Reading temperature from Temperature and Humidity Sensor


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 “”, line 36, in <module>
File “/home/pi/work/GrovePi/Software/Python/”, line 52, in temp
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?

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.


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:

The firmware and software update is out along with documentation related to the working of the GrovePi .

The DHT sensor is now supported.


I also try to read the dht sensor. I have updated the firmware, in 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
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 ??
What did I mis?

Hi arne,

you need to call the function this way:



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

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


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)

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:

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


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 file, all I get is a IOError: [Errno 13] Permission denied

pi@raspberrypi ~/GrovePi/Software/Python $ python
Traceback (most recent call last):
  File &quot;;, line 4, in &lt;module&gt;
    import grovepi
  File &quot;/home/pi/GrovePi/Software/Python/;, 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

import grovepi

# Connect the Grove Temperature &amp; Humidity Sensor Pro to digital port D4
sensor = 4

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

    except IOError:
        print &quot;Error&quot;

I have tried running via sudo too:

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

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

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

Any suggestions?

Ummm so yeah… I re-ran the script and now I’m reporting out of the script!

Of course…

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