Skip to content

BU03-Kit UWB positioning bring-up (tag + anchors + XIAO ESP32-C3)

BU03-Kit UWB Positioning: Bench Bring-Up Notes

Summary

The AI-Thinker BU03-Kit is an ultra-wideband (UWB) radio board that measures distances (not directions) between a tag, which goes on the drone, and several fixed anchors. With distances to three anchors at known positions you can work out where the tag is, like GPS but indoors. Two things are not obvious from the vendor documentation. First, boards must be configured through the USB-C port labelled “TTL”, not the one labelled “USB”: the “USB” port freezes on save and the settings are lost. Second, it is the tag that outputs every anchor distance, as 37-byte binary frames on pad PA2. We wired PA2 to a Seeed XIAO ESP32-C3, which checks each frame and solves a 2D position. A browser visualiser plots the result live. The full chain works at 10 Hz, but positions in the first walk-around were off by 0.2–0.7 m. The cause is still being investigated (see “First live results”).

Warning

⚠️ Carbon fibre frames interfere with UWB. Carbon fibre blocks and reflects UWB signals, so positioning can become inaccurate or the signal can drop out completely.

Fix: Mount the tag’s antenna well away from the carbon fibre, in a spot with the best possible line of sight to the UWB anchor antennas.

Code: the XIAO firmware, visualiser and setup README are in the SAFMC 2027 Cat D2 repo under working-test-code/bu03-uwb-positioning (private: ask the team for access).

Project: SAFMC27 indoor positioning · Hardware: AI-Thinker BU03-Kit (firmware V1.0.0, built Jul 19 2024) + Seeed XIAO ESP32-C3 Written: 3 Dec 2026, from a full day of bench testing on the club’s own boards.

AI-Thinker’s documentation for this kit is thin, partly in Chinese, and misleading in a few places. Everything marked ✅ was tested on our hardware. Anything else is from the vendor docs and says so.

Contents

  1. TL;DR
  2. How the system works
  3. The board: ports and pins
  4. Configuring a board (AT commands)
  5. Who outputs the distances
  6. The PA2 data frame
  7. XIAO ESP32-C3 bridge firmware
  8. Computing position
  9. Live visualiser
  10. Our boards and test setup
  11. Troubleshooting
  12. Lessons learned
  13. Next steps
  14. References

1. TL;DR

  • Configure boards through the USB-C labelled “TTL” (a CH340 USB-to-serial chip), never the one labelled “USB”. Install the WCH CH340 driver first.
  • AT syntax: AT+SETUWBMODE=0, then AT+SETCFG=<id>,<role>,1,1 (role 0 = tag, 1 = anchor), then AT+SAVE. Use =, not a space, and end each command with CR+LF.
  • The tag streams every anchor distance out of pad PA2 at 10 Hz, 115200 8N1, in 37-byte frames: AA 25 01 + 8 × uint32 little-endian (mm) + checksum + 55.
  • A XIAO ESP32-C3 reading PA2 (→ D7, plus GND) can check the frames, filter them, and solve a 2D position from 3 anchors.
  • The tag’s own AT+DISTANCE always reads 0. That doesn’t mean it isn’t ranging: check PA2.

2. How the system works

  • The BU03 is an ultra-wideband (UWB) ranging module. It measures distance only, not direction, between a tag and anchors (the vendor calls them “base stations”), using two-way ranging (TWR). For direction you’d need the dual-antenna BU04 in PDOA mode.
  • One network holds up to 8 anchors (IDs 0–7) and 10 tags. Every board must use the same channel and data rate.
  • Position = multilateration. Distances to 3+ anchors at known positions give a 2D fix. 3D needs 4+ anchors that aren’t all at the same height.
  • Vendor spec: about 25 m line-of-sight range and about 10 cm accuracy. ✅ On the bench at about 0.75 m, readings jittered by roughly ±20–40 mm with no calibration.
    flowchart LR
    A["Anchors 0..7<br/>fixed, known positions"] -- UWB radio --> T["BU03 tag<br/>(on the drone)"]
    T -- "PA2 → D7<br/>115200 8N1, binary" --> X["XIAO ESP32-C3<br/>validate, filter, solve"]
    X -- USB serial --> H["Laptop visualiser now<br/>RPi 5 → MAVLink later"]
  

3. The board: ports and pins

Each kit has an STM32F103 driving the UWB module, and two USB-C ports that do different jobs. Mixing them up cost us most of the morning.

