
Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython
Created by Brent Rubell
Last updated on 2021-03-26 11:44:36 PM EDT

2
3
3
7
7
7
9
9
9
11
11
12
12
13
15
16
16
18
18
18
18
20
23
27
28
Guide Contents
Guide Contents
Overview
Parts
Bluetooth Low Energy Basics
Bluetooth Terms
Making a Bluetooth Connection
Assembly
Adafruit Feather RP2040 Wiring
Raspberry Pi Pico RP2040 Wiring
Upgrade RP2040 AirLift Firmware
Upload Serial Passthrough Code
Download NINA Firmware
Flash AirLift using Web Serial ESPTool
Enable Chrome's Web Serial API
Flash AirLift using esptool.py
Burning nina-fw with esptool
Verifying the Upgraded Firmware Version
Code Usage
Install CircuitPython Libraries
Install Adafruit Bluefruit LE Connect App
Code Setup
Code Usage
NeoPixel Color
Adapting Existing CircuitPython BLE Code for AirLift BLE
BLE Technical Details
© Adafruit Industries https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython Page 2 of 29

Overview
Add Bluetooth Low Energy (BLE) connectivity to your Raspberry Pi RP2040 project by adding an Adafruit
AirLift ESP32 co-processor. The AirLift's ESP32 module can be placed into either a WiFi mode (we've
published a guide about using the AirLift's WiFi mode with Pico here (https://adafru.it/RlC)) or BLE mode,
giving you the option of adding two different methods of wireless connectivity to your RP2040 project.
This guide will cover getting started using BLE to connect an RP2040 board with the Bluefruit LE Connect
App along with examples for a UART echo server and wirelessly changing the color of a NeoPixel RGB
LED.
A few notes before we begin:
You can not use the WiFi and BLE mode on the Adafruit AirLift simultaneously , so select your
transport
wisely
(https://adafru.it/Cio).
CircuitPython's AirLift support only provides BLE peripheral support , BLE central support is under
development. This means you can not connect the RP2040 to BLE devices such as heart rate
monitors or thermometers, but you can make the RP2040 act as a BLE peripheral.
Parts
© Adafruit Industries https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython Page 3 of 29

Adafruit Feather RP2040
A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip
we thought "this chip is going to be awesome when we give it the Feather...
Out of Stock
Out of
Stock
© Adafruit Industries https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython Page 4 of 29

Raspberry Pi Pico RP2040
The Raspberry Pi foundation changed single-board computing when they released the Raspberry Pi
computer, now they're ready to...
Out of Stock
Adafruit AirLift FeatherWing – ESP32 WiFi Co-Processor
Give your Feather project a lift with the Adafruit AirLift FeatherWing - a FeatherWing that lets you use the
powerful ESP32 as a WiFi co-processor. You probably have your...
$12.95
In Stock
Out of
Stock
Add to Cart
© Adafruit Industries https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython Page 5 of 29

Adafruit AirLift – ESP32 WiFi Co-Processor Breakout Board
Give your plain ol' microcontroller project a lift with the Adafruit AirLift - a breakout board that lets you use
the powerful ESP32 as a WiFi co-processor. You probably...
$9.95
In Stock
1 x FeatherWing Doubler
FeatherWing Doubler - Prototyping Add-on For All Feather Boards
1 x USB-C Cable
USB-C Cable for RP2040 Feather
1 x USB Cable
USB cable - USB A to Micro-B - 3 foot long
1 x Breadboard
Full sized breadboard
1 x Breadboarding Wires
Breadboarding wire bundle
Add to Cart
Add to Cart
Add to Cart
Add to Cart
Out of
Stock
Add to Cart
© Adafruit Industries https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython Page 6 of 29

Bluetooth Low Energy Basics
The nRF52840 uses Bluetooth Low Energy, or BLE. BLE is a wireless communication protocol used by
many devices, including mobile devices. You'll be able to communicate with your nRF52840 board using
your mobile phone!
There's a few terms and concepts commonly used in BLE with which you may want to familiarise yourself.
This will help you understand what your code is doing when you're using CircuitPython and BLE.
The major concepts can be broken down into two categories: connection set up and communication. The
first deals with setting up connections between devices, such as between your mobile phone and the
nRF52840 board. The second deals with communication between the devices once they are connected.
Bluetooth Terms
Central - The host computer. This is often a mobile device such as a phone or tablet, or it could be a
desktop or laptop.
Peripheral - The connected device. Examples of peripherals are: heart rate monitor, smart watch, or
fitness tracker. The CircuitPython code we have so far is designed to make the Adafruit nRF52840
devices work as peripherals.
Advertising - Information sent by the peripheral during connection set up. When a device advertises,
it is transmitting the name of the device and describing its capabilities. The central looks for an
advertising peripheral to connect to, and uses that information to determine what the peripheral is
capable of.
Service - A function the peripheral provides. The peripheral advertises its services. A really common
service that we use is the UART service, which acts like a hardware UART and is a way of
bidirectionally sending information to and from devices.
Packet - Data transmitted by a device. BLE devices and host computers transmit and receive data in
small bursts called packets.
Making a Bluetooth Connection
To use these terms in the context of connecting to your Adafruit nRF52840:
You run CircuitPython code that makes your board act as a peripheral by advertising its name and
the services it's capable of.
You start up Adafruit's Bluefruit LE Connect app on an Android or iOS device in central mode, that
device becomes the central, and begins listening for the peripheral.
You set up the connection between the nRF52840 peripheral and the Bluefruit LE Connect app, and
the app discovers the details about the services that the peripheral is capable of.
Once this connection is made, you can use CircuitPython code to read packets sent from the
Bluefruit LE Connect app to your nRF52840 board. For example, you can receive data describing
screen button presses or RGB color values.
© Adafruit Industries https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython Page 7 of 29

Now that you have a general idea of basic BLE terms and concepts, it's time to install the Bluefruit LE
Connect application, and run some CircuitPython demos!
© Adafruit Industries https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython Page 8 of 29

Assembly
Adafruit sells Airlift hardware in multiple (https://adafru.it/JDc) form (https://adafru.it/EDW)
factors (https://adafru.it/RlD) in order to be compatible with many microcontroller boards. While each
microcontroller board and airlift hardware combination has its own wiring scheme, we suggest either
using the wiring below or referencing the AirLift product guide.
Adafruit Feather RP2040 Wiring
To use the AirLift FeatherWing with BLE, you will need to solder the three jumpers closed on the bottom
of the AirLift FeatherWing:
After soldering the jumpers closed, we suggest using the
FeatherWing Doubler (https://adafru.it/kBi) to connect a
Feather RP2040 and an AirLift FeatherWing side-by-side.
Raspberry Pi Pico RP2040 Wiring
If you're using a Raspberry Pi Pico RP2040, make the following connections between the Pico RP2040
and an Adafruit AirLift breakout.
You MUST use the Pico's VSYS pin for powering the AirLift Breakout.
© Adafruit Industries https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython Page 9 of 29