Bluetooth: Central UART

The Central UART sample demonstrates how to use the Nordic UART Service (NUS) Client. It uses the NUS Client to send data back and forth between a UART connection and a Bluetooth LE connection, emulating a serial port over Bluetooth LE.

Overview

When connected, the sample forwards any data received on the RX pin of the UART 1 peripheral to the Bluetooth LE unit. On Nordic Semiconductor’s development kits, the UART 1 peripheral is typically gated through the SEGGER chip to a USB CDC virtual serial port.

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

Requirements

  • One of the following development boards:

    • nRF5340 PDK board (PCA10095) - see Working with nRF5340

    • nRF52840 DK board (PCA10056)

    • nRF52 DK board (PCA10040)

  • Another development board running a compatible application (see Bluetooth: Peripheral UART).

Building and running

This sample can be found under samples/bluetooth/central_uart in the nRF Connect SDK folder structure.

See Building and programming a sample application for information about how to build and program the application.

Testing

After programming the sample to your board, test it by performing the following steps:

  1. Connect the board to the computer using a USB cable. The board is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the board that runs this sample with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.

  3. Reset the board.

  4. Observe that the text “Starting NUS Client example” is printed on the COM listener running on the computer and the device starts scanning for Peripheral boards with NUS.

  5. Program the Bluetooth: Peripheral UART sample to the second board. See the documentation for that sample for detailed instructions.

  6. Observe that the boards connect. When service discovery is completed, the event logs are printed on the Central board’s terminal.

  7. Now you can send data between the two boards. To do so, type some characters in the terminal of one of the boards and hit Enter. Observe that the data is displayed on the UART on the other board.

  8. Disconnect the devices by, for example, pressing the Reset button on the Central board. Observe that the boards automatically reconnect and that it is again possible to send data between the two boards.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries:

  • include/zephyr/types.h

  • boards/arm/nrf*/board.h

  • Kernel Services:

    • include/kernel.h

  • Peripherals:

    • include/uart.h

  • Bluetooth:

    • include/bluetooth/bluetooth.h

    • include/bluetooth/gatt.h

    • include/bluetooth/hci.h

    • include/bluetooth/uuid.h