Raspberry Pi Integration

In This guide

This guide explains how to connect the GrowSpace UWB developer tag to a Raspberry Pi 4 Model B and receive real-time location data using the lec and lep commands. It focuses on a hands-on example where you use Python to handle serial communication and directly analyze the location data.

Required Materials

  • Raspberry Pi 4 Model B

  • USB-C power adapter (5V 3A or higher)

  • GrowSpace UWBdeveloper tag

  • Jumper wires (TX, RX, GND, 3.3V)

  • Python 3.9.2 or higher (based on Debian GNU/Linux 11)

  • pyserial package installed


Raspberry Pi Serial Port Setup

  1. Enter the following command in the terminal:

    sudo raspi-config
  2. Navigate through the menu:

    • Interface Options → Serial Port

    • Login shell via serial: No

    • Enable serial port hardware: Yes

  3. After completing the setup, reboot using sudo reboot


Serial Pin Connection (UART)

Connect the pins as shown below, using the 3.3V connector on the left side of the GrowSpace developer tag as the reference:

Developer Tag Pin
Raspberry Pi Pin Number
GPIO Number

TX

Pin 10 (RXD)

GPIO15

RX

Pin 8 (TXD)

GPIO14

3.3V

Pin 1

-

GND

Pin 6

-

⚠️ Make sure to cross-connect TX and RX: (Tag TX → Pi RX, Tag RX → Pi TX)

Note: Raspberry Pi GPIO Pinout

Below is the full pin map of the 40-pin header on the Raspberry Pi. Use the pin numbers shown to make accurate connections.

  • TX0: GPIO14 (Pin 8)

  • RX0: GPIO15 (Pin 10)

  • 3.3V: Pin 1

  • GND: Pin 6

This diagram helps you better understand how to connect the developer tag via serial communication.

To view the full GPIO layout and circuit details, visit the official documentation: See official Raspberry Pi pinout and schematics


Caution! Serial Port Types on the GrowSpace Tag

The GrowSpace developer tag has two serial ports, one on each side, with different voltage levels. These are not just different pin positions—they use completely different electrical levels, so it's important to use the correct port for your device.

  • Port 1 (Left Connector)

    • Pins: TX, RX, 3.3V, GND

    • Voltage Level: 3.3V Level

    • Use Case: For devices that use 3.3V logic, such as Raspberry Pi or ESP32

  • Port 2 (Right Connector)

    • Pins: TX, RX, 5V, GND

    • Voltage Level: 5V Level

    • Use Case: For devices that use 5V logic, such as Arduino UNO

Check Before You Connect

  • The GPIO pins on the Raspberry Pi only support 3.3

  • If you connect the 5V port (right-side connector) by mistake, it may damage the Raspberry Pi's UART circuit.

  • For this manual, always use the **left connector (3.3V port)** on the GrowSpace tag.


Python-Based 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("Starting UWB Serial Relay (/dev/serial0)")
    threading.Thread(target=read_from_uwb, daemon=True).start()
    write_to_uwb()
  • read_from_uwb() prints real-time data received from the UWB tag.

  • write_to_uwb() sends a command input (includes \r at the end).

Example: If the si command returns device information, the communication is working correctly.


Location Data Parsing Example (lep, lec commands)

LEP(For location data only)

def parse_lep(line):
    print("\n[LEP location 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 (For distance + location data)

def parse_lec(line):
    print("\n[LEC distance + location 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 Receiving Loop Structure (Auto 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 responses] {line}")
                input_buffer = ""
            else:
                input_buffer += data
  • If the response starts with POS, parse it as LEP

  • If the response starts with DIST, parse it as LEC

  • Print all other responses as well


Conclusion

In this manual, we explained how to set up serial communication between the GrowSpace developer tag and a Raspberry Pi, and how to receive and parse real-time location data using the lep and lec commands in Python.

Through this process, you can:

  • Establish stable communication using the Raspberry Pi’s /dev/serial0 port

  • Parse and view real-time location data with Python

  • Use it as a testbed for RTLS experiments and prototyping

If you encounter any issues during testing, make sure to check the TX/RX wiring and verify that the serial port is enabled.

Last updated