Bluetooth: nRF Distance Measurement with Bluetooth LE discovery
The nRF Distance Measurement sample demonstrates the functionality of the Distance Measurement (DM) subsystem. It shows how to use DM to measure the distance between devices. The Bluetooth® Direction and Distance Finding Service is running simultaneously.
Sample is configured to use Nordic’s SoftDevice link layer.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Build target |
---|---|---|---|
PCA10056 |
|
||
PCA10100 |
|
Overview
The sample initializes and performs distance measurements between devices. The procedure for distance measurement on both devices must be synchronized.
The synchronisation step has two goals:
Detect peers that support the ranging procedure.
Provide synchronisation for the ranging step.
This sample synchronizes devices using the scan and advertising facilities of the Bluetooth LE.
Anchoring occurs after the exchange of SCAN_REQ
and SCAN_RSP
packets.
Both devices act as an advertiser and a scanner.
Device B receives advertising from Device A and scans it.
Device A sends a scan response that contains Manufacturer Specific Data
.
This message contains the following fields:
Company Identifier Code.
Identifier indicating that the device supports distance measurement.
The access address used for measurement.
This scanner/advertiser interaction is used as a synchronisation point. After a configurable delay, Device A and Device B try to range each other.
If a Device acts as an advertiser in synchronization, it will act as the reflector in the ranging procedure.
If a Device acts as a scanner in synchronization, it will act as the initiator in the ranging procedure.
The synchronization will be performed cyclically.
Based on the SCAN_RSP
response, the device recognizes peers that support the distance measurement functionality within its coverage.
The addresses of these devices are stored in a list.
When a device does not respond within a certain period of time, it is removed from the list.
Also the last measurement results with the peers are stored in this list.
User interface
- LED 1:
Indicates the measured distance for MCPD (Multi-carrier phase difference) method. The shorter the distance, the brighter the light.
- LED 2:
Blinks every two seconds with the duty cycle set to 50% when the main loop is running and the device is advertising.
- LED 3:
On when connected.
Building and running
This sample can be found under samples/bluetooth/nrf_dm
in the nRF Connect SDK folder structure.
See Building and programming an application for information about how to build and program the application.
Testing
After programming the sample to development kits, test it by performing the following steps:
Connect to the kit that runs this sample with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.
Reset the kit.
Program the other development kit with the same sample and reset it.
Wait until the devices identify themselves and synchronize.
Observe that the received measurement results are output in the terminal window.
Sample output
The result should look similar to the following output:
The MCPD method:
*** Booting Zephyr OS build v2.6.99-ncs1 *** Starting Distance Measurement example I: SoftDevice Controller build revision: I: 3f 47 70 8e 81 95 4e 86 |?Gp...N. I: 9d d3 a2 95 88 f6 30 0a |......0. I: 7f 53 49 fd |.SI. I: HW Platform: Nordic Semiconductor (0x0002) I: HW Variant: nRF52x (0x0002) I: Firmware: Standard Bluetooth controller (0x00) Version 63.28743 Build 1318420878 I: Identity: C4:90:D5:4E:C2:20 (random) I: HCI: version 5.2 (0x0b) revision 0x125b, manufacturer 0x0059 I: LMP: version 5.2 (0x0b) subver 0x125b DM Bluetooth LE Synchronization initialization Measurement result: Addr DB:49:E9:62:DF:6D (random) Quality ok Distance estimates: mcpd: ifft=0.29 phase_slope=0.28 rssi_openspace=0.28 best=0.29 Measurement result: Addr CF:4E:38:D5:C0:ED (random) Quality ok Distance estimates: mcpd: ifft=0.94 phase_slope=1.10 rssi_openspace=0.22 best=0.94 Measurement result: Addr CF:4E:38:D5:C0:ED (random) Quality ok Distance estimates: mcpd: ifft=0.79 phase_slope=1.08 rssi_openspace=0.25 best=0.79
The RTT method:
*** Booting Zephyr OS build v2.6.99-ncs1 *** Starting Distance Measurement example I: SoftDevice Controller build revision: I: 3f 47 70 8e 81 95 4e 86 |?Gp...N. I: 9d d3 a2 95 88 f6 30 0a |......0. I: 7f 53 49 fd |.SI. I: HW Platform: Nordic Semiconductor (0x0002) I: HW Variant: nRF52x (0x0002) I: Firmware: Standard Bluetooth controller (0x00) Version 63.28743 Build 1318420878 I: Identity: C4:90:D5:4E:C2:20 (random) I: HCI: version 5.2 (0x0b) revision 0x125b, manufacturer 0x0059 I: LMP: version 5.2 (0x0b) subver 0x125b DM Bluetooth LE Synchronization initialization Measurement result: Addr CF:4E:38:D5:C0:ED (random) Quality ok Distance estimates: rtt: rtt=1.75 Measurement result: Addr CF:4E:38:D5:C0:ED (random) Quality ok Distance estimates: rtt: rtt=1.70 Measurement result: Addr DB:49:E9:62:DF:6D (random) Quality ok Distance estimates: rtt: rtt=2.75
Dependencies
This sample uses the following nRF Connect SDK subsystems:
This sample uses the following sdk-nrfxlib library:
In addition, it uses the following Zephyr libraries:
-
include/kernel.h
PWM:
drivers/pwm.h
include/sys/printk.h
include/sys/byteorder.h
include/random/rand32.h
-
include/bluetooth/bluetooth.h
include/bluetooth/scan.h
ext/hal/nordic/nrfx/hal/nrf_radio.h