DUO and Python serial

I am trying Python serial:

import serial
ser = serial.Serial(‘/dev/ttyS1’) # open serial port
print(ser.name) # check which port was really used
ser.write(b’hello’) # write a string
ser.close() # close port

I get an error when i try to open the serial line

Best regards

Georges

Try /dev/ttyS0, assuming your pin is connected to GPIOA16, GPIOA17 and ground, if not, try switching A17 and A16. I just tried echo ‘hello’ > /dev/ttyS0 and it works. I have adafruit ttl usb 3.3v connected to 16, 17 and ground. Also with UART tutorial, boot without ttl usb then plugin ttl usb otherwise it doesnt work, see note in the link at the end of the article uart

Sonny

Thanks for your help,

I try ttyS0, i get the same problem…
The problem is not about hardware it is about Python library I guess.

Best regards
Georges

I just tried you code and it works for me, my Linux terminal is set at 9600 baud, you can find your milkv duo setting in python by executing ser return and it will return the baud rate, see picture link below

python serial pic

1 Like

Sonny,

Thanks a lot your code is working.

Best regards
Georges