how to receive integer from uart 1
Posted: Fri Aug 24, 2018 3:33 pm
Hello
i have solved problem with my esp32 that i want to share it with others .
Since the Uart is receive only char with 1 bytes so if you want to receive an integer with 2 bytes you must receive two char and
merge them (or combine) with each other
i simple do that
import machine
buf=''
lower='' ##global variable to the lower byte
uper='' ##global variable to the upper byte
u2=machine.UART(2, baudrate=115200, rx=16, tx=17, timeout=10)
if(u2.any()>3):
buf= u2.read(2)
uper=buf[:1]
lower=buf[1:2]
uper=ord(upper)
lower=ord(lower)
t=int((uper<<8)+lower)
print(t)
pls:
if you have any notes ,feel free to write it down
i have solved problem with my esp32 that i want to share it with others .
Since the Uart is receive only char with 1 bytes so if you want to receive an integer with 2 bytes you must receive two char and
merge them (or combine) with each other
i simple do that
import machine
buf=''
lower='' ##global variable to the lower byte
uper='' ##global variable to the upper byte
u2=machine.UART(2, baudrate=115200, rx=16, tx=17, timeout=10)
if(u2.any()>3):
buf= u2.read(2)
uper=buf[:1]
lower=buf[1:2]
uper=ord(upper)
lower=ord(lower)
t=int((uper<<8)+lower)
print(t)
pls:
if you have any notes ,feel free to write it down