UWB Q1

Receive UWB Position Data with ESP32 (Arduino IDE Example)

A step-by-step guide to connect a GrowSpace UWB developer tag to an ESP32 board, then receive and parse real-time position data with the lec and lep commands.

ESP32 integration, what you need, screen 1

About this article

This article shows how to connect a GrowSpace developer tag to an Arduino ESP32 board, and receive and parse real-time position data with the lec and lep commands. The steps are explained one by one, so that even readers connecting an ESP32 and a tag initially can follow them easily.

Unlike the UNO, the ESP32 supports multiple hardware serial ports, and it is a suitable board for building a small test environment.


What you need

ItemUse
ESP32 board (example: DevKitC) ESP32 integration, what you need, screen 1Serial reception and parsing
GrowSpace developer tagDevice that sends position information
Arduino IDEWriting and uploading code
Jumper cables (4 pins)For TX, RX, GND and 3.3V connections

Arduino IDE setup for ESP32

Installation

Add the ESP32 board

ESP32 integration, adding the ESP32 board, screen 3

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

ESP32 integration, adding the ESP32 board, screen 4

ESP32 integration, adding the ESP32 board, screen 5

ESP32 integration, adding the ESP32 board, screen 6


Serial wiring between the tag and ESP32

The left connector of the GrowSpace developer tag supports 3.3V serial.
Connect it to the TX2/RX2 pins of the ESP32 board as follows:

Developer tagESP32 board
TXGPIO 16 (RX2)
RXGPIO 17 (TX2)
GNDGND
3.3V3.3V

⚠️ TX ↔ RX must be cross-connected.
Example: tag TX → ESP32 RX, tag RX → ESP32 TX

Below is the pin map of the ESP32 DevKit. Find the position of TX2/RX2 and connect exactly:

ESP32 integration, serial wiring, screen 8


Serial relay example code

This code lets the ESP32 relay serial data between the PC and the tag.

#define SERIAL2_RX 16  // GPIO16
#define SERIAL2_TX 17  // GPIO17

String inputFromSerial = "";
String inputFromSerial2 = "";

void setup() {
  Serial.begin(115200);
  Serial2.begin(115200, SERIAL_8N1, SERIAL2_RX, SERIAL2_TX);
  Serial.println("ESP32 Serial <-> Serial2 relay (split on \\n, add \\r, parse lep/lec)");
}

void loop() {
  // Serial input → send to Serial2
  while (Serial.available()) {
    char ch = (char)Serial.read();
    if (ch != '\n') {
      inputFromSerial += ch;
    }

    if (ch == '\n') {
      Serial2.print(inputFromSerial);
      Serial2.print('\r');  // Add CR
      inputFromSerial = "";
    }
  }

  // Serial2 input → parse and print
  while (Serial2.available()) {
    char ch = (char)Serial2.read();
    inputFromSerial2 += ch;

    if (ch == '\n') {
      inputFromSerial2.trim();

      if (inputFromSerial2.startsWith("POS,")) {
        parseLEP(inputFromSerial2);
      } else if (inputFromSerial2.startsWith("DIST,")) {
        parseLEC(inputFromSerial2);
      } else {
        Serial.print("[Serial2 → Serial] Received: ");
        Serial.println(inputFromSerial2);
      }

      inputFromSerial2 = "";
    }
  }
}

Position data parsing example (lep / lec commands)

The developer tag returns the current position information with the lep or lec command. The code below analyzes that response and prints it in a readable form.

#define SERIAL2_RX 16  // GPIO16
#define SERIAL2_TX 17  // GPIO17

String inputFromSerial = "";
String inputFromSerial2 = "";

void setup() {
  Serial.begin(115200);
  Serial2.begin(115200, SERIAL_8N1, SERIAL2_RX, SERIAL2_TX);
  Serial.println("ESP32 Serial <-> Serial2 relay (split on \\n, add \\r, parse lep/lec)");
}

