nodemecu/raspberry/arduinos.py

35 lines
587 B
Python
Raw Permalink Normal View History

2022-02-23 14:42:32 +00:00
#!/usr/bin/env python
import time
import serial
import sys
ser = serial.Serial(
port='/dev/serial0', #Replace ttyS0 with ttyAM0 for Pi1,Pi2,Pi0
2022-04-05 20:56:40 +00:00
baudrate = 9600,
2022-02-23 14:42:32 +00:00
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
ser.flush()
cw = int(sys.argv[1], 0)
com = [cw]
ser.write(serial.to_bytes(com))
ser.flush()
while True:
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8', errors='replace').rstrip()
2022-04-05 20:56:40 +00:00
#time.sleep(0.1)
2022-02-23 14:42:32 +00:00
print(line)
ser.flush()
break
quit()