I have an Arduino Uno (R3) monitoring a magnetometer connected via USB to a PI (B) running latest Raspian. My Pi Python program scans the USB every second reading an integer value via
ser = serial.Serial('/dev/ttyACM0', 57600)
.
This works fine when run from an active terminal. However I want to run the Python program starting at boot. Now the Python program fails to read the USB state.
I have tried starting the program via both rc.local
and crontab
. In either case the Python script is happy, reading/writing its data files, but fails when it tries to access USB. I have inserted a wait of up to 2 min assuming that USB may take time to initialize.
I wonder whether the USB is disabled until active login? Am I simply being dim here? :-)
1 Answer 1
Sorted it. The problem was that I was not flushing the buffer first
ser = serial.Serial('/dev/ttyACM0', 57600)
ser.flushInput()