Bluetooth: Nordic UART Service (NUS)

This sample demonstrates how to use the Nordic UART Service (NUS). It uses the NUS 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:

S115:

Hardware platform

PCA

Board target

nRF54L15 DK

PCA10156

bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice

nRF54L15 DK (emulating nRF54L10)

PCA10156

bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice

nRF54L15 DK (emulating nRF54L05)

PCA10156

bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice

nRF54LM20 DK

PCA10184

bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice

nRF54LS05 DK

PCA10214

bm_nrf54ls05dk/nrf54ls05b/cpuapp/s115_softdevice

nRF54LV10 DK

PCA10188

bm_nrf54lv10dk/nrf54lv10a/cpuapp/s115_softdevice

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

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

Any data sent from the Bluetooth LE unit is sent out of the UART 0 peripheral’s TX pin.

User interface

LED 0:

Lit when the device is initialized.

LED 1:

Lit when a device is connected.

Note

LEDs are only used in the normal UARTE configuration. In LPUARTE mode, LEDs are disabled to allow proper low-power operation.

In LPUARTE mode, the LEDs may appear on even when no device is connected for some development kits because it shares pins with the LPUARTE; RX or TX activity can toggle the LED, which is expected behavior.

Building and running

This sample can be found under samples/bluetooth/ble_nus/ 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 Service. This is useful for reducing the power consumption. The file must be added to the build configuration is VS Code or as an extra argument to west: -DEXTRA_CONF_FILE="lpuarte.conf".

Testing

The sample can be tested 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 a single device and one phone. This is the default configuration.

  1. Compile and program the application.

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

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

  4. Reset the kit.

  5. Observe that the text BLE NUS sample initialized is printed on the COM listener running on the computer.

  6. Observe that the Advertising as nRF_BM_NUS message is printed. 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. Connect to your device using the nRF Toolbox mobile application with the Universal Asynchronous Receiver/Transmitter (UART) service. If the device is not advertising, reset the board with the Reset Board option in Visual Studio Code or by pressing the reset button on the development kit.

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

  9. Write a text in the terminal on the mobile phone and press Send. Observe that the text is displayed in the second COM listener running on the computer.