# Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/101/020/medium800/raspberry_pi_micropython___circuitpython_Blinka_Bluefruit_Ouroboros_Dark.png?1616702127)

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&nbsp; (we've published a [guide about using the AirLift's WiFi mode with Pico here](https://learn.adafruit.com/quickstart-rp2040-pico-with-wifi-and-circuitpython)) 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://learn.adafruit.com/alltheiot-transports/).
- **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.

Info: This tutorial uses the mobile Adafruit Bluefruit Connect app on iOS and Android. To run the examples, your device must be compatible with one of these two apps - see the Apple app store or Google Play for compatibility.

## Parts
### Adafruit Feather RP2040

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
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 Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

In Stock
[Buy Now](https://www.adafruit.com/product/4884)
[Related Guides to the Product](https://learn.adafruit.com/products/4884/guides)
![Angled shot of black rectangular microcontroller "Feather RP2040"](https://cdn-shop.adafruit.com/640x480/4884-04.jpg)

### Raspberry Pi Pico RP2040

[Raspberry Pi Pico RP2040](https://www.adafruit.com/product/4864)
The Raspberry Pi foundation changed single-board computing [when they released the Raspberry Pi computer](https://www.raspberrypi.org/archives/723), now they're ready to do the same for microcontrollers with the release of the brand new **Raspberry Pi Pico**. This...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4864)
[Related Guides to the Product](https://learn.adafruit.com/products/4864/guides)
![Angle shot of Raspberry Pi Pico RP2040](https://cdn-shop.adafruit.com/640x480/4864-00.jpg)

### Adafruit AirLift FeatherWing – ESP32 WiFi Co-Processor

[Adafruit AirLift FeatherWing – ESP32 WiFi Co-Processor](https://www.adafruit.com/product/4264)
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 favorite Feather ([like the Feather M4](https://www.adafruit.com/product/3857)) that comes with its own...

In Stock
[Buy Now](https://www.adafruit.com/product/4264)
[Related Guides to the Product](https://learn.adafruit.com/products/4264/guides)
![Angled shot of Adafruit AirLift FeatherWing.](https://cdn-shop.adafruit.com/640x480/4264-07.jpg)

### Adafruit AirLift – ESP32 WiFi Co-Processor Breakout Board

[Adafruit AirLift – ESP32 WiFi Co-Processor Breakout Board](https://www.adafruit.com/product/4201)
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 have your favorite microcontroller (like the ATmega328 or ATSAMD51), awesome peripherals and lots of libraries....

In Stock
[Buy Now](https://www.adafruit.com/product/4201)
[Related Guides to the Product](https://learn.adafruit.com/products/4201/guides)
![Top view of Adafruit AirLift Breakout Board.](https://cdn-shop.adafruit.com/640x480/4201-08.jpg)

### Part: FeatherWing Doubler
quantity: 1
FeatherWing Doubler - Prototyping Add-on For All Feather Boards
[FeatherWing Doubler](https://www.adafruit.com/product/2890)

### Part: USB-C Cable
quantity: 1
USB-C Cable for RP2040 Feather
[USB-C Cable](https://www.adafruit.com/product/4199)

### Part: USB Cable
quantity: 1
USB cable - USB A to Micro-B - 3 foot long
[USB Cable](https://www.adafruit.com/product/592)

### Part: Breadboard
quantity: 1
Full sized breadboard
[Breadboard](https://www.adafruit.com/product/239)

### Part: Breadboarding Wires
quantity: 1
Breadboarding wire bundle
[Breadboarding Wires](https://www.adafruit.com/product/153)

# Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython

## Bluetooth Low Energy Basics

![](https://cdn-learn.adafruit.com/assets/assets/000/070/422/medium800/micropython___circuitpython_Bluetooth_Logo.png?1549045741)

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.&nbsp;
- **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.

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!

# Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython

## Assembly

Adafruit sells Airlift hardware in [multiple](https://www.adafruit.com/product/4264) [form](https://www.adafruit.com/product/4201) [factors](https://www.adafruit.com/product/4363) 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** :

![](https://cdn-learn.adafruit.com/assets/assets/000/100/782/medium800/raspberry_pi_Pasted_Image_3_18_21__12_40_PM.png?1616085697)

After soldering the jumpers closed, we suggest using the [FeatherWing Doubler](https://www.adafruit.com/product/2890) to connect a Feather RP2040 and an AirLift FeatherWing side-by-side.

![raspberry_pi_rp2040-airlift-featherwing.png](https://cdn-learn.adafruit.com/assets/assets/000/100/778/medium640/raspberry_pi_rp2040-airlift-featherwing.png?1616084275)

## 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.

Danger: 

- Pico **&nbsp;VSYS** &nbsp;to&nbsp; **AirLift Vin**
- **Pico GND** &nbsp;to&nbsp; **AirLift GND**
- **Pico GP13** &nbsp;(SPI1 CSn) to&nbsp; **AirLift CS**
- **Pico GP14** &nbsp;to **&nbsp;AirLift BUSY**
- **Pico GP16** &nbsp;to&nbsp; **AirLift !RST**
- **Pico GP9** to **AirLift GPIO0**
- **Pico GP0** to **AirLift RXI**
- **Pico GP1** to **AirLift TX0**

For more information about the UART peripheral and pinouts of the Pico,&nbsp;[check out this guide](https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/pinouts).

![raspberry_pi_pico_airliftwing_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/101/028/medium640/raspberry_pi_pico_airliftwing_bb.png?1616779950)

# Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython

## Code Usage

Warning: 

## Install CircuitPython Libraries

Make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;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&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases).&nbsp; Our CircuitPython starter guide has&nbsp;[a great page on how to use the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

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&nbsp; **lib** &nbsp;folder or root filesystem has the files and&nbsp;folders listed above **&nbsp;** 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&nbsp;[Bluefruit LE Connect Guide](https://learn.adafruit.com/bluefruit-le-connect/)&nbsp;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.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/rp2040_ble_airlift/ble-bluefruit-uart-echo-rp2040/code.py

Your CIRCUITPY file-system should look like the following:

![](https://cdn-learn.adafruit.com/assets/assets/000/101/016/medium800/raspberry_pi_lib_fs.png?1616693965)

## 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.

![](https://cdn-learn.adafruit.com/assets/assets/000/101/008/medium800/raspberry_pi_adafruit_products_airlift-connect.png?1616689514)

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

![](https://cdn-learn.adafruit.com/assets/assets/000/101/009/medium800/raspberry_pi_adafruit_products_airlift-uart_%281%29.png?1616689535)

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).

![](https://cdn-learn.adafruit.com/assets/assets/000/101/010/medium800/raspberry_pi_adafruit_products_airlift-echo.png?1616689549)

That's it!&nbsp;

# Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython

## NeoPixel Color

Warning: 

The Bluefruit LE Connect app has a Color Picker that allows you to easily set the color of NeoPixels connected to your Adafruit Feather RP2040. In this example, we'll change the color of the onboard NeoPIxel using CircuitPython and the Bluefruit LE Connect app.

Save the following as **code.py** on your **CIRCUITPY** drive and then connect to the board using the Bluefruit LE Connect app.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/rp2040_ble_airlift/ble-bluefruit-color-picker-rp2040/code.py

Then, connect to your board using the Bluefruit LE Connect application. From the controller page, navigate to the Color Picker page.

Connect to your board using the Bluefruit LE Connect application.

From the Device page, navigate to the Controller page.

![raspberry_pi_Pasted_Image_3_25_21__1_45_PM.png](https://cdn-learn.adafruit.com/assets/assets/000/101/017/medium640/raspberry_pi_Pasted_Image_3_25_21__1_45_PM.png?1616694340)

On the controller page, tap the Color Picker.

![raspberry_pi_IMG_35D30A19D296-1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/018/medium640/raspberry_pi_IMG_35D30A19D296-1.jpg?1616694607)

Selecting a color and tapping the "Send Selected Color" button should send the red, green, and blue values from the Bluefruit Connect App to the RP2040.

![](https://cdn-learn.adafruit.com/assets/assets/000/101/027/medium800thumb/raspberry_pi_ezgif.com-gif-maker_%282%29.jpg?1616704526)

# Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython

## Adapting Existing CircuitPython BLE Code for AirLift BLE

Info: 

We have written lots of [examples](https://learn.adafruit.com/circuitpython-nrf52840/) and projects for using CircuitPython's BLE peripheral mode. However, these examples are designed to work with CircuitPython hardware that includes a built-in BLE module such as the Nordic NRF52840.

Adapting code that uses the built-in BLE module to use the AirLift ESP32's BLE mode is simple. Add the following line to your code to import the `adafruit_airlift` module:

```python
from adafruit_airlift.esp32 import ESP32
```

Code that utilizes native `adafruit_ble`&nbsp;will have the following line which initializes an onboard BLE module:&nbsp;

```python
ble = BLERadio()
```

Replace this line with the following lines below to initialize the AirLift and set up the `BLERadio` module for use with the AirLift. Make sure to match the `esp32`'s pinout with your wiring.

```python
esp32 = ESP32(
    reset=board.D12,
    gpio0=board.D10,
    busy=board.D11,
    chip_select=board.D13,
    tx=board.TX,
    rx=board.RX,
)

adapter = esp32.start_bluetooth()
ble = BLERadio(adapter)
```

That's it - you do not need to modify the rest of the code, it should work as-is! Visit the [Adafruit Learning System](https://learn.adafruit.com/) for more guides on using Bluetooth Low Energy with CircuitPython.

# Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython

## BLE Technical Details


## Featured Products

### Adafruit Feather RP2040

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
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 Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

In Stock
[Buy Now](https://www.adafruit.com/product/4884)
[Related Guides to the Product](https://learn.adafruit.com/products/4884/guides)
### Adafruit AirLift FeatherWing – ESP32 WiFi Co-Processor

[Adafruit AirLift FeatherWing – ESP32 WiFi Co-Processor](https://www.adafruit.com/product/4264)
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 favorite Feather ([like the Feather M4](https://www.adafruit.com/product/3857)) that comes with its own...

In Stock
[Buy Now](https://www.adafruit.com/product/4264)
[Related Guides to the Product](https://learn.adafruit.com/products/4264/guides)
### Raspberry Pi Pico RP2040

[Raspberry Pi Pico RP2040](https://www.adafruit.com/product/4864)
The Raspberry Pi foundation changed single-board computing [when they released the Raspberry Pi computer](https://www.raspberrypi.org/archives/723), now they're ready to do the same for microcontrollers with the release of the brand new **Raspberry Pi Pico**. This...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4864)
[Related Guides to the Product](https://learn.adafruit.com/products/4864/guides)
### Adafruit AirLift – ESP32 WiFi Co-Processor Breakout Board

[Adafruit AirLift – ESP32 WiFi Co-Processor Breakout Board](https://www.adafruit.com/product/4201)
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 have your favorite microcontroller (like the ATmega328 or ATSAMD51), awesome peripherals and lots of libraries....

In Stock
[Buy Now](https://www.adafruit.com/product/4201)
[Related Guides to the Product](https://learn.adafruit.com/products/4201/guides)
### FeatherWing Doubler - Prototyping Add-on For All Feather Boards

[FeatherWing Doubler - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2890)
This is the **FeatherWing Doubler** - a prototyping add-on and more for all Feather boards. This is similar to our [FeatherWing Proto](https://www.adafruit.com/products/2884) except there are two! The magic of the Doubler comes when stacking a Feather and another...

In Stock
[Buy Now](https://www.adafruit.com/product/2890)
[Related Guides to the Product](https://learn.adafruit.com/products/2890/guides)
### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

Out of Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)
### USB C to USB C Cable - USB 3.1 Gen 4 with E-Mark - 1 meter long

[USB C to USB C Cable - USB 3.1 Gen 4 with E-Mark - 1 meter long](https://www.adafruit.com/product/4199)
As technology changes and adapts, so does Adafruit! Rather than the regular USB A, this cable has&nbsp; **USB C to USB C** &nbsp;plugs!

USB C is the latest industry-standard connector for transmitting data&nbsp;_and_&nbsp;power. Like Lightning and MagSafe cables, USB C...

In Stock
[Buy Now](https://www.adafruit.com/product/4199)
[Related Guides to the Product](https://learn.adafruit.com/products/4199/guides)
### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)

## Related Guides

- [Adafruit AirLift - ESP32 WiFi Co-Processor Breakout](https://learn.adafruit.com/adafruit-airlift-breakout.md)
- [Adafruit AirLift FeatherWing - ESP32 WiFi Co-Processor](https://learn.adafruit.com/adafruit-airlift-featherwing-esp32-wifi-co-processor-featherwing.md)
- [Introducing Adafruit Feather RP2040](https://learn.adafruit.com/adafruit-feather-rp2040-pico.md)
- [Upgrading AirLift ESP32 Firmware](https://learn.adafruit.com/upgrading-esp32-firmware.md)
- [MQTT in CircuitPython](https://learn.adafruit.com/mqtt-in-circuitpython.md)
- [CircuitPython displayio Setup for TFT FeatherWings](https://learn.adafruit.com/using-circuitpython-displayio-with-a-tft-featherwing.md)
- [Optical Sensor Drum Track Sequencer](https://learn.adafruit.com/drum-track-sequencer.md)
- [Program RP2040 in Arduino](https://learn.adafruit.com/rp2040-arduino-with-the-earlephilhower-core.md)
- [Bubble Table with LED Animations and IR Remote Control](https://learn.adafruit.com/bubble-table-with-led-animations-and-ir-remote-control.md)
- [Customizing USB Devices in CircuitPython](https://learn.adafruit.com/customizing-usb-devices-in-circuitpython.md)
- [Numpad 4000 Mechanical Keyswitch Data Entry Device](https://learn.adafruit.com/numpad-4000-mechanical-keyswitch-data-entry-device.md)
- [Circle of Fifths Euclidean Synth with synthio and CircuitPython](https://learn.adafruit.com/circle-of-fifths-euclidean-synth-with-synthio-and-circuitpython.md)
- [Daily Cheer Automaton](https://learn.adafruit.com/daily-cheer-automaton.md)
- [IoT Air Quality Sensor with Adafruit IO](https://learn.adafruit.com/diy-air-quality-monitor.md)
- [Air Quality Sensor 3D Printed Enclosure](https://learn.adafruit.com/air-quality-sensor-silo-house.md)
- [4x4 Rotary Encoder MIDI Messenger](https://learn.adafruit.com/4x4-rotary-encoder-midi-messenger.md)
- [Deco Two-Key Feather Macro Pad](https://learn.adafruit.com/deco-two-key-keypad-macropad-circuitpython-feather.md)
- [Adafruit IO Basics: AirLift](https://learn.adafruit.com/adafruit-io-basics-airlift.md)
