UWB Q1

Receive UWB Position Data with Raspberry Pi (Python Example)

A hands-on example that connects a GrowSpace UWB developer tag to a Raspberry Pi 4, receives real-time position data with the lec and lep commands, and parses it with Python.

Raspberry Pi integration, what you need, screen 1

About this article

This article shows how to connect a GrowSpace UWB developer tag to a Raspberry Pi 4 Model B, and receive and parse real-time position data with the lec and lep commands. It centers on a hands-on example that implements serial communication in Python and analyzes the position data directly.


What you need

Raspberry Pi integration, what you need, screen 1


Set up the Raspberry Pi serial port

  1. Enter the following command in the terminal:

sudo raspi-config

  1. Go to the menu:
    \* Interface Options → Serial Port
    \* Login shell via serial: No
    \* Enable serial port hardware: Yes
  2. When the setup is done, reboot with the sudo reboot command

Serial pin wiring (UART)

Using the 3.3V connector (left side) of the GrowSpace developer tag, connect as follows:

Developer tag pinRaspberry Pi pin numberGPIO number
TXPin 10 (RXD)GPIO15
RXPin 8 (TXD)GPIO14
3.3VPin 1–
GNDPin 6–

⚠️ Make sure TX ↔ RX is cross-connected: tag TX → Pi RX, tag RX → Pi TX

Reference: Raspberry Pi GPIO pin layout

Below is the full pin map of the Raspberry Pi 40-pin header. Connect exactly by the following pin numbers:

This diagram helps you understand the serial connection to the developer tag more clearly.

For the full GPIO layout and circuit information, see the official documentation: Raspberry Pi official pinout and drawings

Raspberry Pi integration, reference: Raspberry Pi GPIO pin layout, screen 3


Caution: serial port types on the GrowSpace tag

The GrowSpace developer tag has serial ports with different voltage levels on the left and right sides. This is not just a difference in pin position. The levels are electrically completely different, so you must tell them apart.

Check this before you connect


Python serial communication code

import serial
import threading

uwb = serial.Serial('/dev/serial0', baudrate=115200, timeout=0.5)

def read_from_uwb():
    while True:
        if uwb.in_waiting:
            data = uwb.readline().decode(errors='ignore').strip()
            if data:
                print(f"[UWB response] {data}")

def write_to_uwb():
    while True:
        try:
            cmd = input(">>> ")
            if cmd.strip():
                uwb.write((cmd + '\r').encode())
        except KeyboardInterrupt:
            print("\nExiting.")
            break

if __name__ == "__main__":
    print("UWB serial relay started (/dev/serial0)")
    threading.Thread(target=read_from_uwb, daemon=True).start()
    write_to_uwb()

Example: when you enter the si command and the device information is printed, communication works.


Position data parsing example (lep and lec commands)

LEP (position data)

def parse_lep(line):
    print("\n[LEP position result]")
    parts = line.strip().split(',')
    if len(parts) >= 5:
        print(f"X: {parts[1]}")
        print(f"Y: {parts[2]}")
        print(f"Z: {parts[3]}")
        print(f"Quality (QF): {parts[4]}")
    else:
        print("→ Invalid LEP format.")

LEC (distance and position information)

def parse_lec(line):
    print("\n[LEC distance + position result]")
    try:
        pos_idx = line.index("POS,")
        dist_part = line[:pos_idx].strip()
        pos_part = line[pos_idx:].strip()

        anchors = []
        tokens = dist_part.split(',')
        i = 2
        while i < len(tokens):
            if tokens[i].startswith("AN"):
                anchor_id = tokens[i+1]
                x = float(tokens[i+2])
                y = float(tokens[i+3])
                z = float(tokens[i+4])
                d = float(tokens[i+5])
                anchors.append((anchor_id, x, y, z, d))
                i += 6
            else:
                i += 1

        for idx, (aid, x, y, z, d) in enumerate(anchors):
            print(f"AN{idx} (ID {aid}): x={x}, y={y}, z={z}, distance={d}m")

        parse_lep(pos_part)

    except Exception as e:
        print(f"lec parsing failed: {e}")

Full receive loop (automatic parsing)

input_buffer = ""

def read_from_uwb():
    global input_buffer
    while True:
        if uwb.in_waiting:
            data = uwb.read().decode(errors='ignore')
            if data == '\n':
                line = input_buffer.strip()
                if line.startswith("POS,"):
                    parse_lep(line)
                elif line.startswith("DIST,"):
                    parse_lec(line)
                else:
                    print(f"[Other response] {line}")
                input_buffer = ""
            else:
                input_buffer += data

Summary

This manual introduced how to set up serial communication with a GrowSpace developer tag on a Raspberry Pi, and how to receive and parse position data in real time with Python, based on the lep and lec commands.

With this procedure:

If a problem occurs during the exercise, be sure to check again whether TX/RX is cross-connected and whether the port is enabled.