Raspi GrovePi Temperature&Humidity Sensor showing -1 -1

grovepi
sensors
update

#1

Hey guys!

I currently working with a Humidity&Temperature Sensor from GrovePi and I’m using a Zero board on a Raspberry pi 3.

I installed everthing according to the documentation of Grovepi. But when i built script or use sample script the only Thing i get out is -1 Temperature and -1 Humidity :frowning: The Port is D3 (Script is correct).

Please help me! Thank you

Best Regards,
Dean


#2

Hi @dean.meyer,

Before we do the testing, can you tell us the following:

  1. What Humidity and Temperature Sensor are you using? There are quite a few on the market and we need to make sure we’re talking about the same product. Please show us a link to the product or at least a close-up photo of the sensor.

  2. Can you pinpoint us to the script you’re trying to run? Give us a link or embed the code into this thread - don’t forget to preformat it.

  3. Do you use a GrovePi Zero with a Pi or a GrovePi with a Pi Zero?

  4. Is your GrovePi updated to the latest version?

  5. Are you using Raspbian For Robots? If so, is it updated to the latest version?

Thank you!


#3

Hey,

First of all thanks for your answer.

  1. The grove temperature and humidity sensor: https://www.pi-shop.ch/grove-temperature-humidity-sensor-pro
  2. I used the Default script from GrovePi. After a Little Research i found this one and customized it:

import grovepi
import math
import numpy
import threading
from time import sleep
from datetime import datetime

sensor = 3  # The Sensor goes on digital port 3 D3.
# temp_humidity_sensor_type
blue = 0    # The Blue colored sensor.
white = 1   # The White colored sensor.

filtered_temperature = [] # here we keep the temperature values after removing outliers
filtered_humidity = [] # here we keep the filtered humidity values after removing the outliers

lock = threading.Lock() # we are using locks so we don't have conflicts while accessing the shared variables
event = threading.Event() # we are using an event so we can close the thread as soon as KeyboardInterrupt is raised

# function which eliminates the noise
# by using a statistical model
# we determine the standard normal deviation and we exclude anything that goes beyond a threshold
# think of a probability distribution plot - we remove the extremes
# the greater the std_factor, the more "forgiving" is the algorithm with the extreme values
def eliminateNoise(values, std_factor = 2):
    mean = numpy.mean(values)
    standard_deviation = numpy.std(values)

    if standard_deviation == 0:
        return values

    final_values = [element for element in values if element > mean - std_factor * standard_deviation]
    final_values = [element for element in final_values if element < mean + std_factor * standard_deviation]

    return final_values

# function for processing the data
# filtering, periods of time, yada yada
def readingValues():
    seconds_window = 10 # after this many second we make a record
    values = []

    while not event.is_set():
        counter = 0
        while counter < seconds_window and not event.is_set():
            temp = None
            humidity = None
            try:
                [temp, humidity] = grovepi.dht(sensor, white)

            except IOError:
                print("we've got IO error")

            if math.isnan(temp) == False and math.isnan(humidity) == False:
                values.append({"temp" : temp, "hum" : humidity})
                counter += 1
            #else:
                #print("we've got NaN")

            sleep(1)

        lock.acquire()
        filtered_temperature.append(numpy.mean(eliminateNoise([x["temp"] for x in values])))
        filtered_humidity.append(numpy.mean(eliminateNoise([x["hum"] for x in values])))
        lock.release()

        values = []

def Main():
    # here we start the thread
    # we use a thread in order to gather/process the data separately from the printing proceess
    data_collector = threading.Thread(target = readingValues)
    data_collector.start()

    while not event.is_set():
        if len(filtered_temperature) > 0: # or we could have used filtered_humidity instead
            lock.acquire()

            # here you can do whatever you want with the variables: print them, file them out, anything
            temperature = filtered_temperature.pop()
            humidity = filtered_humidity.pop()
            print('{},{:.01f},{:.01f}' .format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), temperature, humidity))

            lock.release()

        # wait a second before the next check
        sleep(1)

    # wait until the thread is finished
    data_collector.join()

if __name__ == "__main__":
    try:
        Main()

    except KeyboardInterrupt:
        event.set()
  1. I use a GrovePi Zero with Pi 3.
  2. It should be :). Where can i see that. I did execute all commands that were recommended in the wiki.
  3. No, i use it to take temperature and humidity from our Server Room. It is on the latest Version.

Thank you.

Best Regards,
Dean


#4

Hi @dean.meyer,

