I'm using a Arduino Uno Rev 3 connected over usb to a Raspberry Pi Modell B+ running Rasbian.
Here ist the arduino code:
int input = 0;
String command = ""; // beinhaltet den aktuellen befehl
int Action = 1;
void setup() {
Serial.begin (9600);
}
void loop() {
if (Serial.available() > 0)
{
input = Serial.read();
char currentChar = input;
if(currentChar == '!') // frage nach trennzeichen
{
Serial.println(command);
//Serial.write(Action);
Action = command.toInt();
command = ""; // befehl wieder leeren
}else
{
command = command + currentChar ; // falls noch kein trennzeichen vorhanden, erweitere kommando
}
}
}
Here is the Raspberry Pi code (in python)
import serial
from time import sleep as sleep
ser = serial.Serial('/dev/ttyACM0',9600)
s = [0]
while True:
ser.write(b'2!')
a = ser.read(1)
print a
sleep(2)
It always works if once after the code was uploaded to the arduino, but if I stop the script on the pi and restart it it stops working. What is the problem here?