Getting Started with UWB Using NXP Trimension® SR250 - Part 3: Trying Out a UWB Distancing Demo (Japanese Blog) Introduction
In the second part, we will cover the setup method for the SR250 evaluation board ( SR250UWBSHIELD ), specifically A. PnP (Plug and Play) Root and B.This document explains the two methods for setting up the Zephyr SDK root environment.
This time, we will finally run the UWB ranging demonstration. We will continue to explain the demonstration process using two separate routes, A and B. If you haven't finished setting up your environment yet, please check out Part 2 first.
UWB distance measurement with a smartphone will be handled using Route B. First, we will introduce how to try using a pre-built binary without building with the Zephyr SDK, and then we will explain how to build the Nearby demo with the Zephyr SDK. With the pre-built version, building the Zephyr SDK is not necessary, and writing the firmware to the RW612 can be done in the same way as the procedure explained in the second part on the PnP route.
1st
Basics of UWB and an overview of the SR250
2nd time
Setting up the SR250 evaluation board (SR250UWBSHIELD)
Third installment (this article)
Let's try UWB ranging.
4th
Try out UWB radar.
The overall picture of the demonstration
UWB ranging requires a communication partner device. In this demonstration,
One board acts as the Controller , handling scheduling and timing control for the UWB session, while simultaneously acting as the Initiator to start distance measurement.
The other board acts as the Controlleree , following the Controller's instructions, and as the Responder , it returns response packets.
Instead of using two boards, you can also use a UWB-compatible smartphone as the other device (see Route B).
For those using the "A. PnP route," please click here.
For those using the "B. Zephyr SDK route," please click here.
A. PnP Route
GitHub: SR250 UWB Plug-and-Play Application
Summary of the Simple_demos folder
The Simple_demos\ folder in the PnP demo repository contains the following files:
file name
Content
UartInterface.py
A module that summarizes the basic processing of serial communication. This is used in common across all demo scripts.
UwbConfig.py
A module for configuring UWB session parameters (channel, timing, etc.). Similar to the calibration demo written using the Zephyr SDK root in the second session, the device calibration values are also set in this file.
Various demo scripts
demo_ranging.py This is the main demo, demonstrating distance measurement between two boards using DS-TWR (Double-Sided Two-Way Ranging). demo_radar_ocpd.py : On-Chip Presence Detection (OCPD) demo. demo_radar_raw.py : A demonstration of obtaining raw data from CIR (Channel Impulse Response). *Details about the radar-related (ocpd/radar_raw) demo will be covered in the next article.
viki_SR250.pl
A Perl script for decoding UCI packets. Used for detailed log analysis. Perl must be installed to use this feature. On Windows, install Strawberry Perl or a similar program, then run perl -v in the command prompt to confirm that the Perl version is displayed (that Perl is installed and the PATH is set).
This time, let's try demo_ranging.py demo for distance measurement.
Check COM port
Connect the board to your PC's USB port and check the COM port number. Please refer to Part 2 for instructions on how to check the port number.
Launching Ranging Demo
As with the second installment, we will be using the command prompt on a Windows PC. Open two command prompt windows and replace the COM port number in each command with the COM port number of your board before executing them. The baud rate will be set automatically by the script, so you do not need to specify it.
Controller side (e.g., COM3):
python demo_ranging.py COM3 controller
Controlee side (e.g., COM4):
python demo_ranging.py COM4 controlee
Checking the execution log
When you run the script, logs will start flowing to the terminal. You can stop it with Ctrl+C.
The log may appear filled with hexadecimal strings, making it difficult to tell at first glance whether distance measurement is working or not. These are the raw data of UCI packets exchanged between the UWB device and the host. UCI will be explained in the next section.
What is UCI (UWB Command Interface) ?
UCI is a standard command interface between a host and a UWB device, developed by the FiRa Consortium. It consists of three types of messages: commands, responses, and notifications.
The Python script we just ran sends UCI commands to the board in the background and receives UCI responses and notifications from the board. The distance measurement results are returned as UCI notifications, but the default Python script does not decode them, and the sent and received UCI packets are displayed as raw hexadecimal data.
How to read UCI logs
First, let's look at a UCI Notification that includes distance measurement results as an example.
NXPUCIR <= 62 00 00 38 30 00 00 00 01 00 00 80 00 c8 00 00 00 01 00 00 00 00 00 00 00 00 00 00 01 11 11 00 00 30 00 85 f9 00 09 fc 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00
UCI packets read multi-byte values in little-endian format. In this example, the first four bytes are the header.
62 00 00 38 This indicates that it is a notification, the message type, and the payload length (0x38 = 56 bytes).
30 00 00 00 This is the session sequence number.
01 00 00 80 This is the session handle that identifies the UWB session.
c8 00 00 00 : Indicates a distance measurement interval of 0x000000C8 = 200 , 200 ms.
01 Two-Way Ranging (TWR) is set as the distance measurement method.
01 This indicates that this notification contains one distance measurement result.
In the following range measurement result field, 11 11 is the short MAC address of the other device, followed by 00 which indicates successful range measurement, and then 00 which indicates line of sight (LoS). Finally, 30 00 is the distance field. When read in little-endian format, it becomes 0x0030 = 48 , so the range measurement result for this packet is 48 cm .
If you only want to check the distance measurement results, as in this case, you can also directly add a function to extract the distance measurement results into your Python script, instead of using viki_SR250.pl which decodes the entire UCI packet as explained in the next section. For example, add the following callback function to demo_ranging.py . ntf[0] is the distance measurement status, and ntf[2] and ntf[3] are the distance data.
def extract_ranging(id, ntf):
if ntf[0] == 0:
distance = int(ntf[2] + (ntf[3] << 8))
print(f"Device {id}: dist = {distance} cm")
Next, we pass extract_ranging as a keyword argument to the receiving thread demo_ranging.py .
read_thread = Thread(
target=UartIntf.read_from_serial_port,
kwargs={"extract_ranging": extract_ranging}
)
read_from_serial_port() The received distance measurement notification is passed to this function, so each time the distance measurement is successful, the distance will be displayed in real time, for example, Device 0: dist = 48 cm .
viki_SR250.pl Decoded by
Use viki_SR250.pl if you want to analyze the entire UCI packet in detail. viki_SR250.pl decodes each field of the UCI packet, allowing you to see session state transitions and details of each packet. Perl must be installed to use this.
python -u demo_ranging.py COM3 controller | perl viki_SR250.pl
Each field of the UCI is decoded, allowing you to view session state transitions and details of each packet.
B. Zephyr SDK Route
Standard distance measurement demo: Controller and Controlleree demo
The distance measurement demo using the Zephyr SDK also works in a Controller/Controlee configuration. Different firmware is built and written to each of the two boards.
First, connect only one board and build and flash the Controller firmware.
west build -b frdm_rw612 -p auto uwbiot-top\demos\common\demo_ranging_controller\zephyr west flash
💡 If you have changed build options since the previous build, you may encounter errors. Try deleting the sr250-uwbiot-zephyr\build folder or try a pristine build first.
Remove the board with the Controller demo written to it, connect the other board, and then build and write the Controlee firmware.
west build -b frdm_rw612 -p auto uwbiot-top\demos\common\demo_ranging_controlee\zephyr west flash
Reconnect the board with the Controller demo written to it, and start two terminal programs. With the settings at 3Mbps, connect the respective COM port numbers, and the distance measurement between the boards will begin as shown in the log below.
Measuring distance from a smartphone: Nearby demo
Route B uses BLE as the connection starting point, enabling distance measurement with UWB-compatible smartphones. The application name used in this demo is demo_nearby_interaction . The name "Nearby" comes from Apple's " Nearby Interaction " framework for iOS and Android's " Nearby " API. These are APIs provided by OS vendors for short-range interactions using UWB.
In the Nearby demo, instead of communicating via UWB from the start, BLE is first used to discover and connect to the other party and exchange information necessary for UWB ranging. This is because smartphone UWB is designed to start the ranging session only after these preliminary connections and settings are completed. Also, since BLE is more power-efficient than UWB for discovering and connecting to the other party, power consumption can be reduced by not running UWB constantly and only starting UWB ranging when necessary. The ranging starts in the following order:
Connect the SR250 board and your smartphone using BLE.
Session information and configuration information necessary for UWB ranging are exchanged via BLE, ensuring that the ranging conditions are consistent for both parties.
Based on the exchanged information, a UWB session will be started, and DS-TWR distance measurement will be performed using UWB.
In short, BLE is used for connection and preparing for UWB ranging, while the actual distance measurement is performed using UWB.
The Nearby demo can be tried with just one board set and a UWB-compatible smartphone. We will explain two methods: an easy way to try it with a pre-built binary, and how to build an application using the Zephyr SDK if needed.
Method 1: Try with a pre-built binary.
You can easily try out the Nearby demo using pre-built binaries instead of building with the Zephyr SDK. This is a convenient method if you just want to check if it works.
For instructions and required files, please refer to NXP Application Code Hub: UWB Nearby Interaction with phones on GitHub. Download and extract the UWB Trimension SR250 Nearby Interaction Demo application package from the repository, and run program_FRDM-RW612.bat to flash the firmware. The flashing operation follows the same procedure as "Step 1: Flashing RW612 PnP firmware" explained in Part 2 of the PnP route; enter ISP mode using the buttons and then execute the batch file.
Method 2: Build with Zephyr SDK
To modify the source code or examine the application's behavior in more detail, build the Nearby demo with the Zephyr SDK.
Nearby Interaction firmware build and flashing:
west build -b frdm_rw612 -p auto uwbiot-top\demos\SR2XX\demo_nearby_interaction\zephyr west flash
In both methods, after writing the firmware, connecting with terminal software will output logs similar to the following, and the device will enter BLE advertising mode. When you launch the smartphone app, the BLE connection will be established, and UWB distance measurement logs will begin to flow.
Smartphone app
On the smartphone side, the partner is You can use MK UWB Connect , created by MobileKnowledge . It's available from Google Play for Android smartphones and from the App Store for iPhones. The app includes demo modes such as Range, Distance Alert, and Tracker, allowing you to try out distance measurement with the SR250 Nearby Interaction accessory.
On iPhones, you can use NXP Trimensions AR in addition to MK UWB Connect . Both NXP Trimensions AR and the MK UWB Connect Tracker demo use UWB ranging and ARKit to display the distance and positional relationship with SR250 accessories on the AR screen. Because ARKit is used, the app will guide you through attitude calibration upon startup. Please move your smartphone according to the on-screen instructions.
Android : MK UWB Connect
iPhone : MK UWB Connect or NXP Trimensions AR
Compatible devices : UWB-compatible smartphones
iPhone : iPhone 11 and later (excluding iPhone SE (3rd generation), iPhone 16e and 17e)
Android : Google Pixel Pro series, Samsung Galaxy S21+ to S26 series, AQUOS R series R8 generation and later , etc.
For other compatible devices, please refer to the list of UWB-compatible mobile devices .
You can view the screen when running MK UWB Connect at NXP Application Code Hub: UWB Nearby Interaction with phones .
When you run NXP Trimensions AR on your iPhone, the following screen will display the distance and direction to the SR250 board.
summary
This time, we actually ran the UWB ranging demonstration using two different routes.
Route A (PnP) : You can easily check UWB distance measurement by simply running a Python script. Using viki_SR250.pl , you can also perform detailed analysis of UCI logs.
Route B (Zephyr SDK) : Using the pre-built binary allows for distance measurement with a smartphone using BLE without building, while building with the Zephyr SDK allows for modification of the source code. On the smartphone side, use the MK UWB Connect app, which is compatible with Android and iPhone.
Next time, we'll try out another feature of the SR250: an on-chip presence detection (OCPD) demonstration using UWB radar .
Reference links
Trimension SR250 Product Page (Japanese)
SR250 Evaluation Board (TRIMENSION-SR250)
SR250 UCI Specification (UM12508)
SR250 UWBIoT for Zephyr OS (GitHub)
Making UWB Plug and Play with Trimension SR250 (Training Video)
=========================
We are currently unable to respond to comments left in the "Comment" section of this post. We apologize for the inconvenience, but please refer to " Technical Questions to NXP - How to Contact Us( Japanese Blog) " when making an inquiry. (If you are already an NXP distributor or have a relationship with NXP, you may ask your representative directly.) In the third session, we will finally run the UWB distance measurement demo using the environment we built in the second session. In addition to measuring distance between boards using two SR250 UWB SHIELDs, we will also try measuring distance with a UWB-compatible smartphone connected via BLE using the Zephyr SDK route. We will explain both the PnP route and the Zephyr SDK route.
(Estimated time: as little as 10 minutes if the environment is already set up) Japanese Blog
View full article