I'm using an arduino uno with the basic "DigitalReadSerial" setup as outlined here: http://arduino.cc/en/Tutorial/DigitalReadSerial
If i use the serial monitor included with the arduino IDE, it immediately displays any changes from pressing the button.
This is what i want in pyserial, either a 0 or a 1 depending on whether the button is pressed. (to eventually trigger a timer)
just to test it, i threw this together, not the prettiest, but it seems to read out the pushbutton state, but there is a 20second delay.
import serial
ser = serial.Serial()
ser.setPort("COM2")
ser.baudrate = 9600
ser.open()
while 1==1:
ser.readline()
Does anyone have any ideas?
It seems to be a caching/sync problem, similar to those that affects the file sync in common filesystems. I have suffered that problem with my arduino/pyserial... until now?
From http://pyserial.sourceforge.net/pyserial_api.html, if I put the 3 flush commands: ser.flush(), ser.flushInput() and ser.flushOutput() in my program, it seems to work as expected.
Are you using Serial.print or Serial.println in your Arduino code? If the former, its not going to issue a carriage return and the ser.readline() in your code will be waiting for one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With