I cannot send serial data correctly from a Python script to Arduino Uno. I use 9600 baud and Arduino correctly resets, but it does not read the char that I am sending with a Python script. I am calling time.sleep()to ensure that the reset on the Arduino does not interfere, and I am using Windows 7. I must clarify by saying that my desktop launches a python script and connects via USB to the Serial of my Arduino Uno. Then I have the RX and TX pins (pins 0 and 1) of my Uno connected to my Mega Serial1 (pins 18 and 19). Then I use the Serial Monitor in the Arduino IDE on my laptop (which uses Mega regular Serial) to look at what Uno sees. Here is the code for Mega:
void setup() {
Serial1.begin(9600);
Serial.begin(9600);
Serial.println("Master Ready");
}
void loop() {
if(Serial1.available() > 0) {
char inByte = Serial1.read();
Serial.write(inByte);
Serial.write("\n");
}
}
Uno:
void setup() {
Serial.begin(9600);
Serial.println("Slave Ready");
}
void loop() {
if(Serial.available() > 0) {
char inByte = Serial.read();
Serial.write(inByte);
}
}
, , script:
import sys
import serial
import time
ser = serial.Serial("COM23",9600)
n = int(sys.argv[1])
print n
time.sleep(10)
print ser
print n == 41
if (n == 70):
ser.write(chr(97))
print 'a'
elif n == 41:
ser.write('ggggggg')
print 'b'
elif n == 42:
ser.write('hello world')
print 'c'
elif n == 25:
ser.write(chr(100))
elif n == 26:
ser.write(chr(101))
elif n == 22:
ser.write(chr(102))
elif n == 10:
ser.write(chr(103))
elif n == 4:
ser.write(chr(104))
elif n == 14:
ser.write(chr(105))
elif n == 7:
ser.write(chr(106))
elif n == 11:
ser.write(chr(105))
elif n == 5:
ser.write(chr(106))
elif n == 17:
ser.write(chr(107))
, , Doom3 Arduino , Arduino . ++, ++, .