Sensor values overwrite one another when multiple sensors connected

I am having a weird issue, may be due to my python code not running in sequence. When I have both a sound sensor and a light sensor connected (A0 and A1), then both report the light sensor value. This happens with the ultrasonic ranger (proximity sensor) as well. The DHT values are fine. Any ideas? Here is the code:

from time import sleep # we need to use the sleep function to delay readings
import datetime # that's for printing the current date
import time
import grovepi
import math
import json
from adxl345 import ADXL345

adxl345 = ADXL345()
dht_sensor = 4
ultrasonic_ranger = 6
light_sensor = 0
sound_sensor = 1
button = 3

grovepi.pinMode(sound_sensor,"INPUT")
grovepi.pinMode(button,"INPUT")
grovepi.pinMode(light_sensor,"INPUT")

data = {
    'sound': 0,
    'light': 0,
    '3axis': 0,
    'button': 0,
    'temp': 0,
    'humidity': 0,
    'prox': 0
}

while True:
    try:
        data['sound'] = grovepi.analogRead(sound_sensor)
        data['light'] = grovepi.analogRead(light_sensor)
        [data['temp'],data['humidity']] = grovepi.dht(dht_sensor,1)
        data['3axis'] = adxl345.getAxes(True)
        data['button'] = grovepi.digitalRead(button)
        data['prox'] = grovepi.ultrasonicRead(ultrasonic_ranger)
        print(json.dumps(data))
        print("sleeping")
        time.sleep(0.2)
    except TypeError:
        print ("Error")
    except IOError:
        print ("Error")

Output:

{“sound”: 356, “temp”: 23.2, “prox”: 356, “light”: 356, “button”: 0, “humidity”: 73.4, “3axis”: {“y”: -0.004, “x”: -0.844, “z”: 0.496}}

Hi @jeremygw,

We are aware of this issue and we’re trying to solve it. We don’t have an ETA for the moment, but we trying to fix it as fast as we can.

A similar issue has been noticed on this forum thread too:

When we’ve got something, we’ll reply you here.

Thank you!

1 Like

Hi,
I just had a similar problem using a dht, 2 relais and a button.
The problems seems to be, that GrovePi is not able to switch on a relais on D5,
when there was allready a comand to switch a relais on D6.
It seems to me, we will have to follow the D-number one after the other,
Try to read data from light-sensor on D0 first, than sound-sensor on D1 and so on.
Hope it helps