I am working on an autonomous robot, which uses a python script running on my RPi 3 to detect traffic lights. I want that as soon as the RPi detects that the traffic light has gone off, it would signal the Arduino to do its thing (i.e run the sketch that I have made for the robot).

Now the thing is, all I can do is to run the Arduino IDE on my RPi, I can upload code to it, I can see the output on the Serial monitor, but how do I get my python script to interface with the Arduino. Let's say upon detecting the traffic light switching off, the python script changes a variable arduinogo from 0 to 1, and I set up my Arduino accordingly to receieve the variable and if its value is 1, do its job. So how can I achieve this communication?

I got it to work, I followed a tutorial here - http://www.instructables.com/id/Interface-Python-and-Arduino-with-pySerial/ . This uses pySerial to communicate with the Arduino's serial port. I was able to make the Arduino's onboard LED light up by passing a variable having an ASCII character from my python script written on my PC (Win 8.1) on the Netbeans 8.1 IDE. This works flawlessly on my PC, I have downloaded the tar package to install on my Raspberry Pi, lets see if this works this well on the RPi as well.

3 Answers 3


If your sketch on arduino is taking input from serial interface, you should be looking for a serial I/O library in python and used it to send the commands over the serial interface.

  • I don't understand. Does the serial I/O library lets me control the Arduino pins the way they are controlled by the Arduino? (making them HIGH or LOW)?
    – YaddyVirus
    Commented Apr 19, 2016 at 5:23
  • please read the edit, I presume this was the serial I/O library you were talking about...
    – YaddyVirus
    Commented Apr 19, 2016 at 6:04

If you want the Pi to cause the Arduino to do "complicated" tasks, then go with Tahir's answer. If it's simpler than that, why not just attach a GPIO wire from the pi to the arduino? Failing that, this is the kind of task that I2C was absolutely made for.

  • I just want to "trigger" the Arduino to run the sketch I wrote, as soon as the RPi detects the traffic is off. Well according to me this just requires passing a variable between the Arduino and the RPi. So is this simple?
    – YaddyVirus
    Commented Apr 19, 2016 at 5:15

There are many different ways of communicating.

You can use serial over USB cable or directly.

You can use direct connection of GPIO pins and just use digitalRead digitalWrite or a protocol like SPI ORI²C.

I have used all of these depending on the project.

Whatever you do make sure that you ensure the Pi 3.3V logic and Uno 5V do not mix. There are many different ways of doing this.

  • I'm using the Arduino from the RPi just as you would use it from your computer, by plugging in the USB cable. I don't have much knowledge regarding the GPIO pins on the RPi at the moment, neither about the protocols you mentioned. I just want the connection to be as fast as possible, so that there is least time between the RPi detecting the traffic light and the Arduino running the motors. What do you suggest?
    – YaddyVirus
    Commented Apr 19, 2016 at 5:12
  • @YaddyVirus: Have you considered removing the Arduino from your design and directly controlling the motors with RPi? Commented Apr 20, 2016 at 14:17
  • No not yet, I thought that the RPi has to do realtime image processing so I better keep the motor control to Arduino. Please read my edit as well, what are your thoughts on that?
    – YaddyVirus
    Commented Apr 20, 2016 at 16:27

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.