I am trying to send messages between python and the arduino via serial port. I am successful going in the Arduino->python direction with this code:
The python:
import termios, fcntl, sys, os, serial, time, smtplib
ser = serial.Serial('/dev/tty.usbserial-AD02AY8A', 9600, writeTimeout = 0)
while 1:
message = ser.readline()
print(message)
The Arduino:
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.write('1');
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
Serial.println("BOBBY");
delay(1); // delay in between reads for stability
}
In this case, I can view the serial port from arduino and the "screen command" on terminal, as well as through the python reprinting "BOBBY".
When I try to send the message from python, it never shows up on the terminal screen or in the Arduino serial port.
Here's the python code that doesn't work. The arduino code shouldn't matter for this one, as I am just monitoring the serial port.
import termios, fcntl, sys, os, serial, time, smtplib
ser = serial.Serial('/dev/tty.usbserial-AD02AY8A', 9600, writeTimeout = 0)
time.sleep(2)
while 1:
try:
ser.write('1')
except: # catch *all* exceptions
print(e)