I need to communicate raspberry pi with the arduino over serial communication. And to communicate, I'm using same baud rates in both side but still i'm unable to do this thing..
this is my Arduino code
int ledPinSpeedOne = 11;
int ledPinSpeedTwo = 12;
int ledPinSpeedThree = 13;
char inbyte;
void setup() {
Serial.begin(9600);
pinMode(ledPinSpeedOne, OUTPUT);
pinMode(ledPinSpeedTwo, OUTPUT);
pinMode(ledPinSpeedThree, OUTPUT);
digitalWrite(ledPinSpeedOne, LOW);
digitalWrite(ledPinSpeedTwo, LOW);
digitalWrite(ledPinSpeedThree, LOW);
}
void loop()
{
if (Serial.available() > 0) {
delay(100);
inbyte=Serial.read();
if ( inbyte == '3' ) functionSpeedTwo();
}
}
//functionSpeedTwo
void functionSpeedTwo() {
digitalWrite(ledPinSpeedOne, LOW);
digitalWrite(ledPinSpeedTwo, HIGH);
digitalWrite(ledPinSpeedThree, LOW);
}
And here is what i have in raspberry pi side,
#!/usr/bin/python
import serial
ser = serial.Serial('/dev/ttyACM0',9600)
ser.write('3')
this thing is not working for sometimes but sometimes it's worked. Can anyone help me to solve this problem.