Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8026

Python • Sending lists over UART with Python

$
0
0
I am tracking some soccer playing robots and an orange golf ball with colored dots on them at around 30 frames per second with an overhead camera using OpenCV’s blob detector on a Raspberry Pi 5. Currently I’m printing it to the screen, and the data looks like this:

robot1 = [robot1x, robot1y, robot1angle]
robot2 = [robot2x, robot2y, robot2angle]
robot3 = [robot3x, robot3y, robot3angle]
robot4 = [robot4x, robot4y, robot4angle]
ball = [ballx, bally]

I should note that these are not variables named robot2x etc., but numbers in there and I access them with something like robot1[2] for finding robot2’s angle, which I might use in a function. The X and Y data may be larger than 255, and the angle data will be between -180 and +180. Sometimes the camera will not detect a robot (like due to a weird glare or the robot has been removed from the playfield) and so there will not be data for that robot (I’m still figuring out what to do about that, code-wise).

I need to send all this data from the Raspberry Pi 5 to four different Picos so that they can use the data to each make calculations and control their robot (wirelessly, over an nRF24L01 wireless module). I have the physical connection working.

I’m having a hard time figuring out how to send this decimal numerical data, as a set of lists, over the GPIO serial UART pins. I can send data, but it’s very confusing, and I’m new to this. The data I get over UART is characters even though I’m sending numbers. How can I send decimal numbers which may be larger than one byte (but no more than two) as a list over UART? I do not understand the encoding scheme of UART, and when I look at tutorials they seem to use these brackets {} with variable names in them sometimes, and the process seems much more complicated than I expected. I need to get this done, but I’m mostly doing it to learn, so I guess what I’m asking for is an overall strategy, and maybe point me in the direction of some resources I can learn the basics about what these {} mean around variable names in Python (and MicroPython?), and UART encoding. I have looked at a lot of tutorials, but I’m missing some fundamentals.

Statistics: Posted by BrianZweerink — Thu Mar 27, 2025 2:44 pm



Viewing all articles
Browse latest Browse all 8026

Trending Articles