Hey All!
I'm having difficulty with a python/arduino script I've written on one Mac to work on a new Mac I'm migrating to. The first computer is running OS X Yosemite 10.10.1, Python 2.7.10, PySerial 2.7, and Arduino IDE 1.6.7. The second computer, the one that is having problems running the script is OS X El Capitan 10.11.3, Python 2.7.11, PySerial 2.7, and Arduino IDE 1.6.7. I'm using an Arduino Micro with the code being:
String readString;
char character;
void setup() {
Serial.begin(9600);
while (!Serial);
}
void loop() {
while (!Serial.available()){}
while(Serial.available() > 0)
{
character = Serial.read();
readString += character;
}
if (readString.length() >= 0) {
readString.trim();
readString = FunctionDecision(readString);
}
}
String FunctionDecision(String ss)
{
if (ss == "YY") {
Serial.println("Yes");
} else {
Serial.println("No");
}
return "";
}
And the Python code is:
from time import sleep
import serial
ser = serial.Serial('/dev/cu.usbmodem14211', baudrate = 9600) # Establishing connection
sleep(10) # Way too long, but making sure connection is up
for x in range(5):
ser.write("YY")
sleep(0.1)
x = ser.readline()
print x
ser.close()
On my first Mac, the python print results in:
Yes
Yes
Yes
Yes
Yes
And repeats like that all day, which is the expected output. On my second Mac, after uploading the code to my Arduino Micro, it runs perfectly the first time. But trying to run it a second time the code hangs on ser.readline(). This led me to believe that there is an EOL error. Changing the serial port configuration to have a timeout of 2 results in my code skipping the first two 'Yes' outputs, and receiving the last three.
So far I've tried upgrading my second Mac to PySerial 3.0.1 and Arduino IDE 1.6.8, but to no avail. I'm sure there's an error somewhere in my code but I can't seem to find it. I was hoping to use your guy's Arduino super powers to help out. Any advice would be greatly appreciated!
