0

I am trying to get an LED to respond to a python program (using python 3.8), and it is not receiving anything. When I connect to the port, the led blinks to indicate it is connected, but then does nothing. Here is my code:

import serial

ser=serial.Serial('/dev/cu.usbmodem1411', 2000000, timeout=1)
ser.write(b'H')
time.sleep(200)

while True:
    #read echo back from arduino verify receipt of message
    #will show printing of x from arduino program
    data = ser.readline()[:-2] 
    if data:
         print (data.decode())

The while loop doesn't print out anything, and I also tried using the Arduino interface and it send signals fine, so my wiring is correct, but there is something missing with the python code. Has anyone run into this before?

1 Answer 1

1

The problem seems to be due to the wrong band speed you are using for the serial port. ser=serial.Serial('/dev/cu.usbmodem1411', 2000000, timeout=1) The value 2000000 here can never be true. There is no such value. The default is 9600, but I'll share a photo showing you the band speed on the Arduino side, the band speeds here and there should be equal. BaudRate

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, the band speeds weren't equal, Arduino can go up to a 2000000 baud rate, but mine was set at 9600 in my Arduino code so I just switched it to 2000000. Thank you!!

Your Answer

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.