Bluetooth: Peripheral LBS

The peripheral LBS sample demonstrates how to use the LED Button Service (LBS).

Overview

When connected, the sample sends the state of Button 1 on the development kit to the connected device, such as a phone or tablet. The mobile application on the device can display the received button state and can control the state of LED 3 on the development kit.

Alternatively, you can use this sample to control the color of RGB LED on the nRF52840 Dongle.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp

nrf5340dk_nrf5340_cpuappns

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nRF52840 DK (emulating nRF52811)

PCA10056

nrf52840dk_nrf52811

nrf52840dk_nrf52811

nRF52833 DK

PCA10010

nrf52833dk_nrf52833

nrf52833dk_nrf52833

nRF52833 DK (emulating nRF52820)

PCA10100

nrf52833dk_nrf52820

nrf52833dk_nrf52820

nRF52 DK

PCA10040

nrf52dk_nrf52832

nrf52dk_nrf52832

nRF52 DK (emulating nRF52810)

PCA10040

nrf52dk_nrf52810

nrf52dk_nrf52810

nRF52840 Dongle

PCA10059

nrf52840dongle_nrf52840

nrf52840dongle_nrf52840

The sample also requires a phone or tablet running a compatible application, for example nRF Connect for Mobile, nRF Blinky, or nRF Toolbox.

User interface

For nRF52840 Dongle:

RGB LED:
Red:
  • On when connected.

Green:
  • Controlled remotely from the connected device.

Button 1:
  • Sends a notification with the button state: “pressed” or “released”.

For development kits:

LED 1:
  • When the main loop is running (device is advertising), blinks with a period of 2 seconds, duty cycle 50%.

LED 2:
  • On when connected.

LED 3:
  • Controlled remotely from the connected device.

Button 1:
  • Sends a notification with the button state: “pressed” or “released”.

Building and Running

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

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

Minimal Build

The sample can be built with a minimum configuration as a demonstration of how to reduce code size and RAM usage.

west build samples/bluetooth/peripheral_lbs -- -DCONF_FILE='prj_minimal.conf'

Testing

After programming the sample to your dongle or development kit, test it by performing the following steps. This testing procedure assumes that you are using nRF Connect for Mobile.

  1. Power on your development kit or plug in your dongle.

  2. Connect to the device from nRF Connect (the device is advertising as “Nordic_Blinky”).

  3. Observe that the services of the connected device are shown.

  4. In “Nordic LED Button Service”, click the Play button for the “Button” characteristic.

  5. Press Button 1 either on the dongle or on the development kit.

  6. Observe that notifications with the following values are received:

    • 00 when Button 1 is released,

    • 01 when Button 1 is pressed.

  7. Control the color of RGB LED on the dongle or status of LED 3 on the kit by writing the following values to the “LED” characteristic in the “Nordic LED Button Service”:

    • 00 to switch the LED off on the kit or turn on the red RGB LED on the dongle.

    • 01 to switch the LED on on the kit or turn on the green RGB LED on the dongle.

  8. Observe that RGB LED on the dongle or LED 3 on the kit corresponds to the value of the “LED” characteristic.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries:

  • include/zephyr/types.h

  • lib/libc/minimal/include/errno.h

  • include/sys/printk.h

  • include/sys/byteorder.h

  • GPIO Interface

  • Bluetooth:

    • include/bluetooth/bluetooth.h

    • include/bluetooth/hci.h

    • include/bluetooth/conn.h

    • include/bluetooth/uuid.h

    • include/bluetooth/gatt.h