I’ve used the modified script you’ve provided me and tried it on a Grove DHT - Blue Version sensor and it worked. Here are the values I got with it.

temp_humidity_blue_sensor

The only 2 major differences between we had in our tests are:

  • I have the Blue version of the DHT sensor while you have the White version of it.

  • You are using a GrovePi Zero (which I do not have for the moment) while I’m using a regular GrovePi.

Therefore, there are 2 things we could do:

  • Use a Blue version of the DHT sensor and see if it works - unfortunately, I don’t have a White version of the sensor. If we discover the Blue one works and the White one doesn’t, then it means there’s an issue with the firmware of the GrovePi - we should not care about this option for now.

  • Run the troubleshooter for the GrovePi board and afterward update the firmware of the GrovePi (pay attention that I’m referring to the firmware and not the software on the Raspberry Pi).
    In order to troubleshoot the firmware of the GrovePi run: sudo bash path-to-GrovePi-repo/GrovePi/Troubleshooting/all_tests.sh. Logs will be written to Desktop - get them and post them here.
    In order to update the firmware of the GrovePi run: sudo bash path-to-GrovePi-repo/GrovePi/Firmware/firmware_update.sh.
    After you do all these steps, try running your script again.

Let’s see where all these take us.

Thank you!


#5

Hey @RobertLucian

Thank you very much for your testing and answer.

Here are the Firmware Logs:

=============================
GrovePi Troubleshooting Script
=============================
all_tests.sh: line 6: cd: /Troubleshooting: No such file or directory

Adding permissions to the scripts
=================================

Check space left
================
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       6.0G  3.7G  2.1G  65% /
devtmpfs        459M     0  459M   0% /dev
tmpfs           463M     0  463M   0% /dev/shm
tmpfs           463M  6.4M  457M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           463M     0  463M   0% /sys/fs/cgroup
/dev/mmcblk0p6   63M   20M   43M  32% /boot
tmpfs            93M     0   93M   0% /run/user/109
tmpfs            93M     0   93M   0% /run/user/1000
tmpfs            93M     0   93M   0% /run/user/1001
/dev/mmcblk0p5   30M  437K   28M   2% /media/administrator/SETTINGS

Check for dependencies
======================
python 2.7.9-1 install ok installed
python-pip 1.5.6-5 install ok installed
git 1:2.1.4-2.1+deb8u4 install ok installed
libi2c-dev 3.1.1+svn-2 install ok installed
python-serial 2.6-1.1 install ok installed
python-rpi.gpio 0.6.3~jessie-1 install ok installed
i2c-tools 3.1.1+svn-2 install ok installed
python-smbus 3.1.1+svn-2 install ok installed
arduino 2:1.0.5+dfsg2-4 install ok installed
minicom 2.7-1+deb8u1 install ok installed
scratch 1.4.0.6~dfsg1-5 install ok installed

wiringPi Not Found (ERR)
wiringPi Found
I2C still in blacklist (ERR)
SPI still in blacklist (ERR)


Check for addition in /modules
==============================
I2C-dev already there
i2c-bcm2708 already there
spi-dev already there


Hardware revision
=================
gpio version: 2.36
Copyright (c) 2012-2015 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: Pi 3, Revision: 02, Memory: 1024MB, Maker: Sony 
  * Device tree is enabled.
  *--> Raspberry Pi 3 Model B Rev 1.2
  * This Raspberry Pi supports user-level GPIO access.


Check the /dev folder
=====================
i2c-1
ttyAMA0

USB device status
=================
Bus 001 Device 005: ID 04b3:3025 IBM Corp. NetVista Full Width Keyboard
Bus 001 Device 004: ID 046d:c046 Logitech, Inc. RX1000 Laser Mouse
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 2: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 3: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
Raspbian for Robots Version
===========================
cat: /home/pi/di_update/Raspbian_For_Robots/Version: No such file or directory


Hostname
========
lrasp001


Checking for Atmega chip
========================


avrdude: Version 5.10, compiled on Jun 18 2012 at 12:38:29
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : unknown
         Using Programmer              : gpio
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : GPIO
         Description     : Use sysfs interface to bitbang GPIO lines

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

avrdude done.  Thank you.


Checking I2C bus for devices
============================

Checking I2C bus 0
==================
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory

Checking I2C bus 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: -- -- -- -- -- -- -- --                         

Checking for firmware version
=============================
python: can't open file '/Software/Python/grove_firmware_version_check.py': [Errno 2] No such file or directory
Log has been saved to Desktop. Please copy it and send it by email or upload it on the forums

