# Wirelessly Code your Bluetooth Device with CircuitPython

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/106/516/medium800/circuitpython_IMG_3685.jpeg?1636996375)

Many people are familiar with Bluetooth Low Energy (BLE) for connecting peripherals such as mice and keyboards or event some headphones or earbuds. However, BLE can do so much more. Did you know you can transfer files over BLE? This is the basis for being able to edit CircuitPython files directly on your device.

Adafruit has been working on a new web-based Code Editor for CircuitPython. This allows you to edit files directly on your Bluetooth devices using just the Chrome web browser without installing any additional software. The great thing about this code editor is it is written completely in JavaScript, so it only runs on your computer and **none of your data is ever uploaded to a server**.

Last year's guide called [Using the Bluefruit Dashboard with Web Bluetooth in Chrome](https://learn.adafruit.com/bluefruit-dashboard-web-bluetooth-chrome/overview) used Web Bluetooth to read sensors on a few of the devices Adafruit offers. This was great for being able to test out all of the sensors on the boards, but the code running on the board was written in Arduino.

With the Code Editor, however, all of the BLE functions are built into CircuitPython itself and so you can have it run any CircuitPython script you would like while still retaining the ability to remotely edit your files.

To get started, all you will need are a Bluetooth board with the nRF52840 chip such as the&nbsp;[**Circuit Playground Bluefruit**](https://www.adafruit.com/product/4333),&nbsp;[**Adafruit CLUE**](https://www.adafruit.com/product/4500), [**Feather nRF52840 Express**](https://www.adafruit.com/product/4062), [**Feather nRF52840 Sense**](https://www.adafruit.com/product/4516), [**BBC micro:bit V2**](https://www.adafruit.com/product/4781), [**LED Glasses Driver**](https://www.adafruit.com/product/5217), or one of a number of [other Bluetooth boards that run CircuitPython](https://circuitpython.org/downloads?features=Bluetooth%2FBTLE).

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

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

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

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

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

### BBC micro:bit v2

[BBC micro:bit v2](https://www.adafruit.com/product/4781)
Meet the new **BBC micro:bit v2** - Upgraded with a powerful new processor that has tons more capability and also adds more sensing with a new speaker and microphone!

The latest micro:bit will fit right into your existing lessons and materials; all the...

In Stock
[Buy Now](https://www.adafruit.com/product/4781)
[Related Guides to the Product](https://learn.adafruit.com/products/4781/guides)
![Angled shot of a BBC micro:bit v2. ](https://cdn-shop.adafruit.com/640x480/4781-04.jpg)

### Adafruit LED Glasses Driver - nRF52840 Sensor Board

[Adafruit LED Glasses Driver - nRF52840 Sensor Board](https://www.adafruit.com/product/5217)
This board is designed to be a thin, Bluetooth®-enabled driver board for our [Adafruit LED Glasses](https://www.adafruit.com/product/5210) RGB LED matrix. That said, it's a perfectly good stand-alone development board for the Nordic nRF52840 chipset, with a very slim design,...

In Stock
[Buy Now](https://www.adafruit.com/product/5217)
[Related Guides to the Product](https://learn.adafruit.com/products/5217/guides)
![Angled shot of thin, rectangular Bluetooth LED driver board.](https://cdn-shop.adafruit.com/640x480/5217-07.jpg)

# Wirelessly Code your Bluetooth Device with CircuitPython

## Preparing Chrome

To use the Code Editor, you will need to do a little bit of setup in Chrome. This involves setting a couple of flags to enable Web Bluetooth and should be done regardless of your device or OS. There are some basic instructions on the website when you first get there, but the instructions below cover those in a bit more detail.

The flags are mostly required for storing the bond and reconnecting because some of the functions fairly new. The exception is on Linux where the flags are required to connect at all. So if you are on a non-Linux platform and would rather not enable the flags, keep in mind that the connect button will not function and you will need to create a new Bluetooth pairing each time you connect.

![](https://cdn-learn.adafruit.com/assets/assets/000/106/451/medium800/circuitpython_Screenshot_from_2021-11-12_11-43-18.png?1636746256)

In the address bar for Chrome, type **chrome://flags** and press enter. This will take you to the internal Chrome flags settings. In the search box, type in **enable-experimental-web-platform-features** and you should see only one result.

![](https://cdn-learn.adafruit.com/assets/assets/000/088/946/medium800/sensors_chrome_flags_experimental.png?1583355336)

Change **disabled** to **enabled**.

![](https://cdn-learn.adafruit.com/assets/assets/000/088/947/medium800/sensors_chrome_flags_restart.png?1583355433)

In the search box, type in **enable-web-bluetooth-new-permissions-backend** and you should again see only one result. Change the setting to **Enabled** and click the **Relaunch** button.

![](https://cdn-learn.adafruit.com/assets/assets/000/106/450/medium800/circuitpython_Screenshot_from_2021-11-12_08-53-08.png?1636736695)

That's it! You should be ready to go.

# Wirelessly Code your Bluetooth Device with CircuitPython

## Device Setup

In order to connect, first make sure you are running the [latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board. &nbsp;You will need to be running **CircuitPython 7.1.0-beta.0** or later.&nbsp;

Once you have that installed, head on over to [https://code.circuitpython.org](https://code.circuitpython.org).

## Bluetooth Advertising Mode

Before connecting, you will need to place the device in Bluetooth Advertising Mode. This allows devices to see the Bluetooth device. When you power up the device, pay attention to the lights. It should show a solid red light, followed by a blinking yellow light, and then a blinking blue light. When the blinking blue light appears, press the reset button.

You should see the lights go through the same sequence except this time the blue light should be solid. Be sure to place the device in fairly close proximity to the computer or mobile device or it may not show up.

![](https://cdn-learn.adafruit.com/assets/assets/000/106/458/medium800thumb/circuitpython_bluetooth_pairing.jpg?1636757543)

## Connecting a New Device for the First Time

The first time you connect, it you will need to create a bond with the device. This allows it to access the files and stores the device information in Chrome.

### Android Devices

At this time, only Android devices with BLE hardware running a more recent version of the operating system such as 6.0 or later will work. If your device meets those requirements and once you have enabled the options in Chrome, the connection steps are the same as Chrome on Linux and macOS.

### Chrome on macOS and Linux

With macOS or Linux, the Code Editor should work without additional modification. Just click the **Request Bluetooth Device** button, select the device from the list, and click **Pair**. The **Bond Bluetooth Device** button should turn purple after a moment and you can click that.

![](https://cdn-learn.adafruit.com/assets/assets/000/106/460/medium800/circuitpython_Screenshot_from_2021-11-12_16-28-47.png?1636763363)

### Chrome on Windows

Chrome for windows has a known bug where if you attempt to connect the bluetooth device directly through the browser, it will have errors connecting.

Warning: 

To work around this, first go to the Bluetooth Devices settings. You can get there by going to **Settings,**  **Devices** , and make sure you are on the **Bluetooth & other devices** tab.

![circuitpython_2021-11-12_11_30_22-Settings.png](https://cdn-learn.adafruit.com/assets/assets/000/106/452/medium640/circuitpython_2021-11-12_11_30_22-Settings.png?1636751012)

Click **Add Bluetooth or other device**.

![circuitpython_2021-11-12_11_32_03-Settings.png](https://cdn-learn.adafruit.com/assets/assets/000/106/454/medium640/circuitpython_2021-11-12_11_32_03-Settings.png?1636751148)

When the dialog comes up, choose **Bluetooth**.

![circuitpython_2021-11-12_11_32_57-Add_a_device.png](https://cdn-learn.adafruit.com/assets/assets/000/106/455/medium640/circuitpython_2021-11-12_11_32_57-Add_a_device.png?1636751193)

Your device may appear as **CIRC** or **CIRPY** or something similar. Click the device to connect. If you don't see it, make sure it has the required version of CircuitPython, is in Bluetooth Advertising mode, and is close enough to the computer.&nbsp;

![circuitpython_2021-11-12_11_56_58-Add_a_device.png](https://cdn-learn.adafruit.com/assets/assets/000/106/456/medium640/circuitpython_2021-11-12_11_56_58-Add_a_device.png?1636751229)

![circuitpython_2021-11-12_11_58_59-Add_a_device.png](https://cdn-learn.adafruit.com/assets/assets/000/106/457/medium640/circuitpython_2021-11-12_11_58_59-Add_a_device.png?1636751238)

Once you do that, you should be able to connect using the **Connect Button** in the upper righthand corner in chrome.

![circuitpython_2021-11-15_09_26_09-CircuitPython_WebBluetooth_Editor.png](https://cdn-learn.adafruit.com/assets/assets/000/106/517/medium640/circuitpython_2021-11-15_09_26_09-CircuitPython_WebBluetooth_Editor.png?1636997297)

## Reconnecting

Once you have connected a device, Chrome saves the Bluetooth connection information for that device. To reconnect, make sure your device is in Bluetooth Advertising mode and just click the **Connect Button** in the upper righthand corner.

![](https://cdn-learn.adafruit.com/assets/assets/000/106/461/medium800/circuitpython_Connect.png?1636763566)

## Troubleshooting Connection Issues

Unfortunately connecting with Bluetooth the first time doesn't always go so smoothly and can involve several attempts before it successfully pairs and shows you the document. Also, Web Bluetooth in general can be a little finicky at times.

Here are a few things to try if you are having trouble connecting:

- Try reloading the web page.
- Restart the device and put into advertising mode again.
- Try removing any existing pairings from the Operating System Bluetooth Devices.
- Try connecting through your Operating System Bluetooth Devices first.
- Try restarting your Browser.
- Try going to chrome://bluetooth-internals, choose the **devices** tab, and removing any existing devices in there.
- In Chrome, go to **Settings&nbsp;**** → Privacy and Security → Site Settings → Additional Permissions → Bluetooth Devices **and make sure** Sites can ask to connect to Bluetooth devices** is selected. Also, try removing any devices from here.
- Open up the Console through the toolbar with **3 Dots Menu**  **→**  **More Tools** &nbsp; **→**  **Developer Tools** and see if there are any messages that might provide more clues.

The code editor is relatively new and there may be some bugs, so if you find a reproducible bug, you can always open a new issue at [https://github.com/circuitpython/web-editor](https://github.com/circuitpython/web-editor).

# Wirelessly Code your Bluetooth Device with CircuitPython

## Usage

Once you are connected, using the File Editor is pretty straightforward. Currently you can only edit one file at a time to reduce the design complexity.

## Editor Mode

The editor mode is the main mode you will be using the CircuitPython Code Editor in. This will allow you to do most of the operations you need to to edit and write new code. When you first open the editor, it will attempt to load **code.py** from the root directory of the circuit board. If the file is not found, it will create a new unsaved document for you to edit.

![](https://cdn-learn.adafruit.com/assets/assets/000/106/462/medium800/circuitpython_Screenshot_from_2021-11-12_16-47-45.png?1636764732)

### New File
This option will close any files you are currently working on after making sure they are saved and create a brand new file.

![circuitpython_Screenshot_from_2021-11-12_16-47-45.png](https://cdn-learn.adafruit.com/assets/assets/000/106/467/medium640/circuitpython_Screenshot_from_2021-11-12_16-47-45.png?1636765164)

### Open File
This option will allow you to open an existing file to work on editing. The code editor tries to determine if the file you are trying to open is a text file or binary file based on the file extension.

![circuitpython_Screenshot_from_2021-11-12_16-47-45.png](https://cdn-learn.adafruit.com/assets/assets/000/106/468/medium640/circuitpython_Screenshot_from_2021-11-12_16-47-45.png?1636765225)

### Save As
This will allow you to choose a filename to save your code as. If the file already exists, it will prompt you if you want to overwrite the file. Keep in mind that you can name it anything you want, but it naming it with an unexpected extension could have unexpected results.

![circuitpython_Screenshot_from_2021-11-12_16-47-45.png](https://cdn-learn.adafruit.com/assets/assets/000/106/469/medium640/circuitpython_Screenshot_from_2021-11-12_16-47-45.png?1636765270)

### Save + Run
This options will save your file. If you are working on a file, it will prompt you to choose a filename and location. If you are working on **code.py** , it will send a **Control+C** and **Control+D** command to restart CircuitPython. If you are working on another filename, it will attempt to import the filename through the REPL.

![circuitpython_Screenshot_from_2021-11-12_16-47-45.png](https://cdn-learn.adafruit.com/assets/assets/000/106/470/medium640/circuitpython_Screenshot_from_2021-11-12_16-47-45.png?1636765306)

## Serial Mode

In serial mode, you can see the output of the CircuitPython device and even enter commands through the REPL.

![](https://cdn-learn.adafruit.com/assets/assets/000/106/463/medium800/circuitpython_Screenshot_from_2021-11-12_16-47-36.png?1636764746)

### Restart
This button will send a Control+C and Control+D to the device in order to soft restart CircuitPython.

![circuitpython_Screenshot_from_2021-11-12_16-47-36.png](https://cdn-learn.adafruit.com/assets/assets/000/106/466/medium640/circuitpython_Screenshot_from_2021-11-12_16-47-36.png?1636765077)

## Mobile Sizing
When the window is small enough, a mobile menu will appear as 3 bars in order to reduce the amount of screen real estate that the editor takes up. Additionally, only the filename and not the full path will be displayed.

![circuitpython_Screenshot_from_2021-11-12_16-50-40.png](https://cdn-learn.adafruit.com/assets/assets/000/106/464/medium640/circuitpython_Screenshot_from_2021-11-12_16-50-40.png?1636764931)

Clicking on the menu will display the editor functions that were hidden allowing for full functionality even in mobile mode.

![circuitpython_Screenshot_from_2021-11-12_16-51-11.png](https://cdn-learn.adafruit.com/assets/assets/000/106/465/medium640/circuitpython_Screenshot_from_2021-11-12_16-51-11.png?1636764986)

That's it! Enjoy using and if you would like to contribute to improving the editor, you can submit a Pull Request to [https://github.com/circuitpython/web-editor](https://github.com/circuitpython/web-editor).


## Featured Products

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

In Stock
[Buy Now](https://www.adafruit.com/product/4500)
[Related Guides to the Product](https://learn.adafruit.com/products/4500/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...

In Stock
[Buy Now](https://www.adafruit.com/product/4516)
[Related Guides to the Product](https://learn.adafruit.com/products/4516/guides)
### 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 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...

In Stock
[Buy Now](https://www.adafruit.com/product/4062)
[Related Guides to the Product](https://learn.adafruit.com/products/4062/guides)
### Adafruit LED Glasses Driver - nRF52840 Sensor Board

[Adafruit LED Glasses Driver - nRF52840 Sensor Board](https://www.adafruit.com/product/5217)
This board is designed to be a thin, Bluetooth®-enabled driver board for our [Adafruit LED Glasses](https://www.adafruit.com/product/5210) RGB LED matrix. That said, it's a perfectly good stand-alone development board for the Nordic nRF52840 chipset, with a very slim design,...

In Stock
[Buy Now](https://www.adafruit.com/product/5217)
[Related Guides to the Product](https://learn.adafruit.com/products/5217/guides)
### BBC micro:bit v2

[BBC micro:bit v2](https://www.adafruit.com/product/4781)
Meet the new **BBC micro:bit v2** - Upgraded with a powerful new processor that has tons more capability and also adds more sensing with a new speaker and microphone!

The latest micro:bit will fit right into your existing lessons and materials; all the...

In Stock
[Buy Now](https://www.adafruit.com/product/4781)
[Related Guides to the Product](https://learn.adafruit.com/products/4781/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)
- [Adafruit EyeLights LED Glasses and Driver](https://learn.adafruit.com/adafruit-eyelights-led-glasses-and-driver.md)
- [BLE Buzzy Box](https://learn.adafruit.com/ble-buzzy-box.md)
- [LED Bullwhip with Motion & Sound Reactivity](https://learn.adafruit.com/led-bullwhip.md)
- [How to Fuse Motion Sensor Data into AHRS Orientation (Euler/Quaternions)](https://learn.adafruit.com/how-to-fuse-motion-sensor-data-into-ahrs-orientation-euler-quaternions.md)
- [Circuit Playground Bluefruit NeoPixel Animation and Color Remote Control](https://learn.adafruit.com/circuit-playground-bluefruit-neopixel-animation-and-color-remote-control.md)
- [Karel The Robot In CircuitPython](https://learn.adafruit.com/karel-the-robot-in-circuitpython.md)
- [Circuit Playground Bluefruit Quick Draw Duo](https://learn.adafruit.com/circuit-playground-bluefruit-quick-draw-duo.md)
- [Wearable Continuous Temperature Monitor with Adafruit IO](https://learn.adafruit.com/wearable-temperature-monitor.md)
- [LIS3MDL Triple-axis Magnetometer](https://learn.adafruit.com/lis3mdl-triple-axis-magnetometer.md)
- [Multi-tasking with CircuitPython](https://learn.adafruit.com/multi-tasking-with-circuitpython.md)
- [PyLeap device enabled - In Rainbows](https://learn.adafruit.com/pyleap-device-enabled-in-rainbows.md)
- [Bluetooth Restroom Key Proximity Tracker](https://learn.adafruit.com/bluetooth-restroom-key-proximity-tracker.md)
- [Pulse Oximeter Wireless Data Logger](https://learn.adafruit.com/pulse-oximeter-wireless-data-logger.md)
- [DIY Darksaber Build - 3D Print with PropMaker FeatherWing and BLE](https://learn.adafruit.com/ble-darksaber-propmaker.md)
- [PyLeap CLUE Sensor Plotter](https://learn.adafruit.com/pyleap-clue-sensor-plotter.md)
- [Frozen-Inspired Animated Pendant with Temperature Sensing](https://learn.adafruit.com/frozen-gizmo-pendant-with-temperature-sensing.md)
