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?
EDIT:
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.