help with E32 program (simple)

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: help with E32 program (simple)

Post by Roberthh » Sat May 14, 2022 4:01 pm

The difference could be caused by encoding or by different \r \n behaviour.

NateOdem
Posts: 13
Joined: Sun May 08, 2022 5:18 pm

Re: help with E32 program (simple)

Post by NateOdem » Thu May 19, 2022 9:41 pm

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")

User avatar
francis
Posts: 28
Joined: Sat Aug 14, 2021 8:14 am

Re: help with E32 program (simple)

Post by francis » Wed May 25, 2022 8:51 pm

rec is a string not a single character
Your program has no hope of working and you've ignored everything we've told you

NateOdem
Posts: 13
Joined: Sun May 08, 2022 5:18 pm

Re: help with E32 program (simple)

Post by NateOdem » Wed May 25, 2022 9:11 pm

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.

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: help with E32 program (simple)

Post by karfas » Thu May 26, 2022 5:04 am

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)
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

User avatar
francis
Posts: 28
Joined: Sat Aug 14, 2021 8:14 am

Re: help with E32 program (simple)

Post by francis » Thu May 26, 2022 10:46 am

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

Post Reply