I followed the instructions on this website successfully:
http://www.doctormonk.com/2012/04/raspberry-pi-and-arduino.html
and I was able to get communication between the pi and my arudino mega exactly as the website specifies.
However, instead of sending an integer representing the number of times the LED blinks, I want to sent ASCII text like:
"MOVE 5 METERS FORWARD", "TURN LEFT", "MOVE 10 METERS BACKWARD" to the arduino from the pi.
I wrote the following code:
char inData[64];
char inChar=-1;
void setup(){
Serial.begin(9600);
Serial.begin("Waiting for Raspberry Pi to send a signal...\n");
}
void loop(){
byte numBytesAvailable= Serial.available();
// if there is something to read
if (numBytesAvailable > 0){
// store everything into "inData"
int i;
for (i=0;i<numBytesAvailable;i++){
inChar= Serial.read();
inData[i] = inChar;
}
inData[i] = '\0';
Serial.print("Arduino Received: ");
Serial.println(inData);
}
}
I flashed above code succesfully to my Arduino Mega 2560.
I switched to my python terminal on the Raspberry Pi and in the console I typed:
import serial
ser = serial.Serial('/dev/ttyACM1',9600)
ser.write("MOVE")
What gets displayed on my Arduino's Serial Monitor is as follows:
Arduino Received: M
Arduino Received: O
Arduino Received: V
Arduino Received: E
But what I want is:
Arduino Received: MOVE
How do I change the code above to get all characters into the inData buffer?