GroveIPiSerial read write?



How can I read and write strings with GroveIPiSerial ports?

I tried to ad a new function definition in which reads with read_i2c_block function.

But i don’t know how to adress the RX pin p0, in your scripts pin 0 is used for the analog port 0.


To use the GrovePi serial port’s, attach a sensor of your choice to the RPISER port. Now you can directly read and write data to your sensor.

You can use the Pyserial package to interact with the sensor. Here is an example .

You can modify the example to read and write data to your sensor.



Thank’s for the answer but the PiSerial port is already in use by a sensor, i would need to write and read strings on the Grove serial port.


There is no direct support for sensors on the GrovePi serial port. You’ll have to customize the firmware and the software to make use of the serial port.

Can you give some more information about what sensor are you already using with the RPISER port and what other sensor are you trying to use.



Thank you for your response but i will use one of the usb ports of the Raspberry to get a second serial port because i have not enough experience in C++ and time to customize the firmware.

But i have a different problem i often get IOError when i try to grovepi.digitalWrite or grovepi.digitalRead, is there a way to prevent that from happening.


I tried to swich digital pin 4 with your script.
Sometimes it prints that the pin is switched on or off without changing the the state of the pin, looks like your exception handling doesn’t work correct.
I have to check the pin after i switched it to be sure it really switched.

#!/usr/bin/env python

import time
import grovepi

ON = 'on’
OFF = ‘off’

relay = 4

def readPin(args):
while True:
pinStatus = grovepi.digitalRead(args)
if pinStatus == 0 or pinStatus == 1:
#print pinStatus
return pinStatus
#print 'IOError’

def writePin(pin, args):
if args == ‘off’:
while True:
y = readPin(pin)
#print y
if y == 1:
print "IOError"
elif y == 0:
print ‘pin:’, pin, args
elif args == ‘on’:
while True:
y = readPin(pin)
#print y
if y == 0:
print "IOError"
elif y == 1:
print ‘pin:’, pin, args

a = raw_input(‘Type on or off to switch relay:n’)
if a == ON:
writePin(relay, ON)
elif a == OFF:
writePin(relay, OFF)


The IOError is thrown when there is a problem communicating with the GrovePi or if the last command was not sent properly. You can easily use the exception handling to take care of that like in this example .