Home > Net >  Serial.write() not received by Arduino
Serial.write() not received by Arduino

Time:06-29

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?

CodePudding user response:

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

  • Related