void loop() {
  // Serial input → send to Serial2
  while (Serial.available()) {
    char ch = (char)Serial.read();
    if (ch != '\n') {
      inputFromSerial += ch;
    }

    if (ch == '\n') {
      Serial2.print(inputFromSerial);
      Serial2.print('\r');  // Add CR
      inputFromSerial = "";
    }
  }

  // Serial2 input → parse and print
  while (Serial2.available()) {
    char ch = (char)Serial2.read();
    inputFromSerial2 += ch;

    if (ch == '\n') {
      inputFromSerial2.trim();

      if (inputFromSerial2.startsWith("POS,")) {
        parseLEP(inputFromSerial2);
      } else if (inputFromSerial2.startsWith("DIST,")) {
        parseLEC(inputFromSerial2);
      } else {
        Serial.print("[Serial2 → Serial] Received: ");
        Serial.println(inputFromSerial2);
      }

      inputFromSerial2 = "";
    }
  }
}

// ✅ LEP result parser: POS,x,y,z,qf
void parseLEP(String line) {
  Serial.println("[LEP position result]");
  int idx = 0;
  String parts[5];

  while (line.length() > 0 && idx < 5) {
    int comma = line.indexOf(',');
    if (comma == -1) {
      parts[idx++] = line;
      break;
    } else {
      parts[idx++] = line.substring(0, comma);
      line = line.substring(comma + 1);
    }
  }

  Serial.print("X: "); Serial.println(parts[1]);
  Serial.print("Y: "); Serial.println(parts[2]);
  Serial.print("Z: "); Serial.println(parts[3]);
  Serial.print("Quality (QF): "); Serial.println(parts[4]);
  Serial.println();
}

// Safe split utility (simple)
static void splitByComma(const String& s, std::vector<String>& out) {
  out.clear();
  int start = 0;
  while (start <= s.length()) {
    int comma = s.indexOf(',', start);
    if (comma == -1) {
      out.push_back(s.substring(start));
      break;
    } else {
      out.push_back(s.substring(start, comma));
      start = comma + 1;
    }
  }
}

// ✅ LEC result parser (safe token parsing): DIST, n, (ANk, id, x, y, z, d)*, POS, x, y, z, qf
void parseLEC(String line) {
  Serial.println("[LEC distance + position result]");

  line.trim();
  std::vector<String> t;
  splitByComma(line, t);
  if (t.size() < 2 || t[0] != "DIST") {
    Serial.println("→ Format error: no DIST header");
    return;
  }

  int i = 1;
  int anchorCount = t[i++].toInt(); // Example: 4
  int parsedAnchors = 0;

  // Parse the anchor groups: ANk, id, x, y, z, d
  while (i + 5 < (int)t.size() && t[i].startsWith("AN")) {
    String anLabel = t[i++];      // AN0, AN1, ...
    String anId    = t[i++];      // 3364, 35BE, ...
    float x = t[i++].toFloat();   // -1.00
    float y = t[i++].toFloat();   // 11.48
    float z = t[i++].toFloat();   // 0.00
    float d = t[i++].toFloat();   // 2.80

    Serial.print(anLabel); Serial.print(" (ID ");
    Serial.print(anId); Serial.print("): ");
    Serial.print("x="); Serial.print(x);
    Serial.print(", y="); Serial.print(y);
    Serial.print(", z="); Serial.print(z);
    Serial.print(" → distance: "); Serial.print(d); Serial.println("m");

    parsedAnchors++;
  }

  if (parsedAnchors != anchorCount) {
    Serial.print("→ Warning: the anchor count given by DIST (");
    Serial.print(anchorCount);
    Serial.print(") does not match the parsed count (");
    Serial.print(parsedAnchors);
    Serial.println(")");
  }

  // POS, x, y, z, qf
  if (i < (int)t.size() && t[i] == "POS") {
    // parseLEP expects the whole "POS,..." string, so rebuild it and pass it on
    String posLine = "POS";
    for (int k = i + 1; k < (int)t.size(); ++k) {
      posLine += ",";
      posLine += t[k];
    }
    Serial.println("▶ Tag position:");
    parseLEP(posLine);
  } else {
    Serial.println("→ No POS information");
  }
}

ESP32 integration, position data parsing example (lep / lec commands), screen 9

ESP32 integration, position data parsing example (lep / lec commands), screen 10


Test summary


Summary

This manual explained the whole flow of connecting a GrowSpace developer tag to an ESP32, entering position commands over serial communication, and receiving and parsing the data.

With this procedure, you can track the real-time position of a single tag. It can then lead to further experiments such as BLE transmission, Wi-Fi integration and MQTT integration.

If the connection fails or there is no response during the exercise, be sure to check again whether TX/RX pins are cross-connected and how the serial port is set.