Receive UWB Position Data with Arduino Mega 2560 (Example Code)
This guide connects a GrowSpace UWB developer tag to an Arduino Mega 2560 over serial, then receives and parses real-time position data with the lec and lep commands, with example code.

About this article
This article shows how to connect a GrowSpace developer tag to an Arduino Mega 2560 board over serial, and receive and parse position data in real time with the lec and lep commands. It also provides example code that uses the Mega 2560, which supports hardware serial, to set up stable high-speed communication.
What you need
- Arduino Mega 2560 board

- GrowSpace developer tag
- Arduino IDE (official: <https://www.arduino.cc/en/software>)
- Jumper cables


⚠️ The UNO board has just 1 hardware serial port, so errors can occur in high-speed communication. The Mega 2560 provides Serial1 to Serial3, which allows stable communication.
Arduino IDE setup and board connection
- Install and run the Arduino IDE
- Apply the following settings from the top menu
- Tools > Board > Arduino Mega or Mega 2560

- Tools > Port > select the connected COM port (example: COM3)

- Connect the Arduino Mega 2560 to the PC with USB
Hardware pin wiring
Using the right connector (5V) of the GrowSpace developer tag, connect as follows:
| Developer tag pin | Arduino Mega pin |
|---|---|
| TX | RX1 (pin 19) |
| RX | TX1 (pin 18) |
| 5V | 5V |
| GND | GND |
🔄 TX ↔ RX must be cross-connected for communication to work.
Below is an example of the Arduino Mega pin layout.
Connect using TX1 (pin 18) and RX1 (pin 19) of the Serial1 port.

Serial relay example (basic communication check)
String inputFromSerial0 = "";
String inputFromSerial1 = "";
void setup() {
Serial.begin(115200); // USB Serial (Serial0)
Serial1.begin(115200); // Hardware Serial1 (pin 18 TX1, pin 19 RX1)
}
void loop() {
// serialEvent() and serialEvent1() are called automatically
}
// Serial0 input → Serial1 output (appends CR)
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
if (inChar != '\n') {
inputFromSerial0 += inChar;
}
if (inChar == '\n') {
Serial1.print(inputFromSerial0);
Serial1.print('\r');
inputFromSerial0 = "";
}
}
}
// Serial1 input → Serial0 output
void serialEvent1() {
while (Serial1.available()) {
char inChar = (char)Serial1.read();
inputFromSerial1 += inChar;
if (inChar == '\n') {
Serial.print("From Serial1: ");
Serial.print(inputFromSerial1);
inputFromSerial1 = "";
}
}
}
Explanation
setup()initializes the USB serial and the hardware serial (Serial1).serialEvent()sends the text typed on the PC (Serial0) to the tag.serialEvent1()prints the response from the tag to the PC.- When a command is sent, the code parses by the newline character (
\n) and adds the\rcarriage return automatically.
Serial Monitor setting tips
- Baudrate: 115200bps
- Newline setting: New Line
- If the tag prints system information after you send the
sicommand, communication works.
Enter the si command in the serial monitor. If you see a normal response, the connection works.

Command-based position parsing example
String bufferSerial0 = "";
String bufferSerial1 = "";
void setup() {
Serial.begin(115200); // USB Serial
Serial1.begin(115200); // Serial1 for the developer tag connection
}
void loop() {
// loop stays empty; serialEvent / serialEvent1 run automatically
}
// Receive commands from Serial0
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
if (inChar != '\n') {
bufferSerial0 += inChar;
}
if (inChar == '\n') {
bufferSerial0.trim(); // Remove the newline
if (bufferSerial0.equalsIgnoreCase("lec") || bufferSerial0.equalsIgnoreCase("lep")) {
Serial.print("Command sent: ");
Serial.println(bufferSerial0);
Serial1.print(bufferSerial0); // Appends CR
Serial1.print('\r');
} else {
Serial.println("⚠ Unsupported command.");
}
bufferSerial0 = "";
}
}
}
// Receive the response from Serial1 → parse lec/lep
void serialEvent1() {
while (Serial1.available()) {
char inChar = (char)Serial1.read();
bufferSerial1 += inChar;
if (inChar == '\n') {
bufferSerial1.trim();
if (bufferSerial1.startsWith("POS,")) {
parseLEP(bufferSerial1);
} else if (bufferSerial1.startsWith("DIST,")) {
parseLEC(bufferSerial1);
} else {
Serial.println("[Response] " + bufferSerial1);
}
bufferSerial1 = "";
}
}
}
// --- Parse position data (lep) ---
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();
}
// --- Parse the full lec response ---
void parseLEC(String line) {
Serial.println("[LEC distance + position result]");
int posIndex = line.indexOf("POS,");
if (posIndex == -1) {
Serial.println("→ Position information missing");
return;
}
String distPart = line.substring(0, posIndex - 1);
String posPart = line.substring(posIndex);
Serial.println("▶ Anchor distance information:");
int anchorIdx = 0;
int anStart = 0;
while ((anStart = distPart.indexOf("AN", anStart)) != -1) {
int idStart = anStart + 2;
int idEnd = distPart.indexOf(",", idStart);
String id = distPart.substring(idStart, idEnd);
int valStart = idEnd + 1;
float x = distPart.substring(valStart, distPart.indexOf(",", valStart)).toFloat();
valStart = distPart.indexOf(",", valStart) + 1;
float y = distPart.substring(valStart, distPart.indexOf(",", valStart)).toFloat();
valStart = distPart.indexOf(",", valStart) + 1;
float z = distPart.substring(valStart, distPart.indexOf(",", valStart)).toFloat();
valStart = distPart.indexOf(",", valStart) + 1;
float d = distPart.substring(valStart, distPart.indexOf(",", valStart)).toFloat();
Serial.print("AN"); Serial.print(anchorIdx++); Serial.print(" (ID "); Serial.print(id); 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");
anStart = valStart;
}
Serial.println("▶ Tag position information:");
parseLEP(posPart);
}
- lep result

- lec result

Summary
With this guide, you can set up serial communication with a GrowSpace developer tag on an Arduino Mega 2560, and practice parsing and printing real-time position data based on the lec and lep commands.
lep: check the X, Y, Z coordinates and the quality (QF)lec: get the anchor information, the distances and the position data