GrovePi Protocol and Adding Custom Sensors

GrovePi Protocol and Adding Custom Sensors

tl;dr- For each operation that you want to do on the GrovePi, the Raspberry Pi sends a command via I2C to the GrovePi and waits for a response for the command from the GrovePi. When it receives the response, it interprets the data and returns the desired output.

Explanation in depth

We will look into how the working of the GrovePi with an example of the Ultrasonic Ranger. The Ultrasonic ranger connects to a digital port and gives out the range in cm.

working_python1

If you look at the above code, the function ultrasonicRead(pin), is repeatedly called to print the distance measured by the ranger.

The ultrasonicRead() is defined in GrovePi.py and is called every time. The Raspberry Pi sends the command to the GrovePi, waits for some time and requests the data back.

In the main python library, the RaspberryPi writes a block of data to the GrovePi whose address is 0x04 and the block which is sent has the following format(5 bytes).

dataformat

For a new sensor, you can create a new unique id and send the required data to the Grove Pi.

working_python1

In the main loop of the GrovePi, there is a case for each of the unique id. When a unique id is received the relevant code is executed and the data is stores in the b[] buffer(b[0] is dummy and should not be used). The Raspberry Pi then asks for the data to be returned back and the Grove Pi sends the bytes depending on the last command executed.

The processing and interpretation of the data is performed by the Python code on the Raspberry Pi and the output is returned back to the calling function.

Because of the large number of Grove Modules available we need your help in making sure that GrovePi works with them all. If you are having any problems integrating the sensors, post it in the forums.

Have a question or a problem?  Post it on the forums and we’ll help you out.