Running Multiple sensors in different programs simultaneously

I’ve been having some issues with the GrovePi in running multiple sensors in different programs simultaneously. By this I mean, I will have two or more terminals open, all running programs that use a single GrovePi. I have the following sensors temperature&humidity, light, sound, ultrasonic ranger, and a button.

I want to be able to run all of these sensors each in a different program, that way I can send the information over MQTT in different topics.

But when I try this I receive numbers that are not even close. I’ll have my temperature sensor running in one program and the button in another. My temperature might say 3000 degrees while the button program is running, but it’ll say 72F when it’s the only program.

So I need to know if this is possible to run the GrovePi like this, and if so, how?

I would also like to know the speed at which these sensors can update information. Thanks.

Hey,
We haven’t tried running multiple python programs interacting with the GrovePi at once and are pretty sure that there might be some problems reading and writing to it when you have multiple programs communicating simultaneously. The reason for this is that the GrovePi gets a command from the Raspberry Pi, does the read/write from the sensors and loads the buffer with the information. The Raspberry Pi then asks for some data back which is promptly gives back. The total delay in this process is between 3-10ms. Even though, multiple programs can communicate with the GrovePi at once, they interrupt this process which might be corrupt the data. For example, when the digitalRead is sent from one program, the GrovePi will load 1 byte of data to the buffer and in the next few milliseconds, another program asks the DHT sensor for some data, it might read from the buffer, the 1 byte from the digitalRead and 1 byte of junk data causing the read on the Pi being meaningless.

Even though it is possible to read/write simultaneously with some major rework to the GrovePi software and firmware, that is not a big priority for us right now with the GroveP. The best way to do this might be to have 1 program communicate with the GrovePi and use sockets or some other way to communicate with the that program from other programs.

The fastest you would be able to read/write from the GrovePi would be 10ms, but this might cause some IO errors. It would be better if you communicate with delays of 100ms or more with it.

-Karan

See also here: http://www.dexterindustries.com/topic/grovepi-sensors-dont-work-or-analog-sensors-dont-work-not-solved/

Specifically regarding running multiple instances accessing the GrovePi: it’s probably not going to be a good idea. The GrovePi operates on the I2C line and can only be polled by one program at a time. I2C transactions can take milliseconds, and if you call one in the middle of another, you can corrupt the communications.

If you have multiple clients logged in (ie you’r logged into the pi multiple times through terminal) the best way to do this is to write one program that continuously polls the Pi, and can communicate over ports to respond to data requests. That way the data is just constantly polled by the Pi, and readily available. You could do something most easily by possibly writing to a file that can be accessed by multiple terminal programs.

Good luck, sounds like a really cool program. - John