Bluetooth: Nordic UART Service Central

This sample demonstrates how to use the Nordic UART Service (NUS) client with a device acting as a Bluetooth® LE central. It uses the NUS client service to send data back and forth between a UART connection and a Bluetooth LE connection, emulating a serial port over Bluetooth LE.

Requirements

The sample supports the following development kits:

The following board variants do not have DFU capabilities:

S145:

Hardware platform

PCA

Board target

nRF54L15 DK

PCA10156

bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice

nRF54L15 DK (emulating nRF54L10)

PCA10156

bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice

nRF54L15 DK (emulating nRF54L05)

PCA10156

bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice

nRF54LM20 DK

PCA10184

bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice

nRF54LS05 DK

PCA10214

bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice

nRF54LV10 DK

PCA10188

bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice

Overview

This sample scans for devices that advertise with the Nordic UART Service (NUS) UUID and initiates a connection when a device is found. When a device is connected, the sample starts the service discovery procedure.

When connected, the sample forwards any data received on the RX pin of the UART 0 peripheral to the Bluetooth LE unit.

In addition, the sample enables peer TX notifications to receive data from the peer.

User interface

LED 0:

Lit when the device is initialized.

LED 1:

Lit when a device is connected.

Button 3:

Disconnects from the peer when pressed.

Note

LEDs are only used in the normal UARTE configuration. In LPUARTE mode, LEDs are disabled to avoid interfering with the RX pin and to allow proper low-power operation.

In LPUARTE mode, LED 1 may appear lit even when no device is connected for some development kits, because it shares a pin with the RX signal; RX activity can toggle the LED, which is expected behavior.

Building and running

This sample can be found under samples/bluetooth/ble_nus_central/ in the Bare Metal folder structure.

For details on how to create, configure, and program a sample, see Getting Started with the samples.

Building and running with LPUARTE

The lpuarte.conf file configures the sample to use the LPUARTE driver for the NUS Client Service. This is useful for reducing the power consumption. Add the file to the build configuration in VS Code or as an extra argument to west: -DEXTRA_CONF_FILE="lpuarte.conf".

Testing

You can test the sample in two ways, depending on the selected UART configuration: the default UARTE configuration or the Low Power UARTE (LPUARTE) configuration.

Test the sample using the standard UARTE interface with two devices, one running this sample (Bluetooth: Nordic UART Service Central) and another running the Bluetooth: Nordic UART Service (NUS) sample. This is the default configuration.

  1. Compile and program the application.

  2. Connect the devices to the computer to access UART 0 and UART 1 on both devices. If you use development kits, UART 0 and 1 are forwarded as COM ports (Windows) or ttyACM devices (Linux) after you connect the development kits over USB. One instance is used for logging (if enabled with CONFIG_LOG), while the other is used for the NUS Client service.

  3. Connect to the kit with a terminal emulator (for example, the Serial Terminal app) for both UARTs on both development kits.

  4. Reset the kits.

  5. Observe that the device running the Bluetooth: Nordic UART Service Central sample is configured to connect to nRF_BM_NUS. You can configure this name using the SAMPLE_TARGET_PERIPHERAL_NAME Kconfig option. For information on how to do this, see Configuring Kconfig.

  6. Observe that the device running the Bluetooth: Nordic UART Service (NUS) sample is advertising under the default name nRF_BM_NUS. You can configure this name using the CONFIG_SAMPLE_BLE_DEVICE_NAME Kconfig option. For information on how to do this, see Configuring Kconfig.

  7. Observe that the text BLE NUS central example started. is printed on the COM listener connected to the device running the Bluetooth: Nordic UART Service Central sample.

  8. Observe that the text BLE NUS sample initialized is printed on the COM listener connected to the device running the Bluetooth: Nordic UART Service (NUS) sample.

  9. Write a text in the COM listener running on the computer and press Enter.

  10. Observe that the text is displayed in the second COM listener running on the computer.