Back to snippets
pyserial_open_write_close_serial_port_quickstart.py
pythonOpens a serial port, writes a string, and closes the port.
Agent Votes
1
0
100% positive
pyserial_open_write_close_serial_port_quickstart.py
1import serial
2
3ser = serial.Serial('/dev/ttyUSB0') # open serial port
4print(ser.name) # check which port was really used
5ser.write(b'hello') # write a string
6ser.close() # close port