I am trying to send commands via serial from Python to Arduino with the code below.
If I save this code in a dedicated python file "Stepper.py" (Python2.7 on Mac OSX) , the code runs successfully but nothing happens (the code does not trigger a motor connected to Arduino).
If I start terminal and run the same code from the interactive shell it works as expected.
How can I run it via a dedicated file ?
import serial import timeser = serial.Serial(port="/dev/cu.usbmodem144231", baudrate=9600, timeout = 0)ser.write("200+")time.sleep(1)print ser.read()- 2You need to wait after opening the serial port for the board to finish resetting and the bootloader to run and exit before you can send any commands.Majenko– Majenko2019-02-18 14:08:40 +00:00CommentedFeb 18, 2019 at 14:08
- You are the man !!! Awesome works. Thank you so muchdigit– digit2019-02-18 14:12:37 +00:00CommentedFeb 18, 2019 at 14:12
1 Answer1
Majenkos comment (above) solved the problem:
"You need to wait after opening the serial port for the board to finish resetting and the bootloader to run and exit before you can send any commands."
import serial import timeser = serial.Serial(port="/dev/cu.usbmodem144231", baudrate=9600, timeout = 0)time.sleep(1)ser.write("200+")print ser.read()Explore related questions
See similar questions with these tags.