Python Sensor read failed after some time, i2C gone

grovepi
multithreading

#1

We noticed, that in the case of concurrent access using multiple python scripts with python3 on a rapsberry3, the grovepi arduino seems to crash sometimes. We have a grovepi ultrasonic sensor and a ir movement sensor connected.

Error:
Traceback (most recent call last):
  File "test-grovepi.py", line 48, in <module>
    sensor_value = grovepi.analogRead(light_sensor)
  File "/home/pi/.local/lib/python3.5/site-packages/grovepi.py", line 227, in analogRead
    return number[1] * 256 + number[2]
TypeError: 'int' object is not subscriptable

After this, i2cdetect 1 shows nothing on the i2c bus

flashing the firmware again (1.2.7) helped most of the time, but only for a shored period of time. Than again: Error.

To reproduce, I started the python script 12 times.

After reading

I updated the firmware to 1.3.0beta. The error still occurred sometimes, but it is now very hard to reproduce. So not fixed, but much better.

Anything else I could do to help fixing this? Is there a way to debug the grovepi?

Thanks,
Arne


#2

Ah, I just noticed, that in case of Error with 1.3.0beta, reset using sudo avrdude -c gpio -p m328p works (not for the 1.2.7)


#3

Hi @arne.bernin,

You cannot run multiple scripts at the same time in neither version of the firmware. It’s all written in the documentation. Here’s the quote:

IMPORTANT
This library and the other ones too are not thread-safe. You cannot call the GrovePi from multiple threads or processes as that will put the GrovePi into a broken state.
In case you need to reset the GrovePi from your Raspberry Pi, check this section.

And here’s the link to the documentation:
https://robertlucian.github.io/GrovePi/fw/

Thank you!