Skip to content

Instantly share code, notes, and snippets.

@rdandy
Created February 16, 2022 05:10
Show Gist options
  • Save rdandy/df1622af2087d7deec5b87b256793c81 to your computer and use it in GitHub Desktop.
Save rdandy/df1622af2087d7deec5b87b256793c81 to your computer and use it in GitHub Desktop.
# serial_write.py
import serial, time
SERIALPORT = "/dev/ttyS0"
ser = serial.Serial(SERIALPORT, baudrate=115200, bytesize=8, parity="N", stopbits=1, rtscts=False, xonxoff=False)
def write_data():
while True:
txt = input("input some thing ...\r\n")
if txt.startswith("exit"):
break
print(txt)
ser.write(bytearray(txt.strip().encode()) + b'\r\n')
print("bye!")
if __name__ == '__main__':
print(ser)
print("write data")
write_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment