Skip to content

BLE Advertising

Overview

The BLE Advertising sample demonstrates the BLE Advertising functionality using the adafruit_ble module.

When the code starts, nRF52840 Connect Kit will advertise with its name.

Tip

adafruit_ble is pre-built into CircuitPython as a frozen module, so that it can be imported in the code directly.

Requirements

Before you start, check that you have the required hardware and software:

Running the code

To run the code, complete the following steps:

  1. Connect nRF52840 Connect Kit to your computer using the USB-C Cable.
  2. Start Mu Editor, click Load to open code.py in the CIRCUITPY drive.
  3. Copy and paste the following code into code.py and click Save:

    CIRCUITPY/code.py
    from adafruit_ble import BLERadio
    from adafruit_ble.advertising import Advertisement
    
    ble = BLERadio()
    ble.name = "nRF52840 Connect Kit"
    advertisement = Advertisement()
    advertisement.complete_name = ble.name
    advertisement.connectable = True
    
    while True:
        print(advertisement)
        ble.start_advertising(advertisement)
        while not ble.connected:
            pass
        print("connected")
        while ble.connected:
            pass
        print("disconnected")
    
  4. Your code will run as soon as the file is done saving. Start the nRF Connect for Mobile app, scan the device and observe that the board is advertising with the Device Name nRF52840 Connect Kit.