0

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? :-)

goldilocks
60.4k17 gold badges117 silver badges236 bronze badges
asked Jan 12, 2016 at 19:45

1 Answer 1

1

Sorted it. The problem was that I was not flushing the buffer first

ser = serial.Serial('/dev/ttyACM0', 57600)
ser.flushInput()
goldilocks
60.4k17 gold badges117 silver badges236 bronze badges
answered Jan 12, 2016 at 21:47
1
  • Perhaps also consider setting timeout when you open the device Commented May 31, 2017 at 15:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.