IOError after several hours of work


#1

Hi,
I bought a GrovePI less than one month ago and I immediately felt in love with it and I started to implement it for a project with my RaspberryPI. Now everything is set up but I’m facing a weird issue.

I have 3 sensors:

  • Light sensor
  • DHT PRO sensor
  • AirQuality sensor

I’m using a modified version of the provided Python script to get access to the sensors, each minute.

Everything works fine except the fact that after few hours (I can’t exactly tell you if it’s constant or not) I start to receive only “IOError”. I tried everything, also the reboot of the RaspberryPI doesn’t work. I have to unplug the power adapter to get everything working back.

Someone have some idea? I think it could be related to a power trouble but … after several tries I’m now totally lost.

Thank you in advance!

EDIT: I forgot to tell you that I upgraded the firmware to the latest available version.


#2

Hey,
We haven’t heard about this kind of error. Can you post the program that you are using and also the ports to which the sensors are connected.

-Karan


#3

Hello Karan,
the sensors are connected as following:

  • Air quality Sensor => Analag 0
  • Temperature & Humidity Sensor Pro => Digital 2
  • Light Sensor => Analog 1

The probing code is actually placed under the “probe()” function.

Thank you for your time

As requested here is the Python script:


# Sensors script
# It uses:
# * GrovePi + Grove Air Quality Sensor (Analog port)
#   --> http://www.seeedstudio.com/wiki/Grove_-_Air_Quality_Sensor
# * GrovePi + Grove Temperature & Humidity Sensor Pro (Analog port)
#   --> http://www.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro
# * GrovePi + Grove Light Sensor (Analog port)
#   --> http://www.seeedstudio.com/wiki/Grove_-_Light_Sensor
import time
import json
import grovepi
import os.path
from pprint import pprint

def version():
    return grovepi.version()

def lock():
    lock_file_path = '/tmp/grove_sensors.lock'
    lock_file = open(lock_file_path, 'w+')
    return;

def unlock():
    lock_file_path = '/tmp/grove_sensors.lock'
    if (os.path.isfile(lock_file_path)):
        os.unlink(lock_file_path)
    return;

def probe():
    lock_file_path = '/tmp/grove_sensors.lock'
    err_output = {}

    if (os.path.isfile(lock_file_path)):
        err_output['err'] = 'sensors busy'
        return json.dumps(err_output)

    lock()

    air_sensor = 0
    dht_sensor = 2
    light_sensor = 1

    # misc. variables
    output = []
    air_output = {}
    dht_output = {}
    light_output = {}

    #
    # PROBING AIR VALUES
    #
    time.sleep(0.5)
    grovepi.pinMode(air_sensor,'INPUT')
    try:
        sensor_value = grovepi.analogRead(air_sensor)
        air_output['value'] = int(sensor_value)
    except IOError as (errno, strerror):
        air_output['err'] = strerror

    #
    # PROBING TEMP/HUMIDITY VALUES
    #
    time.sleep(0.5)
    try:
        [temp,humidity] = grovepi.dht(dht_sensor,1)

        dht_output['temp'] = {}
        dht_output['humidity'] = {}
        dht_output['temp']['value'] = int(temp) - 0.5
        dht_output['humidity']['value'] = int(humidity) - 2
    except IOError as (errno, strerror):
        dht_output['temp']['err'] = strerror
        dht_output['humidity']['err'] = strerror

    #
    # LIGHT VALUES
    #
    time.sleep(0.5)
    grovepi.pinMode(light_sensor,'INPUT')
    try:
        sensor_value = int(grovepi.analogRead(light_sensor))

        if sensor_value <= 0:
            light_output['value'] = 0
        else:
            # Calculate resistance of sensor in K
            resistance = (float)(1023 - sensor_value) * 10 / sensor_value
            light_output['value'] = resistance
    except IOError as (errno, strerror):
        light_output['err'] = strerror

    output.append(air_output)
    output.append(dht_output)
    output.append(light_output)

    unlock()

    return json.dumps(output)


#4

Hey,
I can’t find anything wrong with the script. If you get the problem after recurring after almost a fixed period, do try running the code just alone, without the file read/writes and print the data to the screen.

Let us know if the error still comes.

-Karan