Page 3 of 3

Re: help with E32 program (simple)

Posted: Sat May 14, 2022 4:01 pm
by Roberthh
The difference could be caused by encoding or by different \r \n behaviour.

Re: help with E32 program (simple)

Posted: Thu May 19, 2022 9:41 pm
by NateOdem
Ok, can anyone look at this and see if they have an idea as to why it's not working?
( for reference, the TX side is transmitting:
"(,2,255,1,0,0,1,1,0,1,0,126,685,1011,975,)"

Code: Select all

from machine import Pin,UART
import _thread
from time import sleep

uart = UART(1,115200, tx=Pin(4), rx=Pin(5))
command = []
inCommand = False
led=Pin(25,Pin.OUT)

def handle():
    if len(command) == 16:
        print(command)
        
    else:
        print('Incomplete Command Received')



while True:
    if uart.any():
        rec = uart.read()
        #print('rec')
        if rec == '(':
            inCommand = True
        
        if inCommand == True:
            command.append(rec)
        
        if rec == ')':
            handle()
            command = []
            inCommand = False
            
    else:
        print("No Data Received")

Re: help with E32 program (simple)

Posted: Wed May 25, 2022 8:51 pm
by francis
rec is a string not a single character
Your program has no hope of working and you've ignored everything we've told you

Re: help with E32 program (simple)

Posted: Wed May 25, 2022 9:11 pm
by NateOdem
How is rec a string? it's = uart.read().
As I understand it, (and I may be completely wrong, - and if so, PLEASE correct me) uart.read() reads a single byte, so rec should be a byte?.
I am not ignoring anything that has been said, I am just not understanding anything the way it has been stated. I am hoping for not only suggestions on how to write the program, but also the logic behind the suggestions as well. The point of all of this is to not only get this program to work, but for me to gain knowledge as to WHY it works the way it does. You say it's a string, how about explaining why it is a string, or what line of the code that sets it as a string. Telling me that "it's a string" only goes so far, and still doesn't help me to understand anything.

Re: help with E32 program (simple)

Posted: Thu May 26, 2022 5:04 am
by karfas
You assume that uart.read() returns one byte. This might happen in rare cases, but the documentation of uart.read() states otherwise:
Read characters. If nbytes is specified then read at most that many bytes, otherwise read as much data as possible. It may return sooner if a timeout is reached. The timeout is configurable in the constructor.
At least the sample code @francis posted told you this:

Code: Select all

while True:
    got = uart.read()
    for ch in got:
        packet.append(ch)

Re: help with E32 program (simple)

Posted: Thu May 26, 2022 10:46 am
by francis
Sorry but you're being ridiculous
The documentation, and every answer here tells uart.read() delivers as many characters as possible.

The only reason for believing uart.read() delivers just one character is because you want it to be so. Everything else from documentation to every single answer here tells you otherwise.

And if you just bothered to debug print what uart.read() returns you would know that.
You are not debugging your problem. You are hoping strangers on a forum will slowly rewrite your code so it works