Port / pinWhat it isUse it for
USB-C “TTL”CH340 USB-to-serial chip (USB ID 1A86:7523) on UART1✅ Configuration (AT) port, 115200. Shows up as USB-SERIAL CH340 (COMx).
USB-C “USB”STM32 native USB, “STMicroelectronics Virtual COM Port”Power, and the vendor’s data output. ✅ Don’t configure through it. It answers AT+GETCFG, but freezes after any AT+SETCFG, so AT+SAVE never gets through and the config is lost at power-off.
Pad PA2 (underside)UART2 TX✅ Ranging data output, 115200 8N1, 3.3 V logic.
Pad PA3UART2 RXLeave unconnected.
Header TX1 / RX1Same UART1 as the CH340✅ Never answered an external microcontroller at any baud rate or in either pin order, most likely because the on-board CH340 shares the lines. Use the TTL USB-C instead.
5V / VBAT / 3V3 / GNDPowerVBAT is a battery input: don’t feed USB 5 V into it. Don’t power a board from two supplies at once. Vendor figure: up to about 500 mA peak.

⚠️ Charge-only cables: our first cable carried no data, so the board didn’t appear in Windows at all. If no COM port shows up, swap the cable first.


4. Configuring a board (AT commands)

PC setup (one time)

  1. Install the WCH CH340 driver (CH341SER.EXE from wch-ic.com, or Windows Update → Optional updates). This needs admin rights. Without it, Device Manager shows “USB Serial” with an error and no COM number.
  2. Plug in the board’s TTL port.
  3. Open a serial terminal at 115200 baud, CR+LF line endings: the PlatformIO monitor, PuTTY, or pyserial.

Command reference ✅

CommandReply / meaning
ATOK. Only answers on the TTL port.
AT+GETCFGgetcfg ID:0, Role:1, CH:1, Rate:1
AT+GETVERgetver software:V1.0.0
AT+GETUWBMODEtwr_pdoa_mode: 0 (0 = TWR, 1 = PDOA)
AT+SETUWBMODE=0Select TWR (what we use)
AT+SETCFG=<id>,<role>,<ch>,<rate>id 0–7 for anchors · role 0 = tag, 1 = anchor · ch 1 = UWB channel 5 (0 = channel 9) · rate must be 1 (6.8 Mbps only)
AT+SAVEOK, then the module reboots and prints a parameter dump. Without this, changes are lost at power-off.
AT+DISTANCELive range in metres. Only meaningful on an anchor; a tag always returns 0.000000.
AT+RESTOREFactory reset (from the vendor docs, not tested)

Gotchas

  • AT+SETCFG=0,0,1,1 works; AT+SETCFG 0,0,1,1 with a space is silently ignored.
  • Some replies are in GBK-encoded Chinese and look garbled in most terminals: 角色 = role, 标签 = tag, 基站 = anchor (base station), 信道 = channel, 速率 = rate.

Procedure ✅

AT                     -> OK
AT+SETUWBMODE=0        -> OK
AT+SETCFG=0,0,1,1      -> setcfg ID:0, Role:0, CH:1, Rate:1     (tag, ID 0)
AT+SAVE                -> OK, module reboots, prints parameter dump
AT+GETCFG              -> getcfg ID:0, Role:0, CH:1, Rate:1     (confirms it stuck)
  • Anchor n: AT+SETCFG=n,1,1,1, then AT+SAVE.
  • Check the saved config; don’t trust the sticker. One board came from the factory as anchor 2, and we turned it into our tag.
  • The dump after AT+SAVE shows the settings loaded at power-on, so reading the right config after that reboot proves the save worked. Defaults seen: Kalman filter on (Q 0.018, R 0.642), antenna delay 16336, calibration a = 1.0, b = 0, power-on count 9.
  • One board printed IIC Error 3 during AT+SAVE but still kept its config. If a board ever comes back with its old settings, suspect its settings memory.

5. Who outputs the distances

  • ✅ The tag streams all anchor distances on PA2 at about 10 Hz. That’s what lets a drone carrying the tag know its own position without any radio link to the ground.
  • AI-Thinker’s guide implies the anchor outputs the data. The anchor does output the range too, but on its own that description makes it sound like the tag doesn’t. We nearly redesigned the system around a ground-to-air radio link because of it.
  • ✅ An anchor’s AT+DISTANCE shows the live range; the tag’s always reads 0, which adds to the confusion.
  • ✅ With no anchor powered and in range, the tag’s PA2 is silent. It doesn’t send zero-filled frames, so a silent line doesn’t mean bad wiring.

6. The PA2 data frame

✅ Verified on hardware. 115200 8N1, 37 bytes per frame, about 10 frames per second.

BytesContentNotes
0–2AA 25 01Header
3–34d0 … d78 × uint32, little-endian, millimetres. Slot n = anchor ID n; 0 = no reading
35Checksum(sum of bytes 0..34) & 0xFF
3655Tail

