RaspiArduino
Below is the protocol for communications between a Raspberry Pi and an Arduino.
The Raspi is assumed to be the "master". The protocol will support multiple Arduinos that can be used for digital or analog I/O.
Arduino Chip Select:
A single pin (D12) will be used as the "chip select" for the Arduino.
The default protocol will be for this pin to be pulled high. A 74138 decoder can be used to perform a 1 of 8 select for Arduino devices, keyed from GPIO pins on the Raspi. Note that select 7 (and also probably select 0) should be avoided to prevent accidental selection of the device.
The Arduino code should only listen or respond to the serial port when the select pin is active (low).
Communication Text Strings
Communication between the master and slave(s) will be over the serial port, at 9600 baud. ED: BT communication may use 38400 baud. All communications will be in ascii text strings.
The master will send a command requesting information from the slave device. The Request will be of the format:
:AREQ:Yxx;
The request is started with a colon character at the beginning of the line, the text "AREQ", followed by a second colon, then the number of the device to request from, a dash, then a letter to designate the type of port, a port number, and a final semicolon to terminate the line.
The type of port may be:
A - analog port
D - digital port
To read analog port 3, the command would be:
:AREQA:03;
The response will be:
:AVA03:1234;
Where "1234" is the returned value of the analog port.
To read digital pin 5, the command would be:
:AREQD:05;
The response would be:
:AVD05:1; if the pin is set, and :AVD05:0; if the pin is cleared.
To SET a digital pin, the command would be:
:ASETD03:1;
The device should answer with:
:VSD03:1;
The command to clear digital pin 3 would be:
:ASETD03:0;
The device should answer with:
:VSD03:0;
The DEFAULT device will be an Arduino Nano.
The pin designations will be as follows:
A0-A7: Reserved for Analog Inputs
Note: A6 and A7 can ONLY be used for analog.
D0-D1: Reserved for USB Serial Port
D10-RX from Raspi
D11-TX to Raspi
D12 - Device Select
D3 - DIO
D4 - DIO
D5 - DIO
D6 - DIO
D7 - DIO
D8 - DIO
D9 - DIO
D13 - Status LED