help with UART and Raspberry Pico
Posted: Wed Aug 18, 2021 8:40 am
Hello
I am developing a small personal project, I use raspberry pico and micropython, previously I had requested your help to solve some problems, despite obtaining the desired behavior, after a time "x" of execution (it varies the time) the program fails, however , it does not send an error, and the behavior of other tasks is not affected, the only task that stops working as expected is the one in charge of transmitting the data, I am a little lost, I do not know where I should look ...
comportamiento deseado:

falla:

the function in charge of transmitting the data:
the function in charge of receiving the data is very simple:
I am developing a small personal project, I use raspberry pico and micropython, previously I had requested your help to solve some problems, despite obtaining the desired behavior, after a time "x" of execution (it varies the time) the program fails, however , it does not send an error, and the behavior of other tasks is not affected, the only task that stops working as expected is the one in charge of transmitting the data, I am a little lost, I do not know where I should look ...
comportamiento deseado:
falla:
the function in charge of transmitting the data:
Code: Select all
async def dataout():
uart = UART(0, baudrate=9600, tx=machine.Pin(16), rx=machine.Pin(17))
swriter = uasyncio.StreamWriter(uart, {})
while True:
d1 = await (h())
d2 = await (t())
d3 = await (humedadsustrato())
d4 = await (tempico())
d5 = await (tsustrato())
if d1 == None:
p1 = "xxxx"
else:
p1 = "{0:.3f}".format(d1)
if d2 == None:
p2 = "xxxx"
else:
p2 = "{0:.3f}".format( d2)
if d3 == None:
p3 = "xxxx"
else:
p3 = "{0:.3f}".format( d3)
if estatus == True:
p4 = "on"
else:
p4 = "of"
if ledazul.pin.value() == 0:
p5 = "aon"
else:
p5 = "aof"
if ledblanco.pin.value() == 0:
p6 = "bon"
else:
p6 = "bof"
if ledrojo.pin.value() == 0:
p7 = "ron"
else:
p7 = "rof"
if bomba1.pin.value() == 0:
p8 = "xon"
else:
p8 = "xof"
p9 = "{0:.3f}".format( d4)
if d5 == None:
p10 = "xxxx"
else:
p10 = "{0:.3f}".format(d5)
data_send =str("a"+p1+"b"+p2+"c"+p3+"d"+p4+"e"+p5+"g"+p6+"h"+p7+"i"+p8+"j"+p9+"k"+p10+"l")
swriter.write(data_send)
await swriter.drain()
await uasyncio.sleep(2)
Code: Select all
ser = serial.Serial('/dev/rfcomm99', 9600,timeout=3, parity=serial.PARITY_EVEN, rtscts=1)
while True:
if recibir == True:
linem = ser.readline()
line = linem.decode()
indice_a = line.find("a")
indice_b = line.find("b")
indice_c = line.find("c")
indice_d = line.find("d")
indice_e = line.find("e")
indice_g = line.find("g")
indice_h = line.find("h")
indice_i = line.find("i")
indice_j = line.find("j")
indice_k = line.find("k")
indice_l = line.find("l")
humedad_ambiente = line[indice_a+1:indice_b]
temperatura_ambiente = line[indice_b+1:indice_c]
humedad_sustrato = line[indice_c+1:indice_d]
estatus_temp = line[indice_d+1:indice_e]
azul = line[indice_e+2:indice_g]
blanco = line[indice_g+2:indice_h]
rojo = line[indice_h+2:indice_i]
bomba = line[indice_i+2:indice_j]
tempico = line[indice_j+1:indice_k]
tsustrato = line[indice_k+1:indice_l]
print("DATA: "+line)
print("---------------------")
print("estaus temporizador: ", estatus_temp)
print("azul: ", azul)
print("blanco: ", blanco)
print("rojo: ", rojo)
print("bommba: ", bomba)
print("humedad ambiente: ",humedad_ambiente)
print("temperatura ambiente: ", temperatura_ambiente)
print("temperatura sustrato: ", tsustrato)
print("tem interna: ",tempico)
print("humedad sustrato: ",humedad_sustrato)
print("---------------------")
else:
print("++++++++++++++++++++++")
print("sin data para recibir")
print("++++++++++++++++++++++")
time.sleep(2)