Worked example (real capture, one anchor at 770 mm):

AA 25 01 | 02 03 00 00 | 00 00 00 00 ×7 | D5 | 55
d0       = 0x00000302 = 770 mm
checksum = AA+25+01+02+03 = 0x1D5 -> D5

Parsing: sync on AA 25 01, read 34 more bytes, check the tail is 55 and the checksum matches, then decode. If either check fails, drop the frame and look for the next header. ✅ Every frame count we took on the bench showed 0 bad frames.

Example code you’ll find online assumes 35-byte frames, which leaves out the checksum and tail. Don’t use those parsers without fixing that.


7. XIAO ESP32-C3 bridge firmware

Wiring

BU03 tagXIAO ESP32-C3
PA2 (UART2 TX)D7 / GPIO20
GNDGND

That’s all it needs. Power the tag from its own USB-C, or a regulated 5 V supply on the drone. Leave the XIAO’s D6 unconnected, because it prints the ESP32 boot log at power-up.

Project

  • PlatformIO project working-test-code/bu03-uwb-positioning in the Cat D2 repo, environment xiao_esp32c3 (platform espressif32, Arduino framework). We use PlatformIO in VS Code, not the Arduino IDE.
  • platformio.ini sets -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1. That makes Serial the native USB port (/dev/ttyACM0 on a Pi), and Serial0/Serial1 the hardware UARTs, remapped to free pins.
  • Build and flash: pio run -t upload. Monitor: pio device monitor, or the 🔌 icon in VS Code’s status bar.
  • Only one program can hold the COM port. Close the serial monitor before uploading.

Things that bit us in the ESP32 Arduino core

  • setRxBufferSize() must be called before begin(); after begin() the core logs an error and ignores it.
  • With native USB CDC, each Serial.print blocks for up to 100 ms when no host is reading the port, which stalls the loop and drops UART bytes. Fix: Serial.setTxTimeoutMs(0).

Processing

Each frame is checked (header, checksum, tail). Each anchor’s distance gets a 3-sample median filter, and anything over 30 m is rejected. The result is then output according to the mode.

Serial-monitor commands

CommandOutput
!pos (default)Human-readable 2D position once a second, averaged over that second: t=12.6s X=1.48 m Y=0.90 m | fit err 0.04 m | d0=1.73 d1=1.75 d2=1.71 | 10 fixes
!vizMachine stream for the visualiser: $P,t_ms,x,y,err,d0..d7 per frame (metres; x,y,err empty if there’s no fix) and $A,id,x,y once a second
!binFor the Pi. Binary 32-byte V2 frame per valid BU03 frame (55 AA 20 02, tag, seq, 8 × uint16 mm, 8 × 0xFF, CRC-16/CCITT-FALSE). Unfiltered ranges; switches silently. See include/uwb_frame_v2.h in the code folder
!tag NTag ID (0–2) written into V2 frames
!inject d0 d1 …Self-test: feed a fake BU03 frame (mm) through the parser
!parseDebug text: $UWB,t_ms,d0..d7*XX (mm, 0 = none, NMEA-style XOR checksum). Superseded by !bin for the Pi
!rawHex dump per frame
!anchor ID X YSet an anchor’s position in metres (!anchor ID off to drop one). Not saved across resets; defaults are in main.cpp
!scanWiring check: a UART TX line sits HIGH when idle, so each wire reports as driven or floating. Also listens at 8 baud rates
!helpMode, anchor positions, good/bad frame counts

8. Computing position

Each anchor i at pᵢ gives a circle ‖p − pᵢ‖ = dᵢ. Subtracting the reference anchor’s equation from each of the others makes the system linear:

2 (p_i − p_0) · p  =  d_0² − d_i² + |p_i|² − |p_0|²

With 3 anchors that’s 2 equations in (x, y). With more, solve the 2×2 normal equations (least squares). The firmware also reports a fit error: the RMS gap between each measured distance and the distance from the solved point.

Fit errorMeaning
< 0.05 mGood
0.05–0.15 mFair
> 0.15 mSomething’s wrong: anchor coordinates, a blocked anchor, or a height difference

Practical rules

  • Same height. The 2D solver assumes the tag and anchors are level. A height difference h makes each measured distance √(r² + h²) instead of r, which biases the solution and raises the fit error. For flight, either use a 4th anchor at a different height and solve in 3D, or remove the known height (from a barometer or rangefinder) before solving.
  • Geometry. Accuracy is best inside the anchor polygon and gets worse quickly outside it. Collinear anchors give no solution at all.
  • Line of sight. People, metal and carbon fibre add distance through multipath. Mount the tag antenna clear of the frame.
  • Calibrate against tape-measured distances (d_true = a·d + b). The board stores a and b; ours are uncalibrated (a = 1, b = 0).
  • ✅ The solver was checked in Python against known points and returned them exactly.

