Before continuing, ensure your AirLift's firmware is version 1.7.1 or higher for BLE to work.

Install CircuitPython Libraries

Make sure you are running the latest version of Adafruit CircuitPython for your board; you'll need 6.0.0 or later.

Next, you'll need to install the necessary libraries to use the hardware and BLE. Carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle.  Our CircuitPython starter guide has a great page on how to use the library bundle.

Install these libraries from the bundle:

  • adafruit_airlift
  • adafruit_ble
  • adafruit_esp32spi
  • adafruit_bus_device
  • adafruit_bluefruit_connect
  • adafruit_requests.mpy
  • neopixel.mpy

Before continuing make sure your board's lib folder or root filesystem has the files and folders listed above copied over.

Install Adafruit Bluefruit LE Connect App

The Adafruit Bluefruit LE Connect iOS and Android apps allow you to connect to BLE peripherals. Follow the instructions in the Bluefruit LE Connect Guide to download and install the app on your phone or tablet.

Code Setup

Copy the code below to the code.py file on your CIRCUITPY drive. If you're using an AirLift Breakout, you will need to modify the code by commenting out the default pin settings and uncommenting the code for the AirLift breakout.

import board
from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService
from adafruit_airlift.esp32 import ESP32

# If you are using an AirLift FeatherWing or AirLift Bitsy Add-On,
# use the pin settings below:
esp32 = ESP32(
    reset=board.D12,
    gpio0=board.D10,
    busy=board.D11,
    chip_select=board.D13,
    tx=board.TX,
    rx=board.RX,
)

# If you are using an AirLift Breakout, comment out the DEFAULT lines
# above and uncomment the lines below:
# esp32 = ESP32(
#    reset=board.GP16,
#    gpio0=board.GP9,
#    busy=board.GP14,
#    chip_select=board.GP13,
#    tx=board.GP0,
#    rx=board.GP1,
# )


adapter = esp32.start_bluetooth()

ble = BLERadio(adapter)
uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)

while True:
    ble.start_advertising(advertisement)
    print("waiting to connect")
    while not ble.connected:
        pass
    print("connected: trying to read input")
    while ble.connected:
        # Returns b'' if nothing was read.
        one_byte = uart.read(1)
        if one_byte:
            print(one_byte)
            uart.write(one_byte)

Your CIRCUITPY file-system should look like the following:

Code Usage

Start the Bluefruit LE Connect App on your phone or tablet. You should see a CIRCUITPY device available to connect to. Tap the Connect button.

You'll then see a list of Bluefruit Connect functions ("modules"). Choose the UART module.

On the UART module page, you can type a string and press Send. You'll see that string entered, and then see it echoed back (echoing is in gray).

That's it! 

This guide was first published on Mar 26, 2021. It was last updated on 2021-03-31 13:20:28 -0400.

This page (Code Usage) was last updated on Apr 21, 2021.

Text editor powered by tinymce.