Exercise 1

Testing a Bluetooth LE connection

In this exercise, we will be using the Bluetooth: Peripheral LBS sample, running on your Nordic board, to establish a Bluetooth LE connection between the board and your smartphone. The Peripheral LBS sample makes the Nordic board act as a Bluetooth LE peripheral, advertising its presence to your smartphone, which will act as the central.

When connected, the Nordic board will act as a GATT Server, exposing the LED Button Service (LBS) to your smartphone, the GATT Client. LBS has two characteristics, Button and LED. The GATT Client, in our case a smartphone, can write and read to these characteristics to control the LEDs and read the status of the button on the Nordic board. The Nordic board acts as the GATT server here.

For all exercises in this course, when building the sample application, you can use any of the boards listed under Hardware Requirements on the course page and their corresponding build targets.

Note

This course builds on the nRF Connect SDK Fundamentals course and focuses on Bluetooth Low Energy. You need to read Lesson 1 in the nRF Connect SDK Fundamentals to learn how to install nRF Connect SDK on your machine and build applications. Furthermore, completing the nRF Connect SDK Fundamentals course is strongly advised as it provides a comprehensive understanding of the nRF Connect SDK.
The exercises in this course assume you have a basic understanding of the nRF Connect SDK.

Exercise steps

1. Prepare the project and build and flash it to your board

1.1 Clone the GitHub repository for this course.

Copy the link to the repository and use VS Code’s Command Palette to clone the repository.

Clone the course’s GitHub repository in VS Code

1.2 In the nRF Connect extension in VS Code, select Open an existing application, and open the base code for this exercise, found in bt-fund/lesson1/blefund_less1_exer1.

1.3 Add a build configuration and select whichever board you are using.

1.4 Build and flash the application to your device.

If this was successful, you should notice LED1 blinking on your device.

2. Use your smartphone to test the application

2.1 Download nRF Connect for Mobile from your app store, and launch it on your smartphone.

2.2 Turn on Bluetooth and Location services on your smartphone.

3. (optional) Open a terminal to view the log output from the application

The UART peripheral is gated through the SEGGER debugger/programmer chip (i.e interface MCU) to a USB-CDC virtual serial port that you can connect directly to your PC.

Connect to the COM port of your DK in VS Code by expanding your device under Connected Devices and selecting the COM port for the device. The number for the COM port may differ on your PC.

Note

When using the nRF5340 DK, you will have two COM ports, one for the application core and one for the network core. We want to view the output from the application core.

Use the default settings 115200 8n1 rtscrs:off. Then reset the device to see the full log message.

If the advertising was successful, your log output should look like this

LED1 should also be blinking, indicating that the device is advertising.

4. Establish a connection to your Nordic board.

Android

4.1 From the nRF Connect for Mobile app, press the SCAN button. Your smartphone will now act as a central device, scanning for any Bluetooth LE devices that are advertising in its presence.

Android

4.2 Several Bluetooth-enabled devices surrounding you will start appearing.

Choose the one called Nordic_LBS and press CONNECT.

Android

4.3 You will know a connection has been established when LED2 on your device is on.

5. Observe the interface on the app.

This image has an empty alt attribute; its file name is less1_exer1_observeInterface-515x1024.png
Android
  1. You can check that you are connected to the correct device
  2. The services available on this device. Here we see the Nordic LED Button Service, since this is the sample we have flashed to the device.
  3. Inside that Service, there is a Characteristic called “Button“, or “Blinky Button State“. It reflects the status of button 1 on the Nordic board. Hence, its properties are “Read” and “Notify”. “Notify” refers to the case when the peripheral initiates the connection. More on notifications in subsequent lessons.
  4. Inside that same Service, there is also another Characteristic called “LED” or “Blinky LED State“. It allows you to toggle LED 3 on the Nordic board. Hence, its property is “WRITE”.

6. Read the status of button 1 using the “Button” Characteristic.

This image has an empty alt attribute; its file name is image-180.png
Android
  1. To receive and view the button 1 status, you need to view the “Value” tab in your “Button” Characteristic. This is done by pressing the single down-arrow icon
  2. To enable notifications regarding this Characteristic to be pushed to your app, you need to press the icon with several down-arrows

Now, you should be able to see the status of button 1 as released.

This image has an empty alt attribute; its file name is less1_exer1_step_6_2-1024x694.png
Android

7. Observe the status of button 1.

7.1 Press button 1 on your Nordic board

7.2 Observe the value shown below changes to “Button pressed”.

This image has an empty alt attribute; its file name is less1_exer1_button_pressed-1024x701.png
Android

8. Toggle LED 3.

8.1 Press the up arrow icon next to the LED characteristic.

This image has an empty alt attribute; its file name is less1_exer1_toggle_led_uparrow-1024x290.png
Android

8.2 Write a value to the LED characteristic to turn it on

Select ON and then SEND to turn the LED on.

Android

8.3 Observe that LED3 is turned on.

8.4 Turn off the LED by selecting OFF.

iOS

4.1 From the nRF Connect for Mobile app, press the Play icon, in the upper right-hand corner. Your smartphone will now act as a central device, scanning for any Bluetooth LE devices that are advertising in its presence.

iOS

4.2 Several Bluetooth-enabled devices surrounding you will start appearing.

Choose the one called Nordic_LBS and press Connect.

iOS

4.3 You will know a connection has been established when LED2 on your device is on.

5. Observe the interface on the app.

Go to the window called Client.

iOS
  1. You can check that you are connected to the correct device
  2. The services available on this device. Here we see the Nordic LED Button Service, since this is the sample we have flashed to the device.
  3. Inside that Service, there is a Characteristic called “Button“, or “Blinky Button State“. It reflects the status of button 1 on the Nordic board. Hence, its properties are “Read” and “Notify”. “Notify” refers to the case when the peripheral initiates the connection. More on notifications in subsequent lessons.
  4. Inside that same Service, there is also another Characteristic called “LED” or “Blinky LED State“. It allows you to toggle LED 3 on the Nordic board. Hence, its property is “WRITE”.

6. Read the status of button 1 using the “Button” Characteristic.

iOS
  1. To receive and view the button 1 status, you need to view the “Value” tab in your “Button” Characteristic. This is done by pressing the down-arrow icon.
  2. To enable notifications regarding this Characteristic to be pushed to your app, you need to press the icon with the underline arrow.

Now, you should be able to see the status of button 1 as released.

iOS

7. Observe the status of button 1.

7.1 Press button 1 on your Nordic board

7.2 Observe the value shown below changes to “Button pressed”.

iOS

8. Toggle LED 3.

8.1 Press the up arrow icon next to the LED characteristic.

iOS

8.2 Write a value to the LED characteristic to turn it on

Select Bool, then switch the value to True and then select Write to send the value.

iOS

8.3 Observe that LED3 is turned on.

8.4 Turn off the LED by selecting OFF.

Register an account
Already have an account? Log in
(All fields are required unless specified optional)

  • 8 or more characters
  • Upper and lower case letters
  • At least one number or special character

Forgot your password?
Enter the email associated with your account, and we will send you a link to reset your password.