I am trying to get Arduino Uno with Raspberry Pi to communicate with each other. I want the python script to write a message and for my Arduino to read it. This was working before, but I came back a week later and it stopped. Essentially, I want the Raspberry Pi to write '3' and for my Arduino to recognize this 3 and light up some LEDs. Where do you think I am going wrong? The Arduino works when testing it through the IDE and Serial Monitor. There are no errors when running the python script, the LEDS just don't light up, so I assume there is some miscommunication.

Python Code

import serial
ser = serial.Serial('/dev/ttyACM0', 9600)

Arduino Code

String serialRead;
int val;
void setup() {
  strip.show(); // Initialize all pixels to 'off'

void loop() {
  serialRead = Serial.read();
  if (Serial.available() > 0) {
    val = Serial.read();

    if (val > '0' && val <= '9') {
      val = val - '0';

      if (val == 3)
        colorWipe(strip.Color(127, 127, 127), 50);
        colorWipe(strip.Color(0, 0, 0), 50);        
  • What you can do is remove the rPi from the equation. Run the sketch and send your own serial commands direct via your computer and see if the LEDs change as expected. That will narrow down which end is having the problem: works, it's the rPi send/arduino rcv. doesn't work, it simply your code or the LED setup. Report back and tell us how you go
    – Madivad
    Commented Dec 14, 2015 at 15:25

1 Answer 1


Just at a glance:

Your loop consumes the byte and stores it in serialRead, so there is probably no available data at the outer if, so it is never entered.

Try deleting this line:

serialRead = Serial.read();
  • Unfortunately, that did not work. I am able to get it to work through the Arduino IDE using Serial Monitor both ways, but still not with the RPi Commented Dec 12, 2015 at 15:23
  • I suspect a timing issue; perhaps the rPi sends the '3' before the Arduino is listening? Have you tried to put a loop w/delay in the Python code?
    – NVRAM
    Commented Dec 12, 2015 at 20:49
  • The first Serial.read(); is a problem for sure – unless the Raspberry Pi sends more than one '3' this line could consume it, and then nothing will happen. I'm suspicious that there are garbage characters that are consumed by that first Serial.read(); when you're testing with Serial Monitor. Why don't you print what your get from it. Also is the pi sending a newline? Could the problem be that there is Serial.read() expects one?
    – dlu
    Commented Dec 13, 2015 at 6:31
  • I took out the first Serial.read(); and the problem persisted. I think NVRAM may be right with the timing issue. I was able to get it to work with constantly writing a 3. Unfortunately, I had to give the setup back to my friend so I won't be able to test this issue further. Thanks for the help. Commented Dec 13, 2015 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.