# CircuitPython BLE Libraries on Any Computer

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/096/449/medium800/raspberry_pi_multi.jpg?1603811830)

Adafruit CircuitPython supports using Bluetooth Low Energy (BLE) to communicate wirelessly with BLE devices, phones, tablets, and with other CircuitPython boards. Adafruit provides many libraries to make this easy and to support specific devices.

Now you can use those same libraries (or write your own) on any host computer--Windows, Mac, or Linux--that has BLE hardware. Most modern computers, especially laptops, already have Bluetooth hardware built in. If not, you can plug in a USB adapter such as Adafruit's [Bluetooth 4.0 USB Module](https://www.adafruit.com/product/1327).

The Adafruit [Blinka bleio library](https://github.com/adafruit/Adafruit_Blinka_bleio) makes this possible. It is a regular Python library that runs on desktop Python, not on CircuitPython boards. It re-implements the `_bleio` module that is part of CircuitPython: all our BLE libraries are ultimately based on `_bleio`.

**The Blinka bleio library only supports acting in a BLE central role.** You can connect to peripheral devices, such as heart rate monitors, pulse oximeters, bicycle sensors, etc., but you cannot act as a peripheral yourself with this code.&nbsp;

The Blinka bleio library is part of the family of "Blinka" libraries that run under regular Python and implement CircuitPython functionality, including Blinka and Blinka displayio.

This guide will explain how to get Python set up on your host computer, how to install the Blinka bleio library, and then give some examples of how to use it.

## Bluetooth Capable Devices from Adafruit
### Xinghuatian Tech Bluetooth® 4.0 USB Module

[Xinghuatian Tech Bluetooth® 4.0 USB Module](https://www.adafruit.com/product/1327)
Add Bluetooth® capability to your computer super fast with a Xinghuatian Tech Bluetooth® 4.0 USB Module. This adapter is backwards compatible with v2.1 and earlier, but also supports the latest v4.0/ Bluetooth® Low Energy. Inside lies a <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1327)
[Related Guides to the Product](https://learn.adafruit.com/products/1327/guides)
![Angled shot of a Bluetooth 4.0 USB Module. ](https://cdn-shop.adafruit.com/640x480/1327-05.jpg)

## Some Adafruit Microcontrollers with Bluetooth
### Adafruit CLUE - nRF52840 Express with Bluetooth® LE

[Adafruit CLUE - nRF52840 Express with Bluetooth® LE](https://www.adafruit.com/product/4500)
Do you feel like you just don't have a CLUE? Well, we can help with that - get a CLUE here at Adafruit by picking up this sensor-packed development board. We wanted to build some projects that have a small screen and a lot of sensors. To make it compatible with existing projects, we made...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4500)
[Related Guides to the Product](https://learn.adafruit.com/products/4500/guides)
![Animated GIF showing CLUE board  displaying data from the many on-board sensors.](https://cdn-shop.adafruit.com/product-videos/640x480/4500-04.jpg)

### Circuit Playground Bluefruit - Bluetooth® Low Energy

[Circuit Playground Bluefruit - Bluetooth® Low Energy](https://www.adafruit.com/product/4333)
 **Circuit Playground Bluefruit** is our third board in the Circuit Playground series, another step towards a perfect introduction to electronics and programming. We've taken the popular Circuit Playground Express and made it even better! Now the main chip is an nRF52840...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4333)
[Related Guides to the Product](https://learn.adafruit.com/products/4333/guides)
![shot of a Black woman's neon-green manicured hand holding up a Circuit Playground Bluefruit glowing rainbow LEDs.](https://cdn-shop.adafruit.com/640x480/4333-11.jpg)

### Adafruit Feather nRF52840 Express

[Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
The **Adafruit Feather nRF52840 Express** is the new Feather family member with Bluetooth® Low Energy and _native USB support_ featuring the nRF52840!&nbsp; It's our take on an 'all-in-one' Arduino-compatible + Bluetooth® Low Energy with built-in USB...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4062)
[Related Guides to the Product](https://learn.adafruit.com/products/4062/guides)
![Angled shot of a Adafruit Feather nRF52840 Express. ](https://cdn-shop.adafruit.com/640x480/4062-02.jpg)

### Adafruit Feather nRF52840 Sense

[Adafruit Feather nRF52840 Sense](https://www.adafruit.com/product/4516)
The **Adafruit Feather Bluefruit Sense** takes our popular [Feather nRF52840 Express](https://www.adafruit.com/product/4062) and adds a smorgasbord of sensors to make a great wireless sensor platform. This Feather microcontroller comes with Bluetooth® Low Energy and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4516)
[Related Guides to the Product](https://learn.adafruit.com/products/4516/guides)
![Angled shot of blue, rectangular, microcontroller.](https://cdn-shop.adafruit.com/640x480/4516-06.jpg)

# CircuitPython BLE Libraries on Any Computer

## Install Python on Your Host Computer

# You Need Python 3 and `pip3`

To run CircuitPython BLE libraries on a host computer, you'll need at least Python 3.9, and you'll need the `pip3` program to install the libraries. You may have `pip` already, but often the `pip` (not pip3) command installs software for Python 2, so make sure you are using `pip3`.

# Windows 10 or 11

You can install Python from [https://python.org,](https://python.org,)or from the Windows Store. See our guide [Using Python on WIndows 10](https://learn.adafruit.com/using-python-on-windows-10) for an easy way to get Python installed.

If you don't use the Windows Store version, make sure you check the box to add Python to your PATH when you run the installer. See the screenshot below.

![](https://cdn-learn.adafruit.com/assets/assets/000/120/092/medium800/raspberry_pi_windows-python-install.png?1680564526)

## Starting Python 3 on Windows

Depending on how you install Python 3, the command to start it in a command shell in Windows can be different.

- Installed from the [https://python.org](https://python.org) download:
  - _Works:_ `python` (`python.exe`)
  - _Works:_`py` (`py.exe`, the Python launcher).
  - _Does not work:_ `python3` (`python3.exe`). You'll get directed to the Windows Store to install Python 3 yet again.

- Installed from the Windows Store:
  - _Works:_ `python` (`python.exe`)
  - _Does not work:_ `py` (the Python launcher is not installed).
  - _Works:_ `python3` (`python3.exe`).

These differences can be confusing; see [this page](https://docs.python.org/3/using/windows.html) for detailed documentation.

# macOS

Modern macOS comes with Python 3, but it may be an older version. Instead of using the system-supplied version, we recommend that you use the [Homebrew](https://brew.sh/) system to install a more recent version of Python 3 and keep it up to date. The Homebrew installation will not interfere with the system-installed Python, and does not replace it.

[This article](https://opensource.com/article/19/5/python-3-default-mac) describes in detail various ways of managing Python on macOS. It's worth reading to understand the issues, and to see various ways of managing multiple versions of Python.

### Bluetooth Permissions

A user has reported that, at least as of macOS Big Sur, you must add your terminal application to the Bluetooth Privacy Settings in **System Preferences \> Security & Privacy \> Privacy \> Bluetooth**.

# Linux

Modern versions of Linux always come with Python. They may include both Python 2 and Python 3. See if the version supplied with your Linux distribution is at least 3.9. If not, your distribution may allow you to install additional versions that do not interfere with the original system-supplied version. If you can upgrade your distribution, considering doing so. For instance, Ubuntu 22.04 comes with Python 3.10.

Make sure you have `pip3` installed as well, by trying to run it. If it's not installed, install it in the appropriate way for your Linux distribution. For instance, for Ubuntu and Debian, do:

```none
sudo apt install python3-pip
```

# Raspberry Pi OS

Raspberry Pi OS (the new name for Raspian), which is based on Debian Linux, also comes with Python. The latest version as of this writing (April 2023), bullseye, comes with Python 3.9, invoked with the `python3` command.

If you are using Raspberry Pi OS Lite, it may not come with `pip3`. You'll need to install it by doing:&nbsp;

```python
sudo apt install python3-pip
```

Danger: 

# Do Not Use `sudo` When Running `pip3`

You may see Internet advice to install libraries using `sudo pip3` on Linux or MacOS. This is in general a bad idea, because you can damage the libraries that the underlying system depends on, and in general end up trashing your system in mysterious ways. Always install using `pip3` without `sudo`. If your `pip3` is old, you may need to specify `pip3 --user`, but these days `--user` is often the default.

[Here's a detailed discussion](https://stackoverflow.com/questions/29310688/sudo-pip-install-vs-pip-install-user) of why `sudo pip3` is a bad idea.

# CircuitPython BLE Libraries on Any Computer

## Install BLE Libraries

Once you have installed Python 3 and `pip3`, you are ready to install the Blinka bleio library and the base CircuitPython BLE library. In your shell, enter this command to install both:

```python
pip3 install --upgrade adafruit-blinka-bleio adafruit-circuitpython-ble
```

The `--upgrade` will ensure that you get the latest versions, even if either library&nbsp;was previously installed. The `adafruit-blinka-bleio` library depends on a number of other libraries, which will be installed automatically, and upgraded if necessary.

&nbsp;

# Linux and Raspberry Pi: Add User to `bluetooth` Group

On Linux, including on Raspberry Pi, you must also add your user to the `bluetooth` group. Reboot after doing this to ensure your user is added to the group and also to ensure that `~/.local/bin` is added to your path (after doing `pip3` above). To add yourself to the group, do this:

```python
sudo usermod -a -G bluetooth $USER
sudo reboot
```

# Raspberry Pi 3B+ and 4B Firmware Fix

Raspberry Pi **3B+** and **4B** boards use different hardware for BLE and WiFi than Raspberry Pi **3B** and Pi **Zero W** boards. There was a [bug](https://github.com/RPi-Distro/bluez-firmware/issues/6) in the firmware for the 3B+ and 4B boards, in the `bluez-firmware` package. `bluez-firmware-1.2-4+rpt2` worked, but versions&nbsp; `rpt3`, `rpt4`, `rpt5`, and `rpt6` did not. Make sure your version is at least `rpt8`, as `rpt8` includes a security fix not present in `rpt7`.

```none
$ apt list bluez-firmware
Listing... Done
bluez-firmware/testing,now 1.2-4+rpt8 all [installed,automatic]
N: There is 1 additional version. Please use the '-a' switch to see it
```

If you need to upgrade bluez-firmware, do:

```none
$ sudo apt upgrade bluez-firmware
```

# CircuitPython BLE Libraries on Any Computer

## Pulse Oximeter, Heart Rate Monitor, and BBQ Thermometer

Once the base BLE libraries are installed, you can install helper libraries for various third-party BLE peripherals, and access them directly. We'll show examples of peripherals accessed from several different host computers.

# Pulse Oximeter
This example uses the&nbsp;[BerryMed Pulse Oximeter](https://www.adafruit.com/product/4582) sold by Adafuit. Install the pulse oximeter library by typing the `pip3` command below into your shell.&nbsp; Then download the example program below.

![raspberry_pi_IMG_1981.jpg](https://cdn-learn.adafruit.com/assets/assets/000/096/160/medium640/raspberry_pi_IMG_1981.jpg?1603224487)

```python
pip3 install adafruit-circuitpython-ble-berrymed-pulse-oximeter
```

https://github.com/adafruit/Adafruit_CircuitPython_BLE_BerryMed_Pulse_Oximeter/blob/main/examples/ble_berrymed_pulse_oximeter_simpletest.py

Run the example program, and turn on the pulse oximeter, reading from your finger. Here's a screenshot from running it on Windows, in PowerShell. In this example, I typed ctrl-C after getting a few readings.

![](https://cdn-learn.adafruit.com/assets/assets/000/096/159/medium800/raspberry_pi_windows-berrymed.png?1603223901)

# Heart Rate Monitor
This is a Schoshe Heart Rate Monitor, which transmits data using the standard BLE Heart Rate Monitor service. Install the heart rate library by typing the `pip3` command below into your shell. Then download the example program below.

![raspberry_pi_IMG_1994.jpg](https://cdn-learn.adafruit.com/assets/assets/000/096/164/medium640/raspberry_pi_IMG_1994.jpg?1603237559)

```python
pip3 install adafruit-circuitpython-ble-heart-rate
```

https://github.com/adafruit/Adafruit_CircuitPython_BLE_Heart_Rate/blob/main/examples/ble_heart_rate_simpletest.py

Turn on your heart rate monitor, and run the example program. reading from your finger. Here's a screenshot from running it on Ubuntu Linux. In this example, I typed ctrl-C after getting a few readings.

![](https://cdn-learn.adafruit.com/assets/assets/000/096/166/medium800/raspberry_pi_linux-heart-rate.png?1603238197)

# iBBQ Thermometer
Here's a BLE-enabled food thermometer, which can take two probes. It and similar models are readily available under the "nutrichef" brand name, and identify as "iBBQ" in their BLE advertisements.

Install the iBBQ library by typing the pip3 command below into your shell. Then download the example program below.

![raspberry_pi_IMG_1995.jpg](https://cdn-learn.adafruit.com/assets/assets/000/096/167/medium640/raspberry_pi_IMG_1995.jpg?1603238720)

```python
pip3 install adafruit-circuitpython-ble-ibbq
```

https://github.com/adafruit/Adafruit_CircuitPython_BLE_iBBQ/blob/main/examples/ble_ibbq_simpletest.py

Turn on your thermometer, and run the example program. Here's a screenshot from running it on MacOS. In this example, I typed ctrl-C after getting a few readings.

![](https://cdn-learn.adafruit.com/assets/assets/000/096/230/medium800/raspberry_pi_macos-ibbq.png?1603372614)

# CircuitPython BLE Libraries on Any Computer

## BLE UART

One simple way of communicating between two BLE devices is to use a simulated "UART". A UART provides a bi-directional byte stream, so that both ends of a connection can transmit and receive bytes with each other.

There are standard BLE UART services, such as the Nordic UART Service (NUS). The Adafruit [Bluefruit Connect](https://learn.adafruit.com/circuitpython-nrf52840/bluefruit-le-connect-basics) app uses NUS to talk to BLE boards.

Once you get the UART service working, it's easy to invent your own _ad hoc_ protocol that sends and receives commands and data over the serial stream.

# BLE UART Python `eval()` Example

Here's a simple example that uses BLE UART to send a text string from a host computer to a CircuitPython board over BLE. The board calls the Python function `eval()` on the string, to evaluate it as a Python expression, and sends the result back as a string to the host computer. For instance, the host might send `2+2`, and the board will send back `4`.

To try this example, first install this library from the latest [library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries) on your BLE-capable CircuitPython board, such as a Feather nRF52840 or a Circuit Playground Bluefruit:

- **adafruit\_ble**

Then copy the program below to **CIRCUITPY** on your CircuitPython board as **code.py** :

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/BLE_Host_Computer/code.py

Now copy the second program to your host computer, and run it. Wait for it to connect to your board, and then type some Python expressions at the **Eval:** prompt.&nbsp;

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/BLE_Host_Computer/ble_eval_client.py

Here's an example of running the **ble\_eval\_client.py** program on a Raspberry Pi Zero W, talking to a Circuit Playground Bluefruit.

Note that errors, like division by zero, are caught and reported. Also note you can only type Python expressions, not statements. So `a = 3` doesn't work.

![](https://cdn-learn.adafruit.com/assets/assets/000/096/252/medium800/raspberry_pi_pi0-eval.png?1603398199)

The example above was mostly recently tested successfully with CircuitPython 10.0.0 on an nRF52840, and&nbsp;`bleak` 1.1.1 on Ubuntu 24.04.

# CircuitPython BLE Libraries on Any Computer

## Troubleshooting

# Reset Bluetooth

Sometimes the Bluetooth system software on the host computer becomes stuck, confused, or in a bad state. This can cause Blinka bleio programs to stop working. Often a simple fix is just to turn Bluetooth off and then back on, on the host computer.

## Windows

There are two ways to cycle Bluetooth off and on in Windows. In Settings, find the Bluetooth setting page, and turn Bluetooth off and then back on:

![](https://cdn-learn.adafruit.com/assets/assets/000/096/261/medium800/raspberry_pi_windows-bluetooth-cycle.png?1603462599)

Or, select the Notification area by clicking the Notification icon in the taskbar (1), and then toggle Bluetooth off and then back on (2):

![](https://cdn-learn.adafruit.com/assets/assets/000/096/262/medium800/raspberry_pi_windows-bluetooth-notification-cycle.png?1603462751)

## macOS

Go to System Preferences, and choose Bluetooth (1). Then toggle Bluetooth off and on (2). If you check the box that says "Show Bluetooth in menu bar" (3), you can toggle Bluetooth more quickly (4).

![](https://cdn-learn.adafruit.com/assets/assets/000/096/264/medium800/raspberry_pi_macos-bluetooth-preferences.png?1603463299)

![](https://cdn-learn.adafruit.com/assets/assets/000/096/263/medium800/raspberry_pi_macos-bluetooth-toggle.png?1603463262)

![](https://cdn-learn.adafruit.com/assets/assets/000/096/266/medium800/raspberry_pi_macos-bluetooth-menu-bar.png?1603467035)

## Linux and Raspberry Pi

Depending on which Linux distribution and desktop software you're using, there might be a Bluetooth item in the task bar or menu bar for your desktop that will allow to you cycle Bluetooth off and back on easily. For instance, the default Raspberry Pi desktop has a Bluetooth icon in the top menu bar; you can turn Bluetooth off and then back on from there.

![](https://cdn-learn.adafruit.com/assets/assets/000/096/268/medium800/raspberry_pi_rpi-desktop-bluetooth.png?1603472875)

If you don't have a desktop icon to use, you can cycle Bluetooth from the command line. For Raspberry Pi OS, Debian, and Ubuntu, type these commands into your shell:

```python
rfkill block bluetooth
rfkill unblock bluetooth
```

You may find it convenient to create a script to do this. For instance, you can put these commands into a file called `btcycle`, make it executable, and put it in some directory on your PATH:

```python
#!/bin/bash
# Cycle Bluetooth on and off to reset it.
rfkill block bluetooth
rfkill unblock bluetooth
 # Wait for bluetooth to come back on. You may need to change this delay.
sleep 1.5
```


## Featured Products

### Circuit Playground Bluefruit - Bluetooth® Low Energy

[Circuit Playground Bluefruit - Bluetooth® Low Energy](https://www.adafruit.com/product/4333)
 **Circuit Playground Bluefruit** is our third board in the Circuit Playground series, another step towards a perfect introduction to electronics and programming. We've taken the popular Circuit Playground Express and made it even better! Now the main chip is an nRF52840...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4333)
[Related Guides to the Product](https://learn.adafruit.com/products/4333/guides)
### Adafruit CLUE - nRF52840 Express with Bluetooth® LE

[Adafruit CLUE - nRF52840 Express with Bluetooth® LE](https://www.adafruit.com/product/4500)
Do you feel like you just don't have a CLUE? Well, we can help with that - get a CLUE here at Adafruit by picking up this sensor-packed development board. We wanted to build some projects that have a small screen and a lot of sensors. To make it compatible with existing projects, we made...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4500)
[Related Guides to the Product](https://learn.adafruit.com/products/4500/guides)
### Adafruit Feather nRF52840 Express

[Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
The **Adafruit Feather nRF52840 Express** is the new Feather family member with Bluetooth® Low Energy and _native USB support_ featuring the nRF52840!&nbsp; It's our take on an 'all-in-one' Arduino-compatible + Bluetooth® Low Energy with built-in USB...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4062)
[Related Guides to the Product](https://learn.adafruit.com/products/4062/guides)
### Adafruit Feather nRF52840 Sense

[Adafruit Feather nRF52840 Sense](https://www.adafruit.com/product/4516)
The **Adafruit Feather Bluefruit Sense** takes our popular [Feather nRF52840 Express](https://www.adafruit.com/product/4062) and adds a smorgasbord of sensors to make a great wireless sensor platform. This Feather microcontroller comes with Bluetooth® Low Energy and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4516)
[Related Guides to the Product](https://learn.adafruit.com/products/4516/guides)
### Finger Pulse Oximeter with Bluetooth LE

[Finger Pulse Oximeter with Bluetooth LE](https://www.adafruit.com/product/4582)
[Discontinued - **you can grab the&nbsp;** Finger Pulse Oximeter - BM1000 **instead!**](https://www.adafruit.com/product/4580)

This&nbsp; **Finger Pulse Oximeter with Bluetooth LE&nbsp;** is great&nbsp;for monitoring your blood oxygen levels and&nbsp;pulse...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/4582)
[Related Guides to the Product](https://learn.adafruit.com/products/4582/guides)
### Xinghuatian Tech Bluetooth® 4.0 USB Module

[Xinghuatian Tech Bluetooth® 4.0 USB Module](https://www.adafruit.com/product/1327)
Add Bluetooth® capability to your computer super fast with a Xinghuatian Tech Bluetooth® 4.0 USB Module. This adapter is backwards compatible with v2.1 and earlier, but also supports the latest v4.0/ Bluetooth® Low Energy. Inside lies a <a...></a...>

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

## Related Guides

- [Introducing the Adafruit nRF52840 Feather](https://learn.adafruit.com/introducing-the-adafruit-nrf52840-feather.md)
- [Adafruit Circuit Playground Bluefruit](https://learn.adafruit.com/adafruit-circuit-playground-bluefruit.md)
- [Introducing Adafruit CLUE](https://learn.adafruit.com/adafruit-clue.md)
- [Adafruit Feather nRF52840 Sense](https://learn.adafruit.com/adafruit-feather-sense.md)
- [Bluetooth CLUE Robot Car using CircuitPython](https://learn.adafruit.com/bluetooth-clue-robot-car-using-circuitpython.md)
- [Color Remote with Circuit Playground Bluefruit](https://learn.adafruit.com/color-remote-with-circuit-playground-bluefruit.md)
- [CircuitPython BLE Advertising Beacons](https://learn.adafruit.com/circuitpython-ble-advertising-beacons.md)
- [Digital Egg Drop Experiment with CLUE](https://learn.adafruit.com/egg-drop-clue.md)
- [Using the Bluefruit Dashboard with Web Bluetooth in Chrome](https://learn.adafruit.com/bluefruit-dashboard-web-bluetooth-chrome.md)
- [Power Glove Wireless MIDI Controller](https://learn.adafruit.com/power-glove-bluetooth-midi-controller.md)
- [Bluetooth Controlled NeoPixel Lightbox](https://learn.adafruit.com/bluetooth-neopixel-lightbox.md)
- [BLE Sniffer with nRF52840](https://learn.adafruit.com/ble-sniffer-with-nrf52840.md)
- [Adafruit LSM6DS33 6-DoF IMU Breakout](https://learn.adafruit.com/lsm6ds33-6-dof-imu-accelerometer-gyro.md)
- [PyLeap BLE Controlled NeoPixels with CLUE](https://learn.adafruit.com/pyleap-ble-controlled-neopixels-with-clue.md)
- [Circuit Playground Bluefruit BLE Heart Rate Pendant with CircuitPython](https://learn.adafruit.com/ble-heart-rate-display-pendant.md)
- [AdaBox 015](https://learn.adafruit.com/adabox015.md)
- [CLUE Rock, Paper, Scissors Game using Bluetooth](https://learn.adafruit.com/rock-paper-scissors-circuitpython.md)
- [Circuit Playground Bluefruit Quick Draw Duo](https://learn.adafruit.com/circuit-playground-bluefruit-quick-draw-duo.md)
- [ulab: Crunch Numbers fast in CircuitPython](https://learn.adafruit.com/ulab-crunch-numbers-fast-with-circuitpython.md)