There was an error reading out the actual firmware of the ZeroPi. So i run the script separate and the Version is the following: 1.2.2

The update failed to. Here is the output:

administrator@lrasp001:~ $ sudo bash Desktop/grovepi/Firmware/firmware_update.sh 
Updating the GrovePi firmware
=============================
 http://www.dexterindustries.com/grovepi 
 Run this program: 
 sudo ./firmware_update.sh
 
=============================
Do you want to update the firmware? [y,n]y
Make sure that GrovePi is connected to Raspberry PiDesktop/grovepi/Firmware/firmware_update.sh: line 18: [: ./GrovePi/Firmware/grove_pi_firmware.hex: unary operator expected

Firmware not found
Check if firmware is there or run again
Press any key to exit

I don’t have a blue DHT Sensor. Maybe i can get hands on a GrovePI (note zero).

We’re getting closer :slight_smile:
Thanks again!

Best Regards,
Dean


#6

Hi @dean.meyer,

It seems like a couple of things are not to be found on your system, which could be the reason for why it doesn’t work on yours. Also, this may explain why the DHT sensor doesn’t work.

Since you’ve been starting to do this on a fresh image of Jessie, I’m going to do it too, test and then see if there are differences between what you’re getting and what you got.

Be right back with an answer.

Thank you!


#7

Hi @dean.meyer,

I’ve tested your case and it worked for me.
Most likely, there was a missed step in your case. So, let’s get this done now.

Here’s what I did:

  1. Burned a fresh Jessie image on a micro SD Card and booted up the Pi.

  2. In a terminal, I typed the sudo curl -L dexterindustries.com/grovepi_setup | bash command. Make sure to reboot at the end.

  3. Installed the firmware for the GrovePi by entering the sudo bash firmware_update.sh command inside the Firmware folder.

  4. Enjoyed the experience :smiley: .

There’s also a more complex way of installing it and it involves cloning the repository and then running the install.sh script that’s in the Script folder.

Please try out these steps and then tell us how it went.

Thank you!


#8

Hi @RobertLucian ,

Thank you for your answer.

I created a new Jessie Image on my micro Card. Then i tried to execute the command sudo curl -L dexterindustries.com/grovepi_setup | bash. It failed again :pensive:. I got en Doctype error. In the afternoon i try to install it like i did it the first time.

Regards,
Dean


#9

Hi @dean.meyer,

Okay, that’s probably because there’s a missing option in the command.
It should have been the following way:

sudo curl -kL dexterindustries.com/update_grovepi | bash

Can you try this and tell us if it worked for you?

Thank you!


#10

Hello @RobertLucian

It’s been a long time :slight_smile: since my last post. We still have our difficulties with the Zero Pi.

So this is the Script we use at the moment:

import grovepi
import math
import numpy
import threading
import csv
from time import sleep
from datetime import datetime



sensor = 3  # The Sensor goes on digital port 3 D3.
# temp_humidity_sensor_type
blue = 0    # The Blue colored sensor.
white = 1   # The White colored sensor.

filtered_temperature = [] # here we keep the temperature values after removing outliers
filtered_humidity = [] # here we keep the filtered humidity values after removing the outliers

lock = threading.Lock() # we are using locks so we don't have conflicts while accessing the shared variables
event = threading.Event() # we are using an event so we can close the thread as soon as KeyboardInterrupt is raised


# function which eliminates the noise
# by using a statistical model
# we determine the standard normal deviation and we exclude anything that goes beyond a threshold
# think of a probability distribution plot - we remove the extremes
# the greater the std_factor, the more "forgiving" is the algorithm with the extreme values
def eliminateNoise(values, std_factor = 2):
    mean = numpy.mean(values)
    standard_deviation = numpy.std(values)

    if standard_deviation == 0:
        return values

    final_values = [element for element in values if element > mean - std_factor * standard_deviation]
    final_values = [element for element in final_values if element < mean + std_factor * standard_deviation]

    return final_values

# function for processing the data
# filtering, periods of time, yada yada
def readingValues():
    seconds_window = 10 # after this many second we make a record
    values = []

    while not event.is_set():
        counter = 0
        while counter < seconds_window and not event.is_set():
            temp = None
            humidity = None
            try:
                [temp, humidity] = grovepi.dht(sensor, white)

            except IOError:
                print("we've got IO error")

            if math.isnan(temp) == False and math.isnan(humidity) == False:
                values.append({"temp" : temp, "hum" : humidity})
                counter += 1
            #else:
                #print("we've got NaN")

            sleep(1)

        lock.acquire()
        filtered_temperature.append(numpy.mean(eliminateNoise([x["temp"] for x in values])))
        filtered_humidity.append(numpy.mean(eliminateNoise([x["hum"] for x in values])))
        lock.release()

        values = []

def Main():
    # here we start the thread
    # we use a thread in order to gather/process the data separately from the printing proceess
    data_collector = threading.Thread(target = readingValues)
    data_collector.start()

    with open('/mnt/Austausch/names.csv', 'w') as csvfile:
        fieldnames = ['date', 'temperature', 'humidity']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        writer.writeheader()

    


        while not event.is_set():
             if len(filtered_temperature) > 0: # or we could have used filtered_humidity instead
                lock.acquire()
                # here you can do whatever you want with the variables: print them, file them out, anything
                temperature = filtered_temperature.pop()
                humidity = filtered_humidity.pop()
                zeit = datetime.now().strftime("%d-%m-%Y %H:%M:%S")
                print(zeit)
                print(temperature)
                print(humidity)
                # print('{},{:.01f},{:.01f}' .format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), temperature, humidity))
                writer.writerow({'date': zeit , 'temperature': round(temperature,1) , 'humidity': round(humidity,1)})
                lock.release()
            # wait a second before the next check
        sleep(1)

    # wait until the thread is finished
    data_collector.join()

if __name__ == "__main__":
    try:
        Main()

    except KeyboardInterrupt:
        event.set()

When we start the script it writes the right temperature & humidity into a csv file. The csv lays on a mounted QNAP share with public permissions. From there a powershell script generates a mail to our exchange mailbox. Everthing works fine for 5-6 hours. But then the temperature & Humidity Drops to -1 -1. The same Problem we had before. Not even a reboot helps.

Our other difficulites with the Raspberry PI are:

  1. The time on the raspi is always false. We try to edit the config file and also tried to add a time server. Nothing worked so far.
  2. When we reboot the share doesn’t get mounted again. We added the mount command to the “Autostart” config file. This didn’t work too.

Maybe you can help us with this two difficulites too. :slight_smile:

Thank you very much!

Best Regards,
Dean


#11

We just made a new Script and solved the Time problem.

Our new Script is much easier, but we still get the -1 -1.

import grovepi
import math
import csv
import sys
import os.path
from time import sleep
from datetime import datetime



sensor = 3  # The Sensor goes on digital port 3 D3.
# temp_humidity_sensor_type
blue = 0    # The Blue colored sensor.
white = 1   # The White colored sensor.

while True:
    try:
        # the first parameter is the port, the second parameter ist the type of sensor.
        [temperature,humidity] = grovepi.dht(sensor,white)
        if math.isnan(temperature) == False and math.isnan(humidity) == False:

            file_exists = os.path.isfile('/mnt/Austausch/names.csv')
            
            with open('/mnt/Austausch/names.csv', 'a') as csvfile:
                fieldnames = ['date', 'temperature', 'humidity']
                writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
                
                if not file_exists:
                    writer.writeheader() # if file doesn't exist, write a header yet
                
                zeit = datetime.now().strftime("%d-%m-%Y %H:%M:%S")
                print(zeit)
                print(temperature)
                print(humidity)
                writer.writerow({'date': zeit , 'temperature': round(temperature,1) , 'humidity': round(humidity,1)})
                sys.exit()
                
    except IOError:
            print("Error")

Thank you!

Best Regards,
Dean


#12

Hi @dean.meyer,

I’ve seen your posts and we’ll take a look at it and come back with an answer ASAP.

Thank you!


#13

Hello @RobertLucian,

We are still waiting for an answer.

Thank you!


#14

Hi @dean.meyer,

You’re telling us that after some hours (5-6) you get (-1, -1) as values for the temperature and humidity.
From my experiments, it’s expected to get those results, so as long as it works for most of time, it’s all good.

We never deep-dived into this issue of the DHT, because we’re not the manufactures of this sensor and instead we had tried to find a workaround for it.
The solution I came with some many months ago was to ignore these outlier values (i.e. (-1, -1)) and print/save/log the rest of them.
Here’s my post from that time (please fully read it even though it’s quite big):

I can also see you had tried using it, but then you ditched the solution for some reason and you winded up with a solution that does not eliminate outlier values. Because of this, I suggest you read the linked post and then tell us if it had helped you.

If we didn’t get your right or if there’s something still unclear, please tell us.
Hope this will solve your issue.

Thank you!


#15

A post was split to a new topic: Installing the GrovePi