Create serial-read-write.py
Initial code for Circuit Playground Express Serial Communications guide
This commit is contained in:
parent
bb21868b95
commit
3b900f20c5
1 changed files with 18 additions and 0 deletions
18
CPX_Serial/serial-read-write.py
Normal file
18
CPX_Serial/serial-read-write.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import time
|
||||
import board
|
||||
import busio
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
uart = busio.UART(board.TX, board.RX, baudrate=115200)
|
||||
|
||||
while True:
|
||||
|
||||
data = uart.read(1) # read a byte
|
||||
|
||||
if data is not None: # Data was received
|
||||
|
||||
output = "%0.1f\t%d\t%0.1f\r\n" % (time.monotonic(),
|
||||
cpx.light, cpx.temperature)
|
||||
uart.write(output) # Print to serial
|
||||
|
||||
time.sleep(1.0)
|
||||
Loading…
Reference in a new issue