Page 11 of 15
Page 243
from machine import UART,Pin
uart = UART(1,baudrate=9600,bits=8,parity=None,rx=12,tx=13)
SendData = bytearray("Hello World \n","utf-8")
uart.write(SendData)
RecData = uart.read()
print(RecData)
Page 246
from machine import UART,Pin, Timer
from utime import sleep_ms,sleep, time_ns
uart = UART(1,baudrate=9600,bits=8,parity=None,rx=12,tx=13,txbuf=256,rxbuf=16*1024)
test="A"*252
s = time_ns()
uart.write(test)
print((time_ns()-s)/1000000)
Page 246
from machine import UART,Pin, Timer
from utime import sleep_ms,sleep, time_ns
uart = UART(1,baudrate=9600,bits=8,parity=None, rx=12,tx=13, txbuf=16*1024,rxbuf=512)
test="A"*1000
s = time_ns()
uart.write(test)
print((time_ns()-s)/1000000)
sleep_ms(4000)
RecData = uart.read()
print(RecData)
Page 247
from machine import UART,Pin, Timer
from utime import sleep_ms,sleep, time_ns
uart = UART(1,baudrate=9600,bits=8,parity=None,rx=13,tx=12, txbuf=4*1024,rxbuf=512)
test = ""
for i in range(280):
test=test + str(i)+","
print(test)
print(len(test))
s = time_ns()
uart.write(test)
print((time_ns()-s)/1000000)
sleep_ms(4000)
RecData = uart.read()
print(RecData)
print(len(RecData))
Page 251
from machine import UART,Pin
from utime import sleep_ms, time_ns
uart = UART(1,baudrate=9600,bits=8,parity=None, rx=12,tx=13,rts=4,cts=5, timeout=0,timeout_char=0,txbuf=2000,rxbuf=256,flow=UART.RTS|UART.CTS)
test = "A"*1000
s = time_ns()
uart.write(test)
print((time_ns()-s)/1000000)
RecData = bytes()
while len(RecData)<1000:
sleep_ms(500)
if uart.any():
RecData = RecData + uart.read()
print(RecData)
print(len(RecData))
return -1
return 0
def writeByte(uart,byte):
buf=[]
for i in range(8):
if byte & 1 == 1:
buf.append(0xFF)
else:
buf.append(0x00)
byte = byte >> 1
uart.write(bytes(buf))
sleep_ms(10)
byte=uart.read(8)
def readByte(uart):
byte = bytes([0xFF]*8)
uart.write(byte)
sleep_ms(10)
byte = uart.read(8)
result=0
for b in byte:
result=result>>1
if b==0xFF:
result=result|0x80
return result
Page 256
uart = UART(1,baudrate=115200,bits=8,parity=None,rx=12,tx=13 )
print(presence(uart))
presence(uart)
writeByte(uart, 0xCC)
writeByte(uart, 0x44)
sleep_ms(1000)
presence(uart)
writeByte(uart, 0xCC)
writeByte(uart, 0xBE)
data=[]
for i in range(9):
data.append(readByte(uart))
t1 = data[0]
t2 = data[1]
temp1 = (t2 << 8 | t1)
if t2 & 0x80:
temp1=temp1 | 0xFFFF0000
temp=temp1/16
print(temp)