The simplest way is to use basic serial I/O.
I use this kind of setup for my data-loggers that occasionally need the Arduino to take action based on the data or the clock.
EXAMPLE:
Assuming that you want to use a USB port (like on a RPi3), say you want to send a command that will cause the Arduino to emit two long beeps. (Or it could trip relays, whatever) the code would look something like this:
PYTHON SIDE:
#!/usr/bin/python
import serial
First open up the port:
(Often as shown, but for CHG340 Arduinos will be more like /dev/ttyACM0
)
ser = serial.Serial("/dev/ttyUSB0",9600)
To read from the port, use:
linein = ser.readline()
To write to the Arduino use:
ser.write("A")
ARDUINO SIDE, (remembering that it will arrive as type char
)
In setup()
char cTMP;
int beePin=12;
Serial.begin(9600);
while (Serial.available()>0) cTMP=Serial.read(); // flush the buffer
Then somewhere in loop()
if (Serial.available) > 0) {
if (serIn=='A') {
digitalWrite(beePin,HIGH); delay(2000); digitalWrite(beePin,LOW);
delay(2000);
digitalWrite(beePin,HIGH); delay(2000); digitalWrite(beePin,LOW);
}
}
I tend to stick to single-letter commands to the Arduinos
The beauty of this setup is that you can also run the Arduino IDE on the RPi3 for Arduino programming, and you can use VNC or xrdp
(with Windows Remote Desktop or remmina) to access it remotely.
I call it a Piduino.