One good solution that comes bundled with the Arduino is
Hans-Christoph Steiner’s Firmata (bit.ly/1CXFnqF), an all-
purpose serial protocol that is simple and human-readable.It may
not be perfect for all applications, but it is a good place to start.
Here’s a quick example:
1. SelectFile→Examples→Firmata→StandardFirmata in the
Arduino IDE; this will open the sample Firmata code that will
allow you to send and receive messages to the Arduino and get
information about all of the pins.
2. Upload that code to the Arduino the same way you did in pre-
vious examples.
3. You’ll need a bit of Python code on the Pi to send commands
to the Arduino to query or change its state. The easiest way is to
use the pyFirmata module. ...