9. Live visualiser

tools/uwb_visualiser.html (in the code folder) is a single file that needs no installation. Open it in Chrome or Edge, because it uses the Web Serial API. VS Code’s built-in browser and Firefox won’t work.

  1. Close VS Code’s serial monitor, so COM8 is free.
  2. Click Connect XIAO and pick the XIAO’s COM port. The page sends !viz itself.
  3. You’ll see the anchors, a circle for each measured distance, the tag position with a trail, the fit error (colour-coded), each anchor’s distance, the update rate and the fix rate. Smoothing can be raw, 0.5 s, 1 s or 3 s.
  4. Disconnect switches the XIAO back to !pos. Demo simulates a tag, so you can try it without hardware.

10. Our boards and test setup

StickerSaved configNotes
TagID 0, Role 0 (tag), CH 1, Rate 1, TWRCame from the factory as anchor 2
Anchor 0ID 0, Role 1Origin of our coordinate frame
Anchor 1ID 1, Role 1
“Anchor 7” → relabel as Anchor 2ID 2, Role 1Reconfigured from ID 7; printed IIC Error 3 on save but kept its config

Bench layout (metres): A0 (0, 0) at bottom-left, A1 (3, 0), A2 (1.5, 3), which is 3 m perpendicular from the A0–A1 midpoint. This gives an isosceles triangle.

First live results:

  • The full chain works, with 0 bad frames and all three anchors reporting at 10 Hz.
  • In the first walk-around, the fit error was 0.2–0.7 m, which is too high. Positions also landed outside the triangle (y < 0) when the tag was believed to be inside it.
  • Not yet resolved. Suspects:
    • a tag/anchor height difference
    • anchors not exactly at their coordinates, or a mirrored layout (A1 on the wrong side of A0)
    • people standing between tag and anchors
    • no calibration
  • Quick check: place the tag on A0 and it should read about (0, 0); place it at the A0–A1 midpoint and it should read about (1.5, 0).

11. Troubleshooting

SymptomLikely cause / fix
No COM port appears at allCharge-only cable; use a data cable
“USB Serial” with an error in Device ManagerCH340 driver missing
AT gets no replyWrong port (the “USB” port only answers some commands), or no CR+LF
Board freezes after AT+SETCFGYou’re on the “USB” port. Power-cycle the board and use “TTL”
Config reverts after power-offAT+SAVE never ran or never returned OK
Board doesn’t reset when you unplug itIt’s still powered another way, for example a 5 V/VBAT wire from another board. Remove all power
Tag PA2 silentNo anchor in range or powered, channel mismatch, or the PA2 wire isn’t connected (!scan)
A distance slot reads 0That anchor is unpowered, out of range, or blocked
Upload fails: “Could not open COMx… Access is denied”The serial monitor or visualiser is holding the port. Close it
Position far off, high fit errorAnchor coordinates wrong, mirrored layout, height difference, or obstruction

12. Lessons learned

  1. Measure; don’t trust the docs. The frame length (37 vs 35 bytes), which board outputs data, and which port configures the board were all different from what the vendor material suggested. A raw hex dump settled each question in minutes.
  2. The kit has two USB ports for a reason. Configuration goes through “TTL”. The other port looks like it works (it answers queries) until you try to save.
  3. Power-cycle properly. A board still fed through another board’s 5 V pin doesn’t reset when you unplug its USB, which makes a failed save look like a firmware bug.
  4. Never back-feed power. We had the XIAO’s VUSB wired into the BU03’s VBAT, then its 5 V pin, while both boards were also on USB. Only PA2 and GND are needed.
  5. Check every frame. The checksum and tail are cheap to verify, and they let the parser recover by itself after a corrupted byte.
  6. Native USB CDC on the ESP32-C3 can block. Set Serial.setTxTimeoutMs(0), or the firmware stalls when nothing is reading the port.
  7. Configure one board at a time and read it back with AT+GETCFG after the AT+SAVE reboot.

13. Next steps

  • Find the cause of the high fit error: check heights, layout orientation and anchor coordinates, then calibrate distances against a tape measure.
  • Add a 4th anchor at a different height and move to a 3D solve (or subtract barometer height).
  • Raspberry Pi 5 side: send !bin, read V2 frames over USB (/dev/ttyACM0) with the CRC check, then send MAVLink ODOMETRY #331 to PX4 (EKF2 external vision).
  • Drone power: run the tag from a regulated 5 V supply, and mount its antenna clear of the carbon frame.

14. References