# CircusPython: Jump through Hoops with CircuitPython Bluetooth LE

## Overview

Here's a simple demonstration project to get you started with Bluetooth Low Energy (BLE) support in CircuitPython. Blinka jumps through a NeoPixel ring of fire, using a servo. It's all controlled wirelessly via the Adafruit Bluefruit LE Connect app from your phone or tablet, using a Feather nRF52840 Express and a CRICKIT FeatherWing.

You can adapt and expand upon this code for your own projects. Add more servos, add sound, whatever you want. It's up to you!

![](https://cdn-learn.adafruit.com/assets/assets/000/070/290/medium800thumb/micropython___circuitpython_circuspython-480x360-optimized.jpg?1548880939)

## Parts
### Part: Feather nRF52840 Express
quantity: 1
A Feather board that supports BLE, running CIrcuitPython.
[Feather nRF52840 Express](https://www.adafruit.com/product/4062)

### Part: Adafruit CRICKIT FeatherWing
quantity: 1
Use with any Feather board
[Adafruit CRICKIT FeatherWing](https://www.adafruit.com/product/3343)

### Part: 5V 2A (2000mA) switching power supply - UL Listed
quantity: 1
You'll need this or another 5V power supply with a 2.1mm plug for the CRICKIT.
[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)

### Part: NeoPixel Ring - 24 x 5050 RGB LED with Integrated Drivers
quantity: 1
A NeoPixel ring for light
[NeoPixel Ring - 24 x 5050 RGB LED with Integrated Drivers](https://www.adafruit.com/product/1586)

### Part: Small Alligator Clip Test Leads
quantity: 1
Cut these in half and solder one end to the NeoPixel Ring terminals.
[Small Alligator Clip Test Leads](https://www.adafruit.com/product/1008)

### Part: Male/Male Jumper Wires
quantity: 1
Connect from the CRICKIT board to the alligator leads on the NeoPixel ring.
[Male/Male Jumper Wires](https://www.adafruit.com/product/758)

### Part: Standard servo - TowerPro SG-5010 - 5010
quantity: 1
A smaller servo would probably work too.
[Standard servo - TowerPro SG-5010 - 5010](https://www.adafruit.com/product/155)

## Other Materials and Tools

- A wood base, about a foot square.
- A scrap of wood, for mounting the servo. I used wood screws to hold the servo on by one set of its ears.
- Foam core board, for mounting the front panel.
- A rod, such as a piece of coat hanger, a chopstick, or even a straw. I used a thin piece of metal salvaged from a discarded windshield wiper, so I could bend one end to mount Blinka more easily.
- Clear packing tape and office tape.
- Hobby knife.
- Glue stick.
- Wire strippers.

## Demonstration during Adafruit Show & Tell
https://youtu.be/Sm09-NTIsfY?t=840

# CircusPython: Jump through Hoops with CircuitPython Bluetooth LE

## Build the Circus

This project was built as quick demonstration of Bluetooth LE support in CircuitPython in about 90 minutes. So I cut a lot of corners on the construction, using tape liberally.

![micropython___circuitpython_circuspython-sideview.jpg](https://cdn-learn.adafruit.com/assets/assets/000/070/281/medium640/micropython___circuitpython_circuspython-sideview.jpg?1548871007)

## Make the Front Panel

I used Microsoft PowerPoint for placing and scaling clip art and Adafruit graphics. After printing it on cardstock, I cut a hole just large enough for the NeoPixel ring by tracing around it and then using a hobby knife. Here is the PowerPoint file, and also PDF, and PNG versions, but you can be creative and make your own!

![](https://cdn-learn.adafruit.com/assets/assets/000/070/248/medium800/micropython___circuitpython_CircusPython_half.png?1548802595)

[CircusPython.pptx](https://cdn-learn.adafruit.com/assets/assets/000/070/158/original/CircusPython.pptx?1548728474)
[CircusPython.pdf](https://cdn-learn.adafruit.com/assets/assets/000/070/159/original/CircusPython.pdf?1548728486)
[CircusPython.png](https://learn.adafruit.com/assets/70160)
## Wire the NeoPixel Ring
Next, wire alligator clips to the NeoPixel ring. Cut a **red** , a **black** , and some other color alligator clip lead in half. Strip a small amount of insulation off the ends, enough to stick through the connection holes on the NeoPixel ring. Twist the stranded ends. Put the black wire in a&nbsp; **GND** &nbsp;hole, the red wire in a&nbsp; **PWR +5V** &nbsp;hole, and the other color in the&nbsp; **DATA INPUT** &nbsp;hole. Bend the wires over, solder, and trim.

&nbsp;

The NeoPixel ring pictured has the wires coming out the front of the ring. This was what I had on hand, but for this project, coming out the back is better.

&nbsp;

Alternatively, you can solder single pin headers to the holes on the ring. Pictured is a smaller ring using this technique.

![micropython___circuitpython_neopixel-ring.jpg](https://cdn-learn.adafruit.com/assets/assets/000/070/161/medium640/micropython___circuitpython_neopixel-ring.jpg?1548728912)

![micropython___circuitpython_neopixel-ring-with-headers.jpg](https://cdn-learn.adafruit.com/assets/assets/000/070/163/medium640/micropython___circuitpython_neopixel-ring-with-headers.jpg?1548729045)

## Mount the Parts

Tape the front panel to the bottom of the board, using one piece of tape on the front wrapped around to the bottom fo the board, and one on the back attaching the panel to the top of the board.

Put the NeoPixel ring into the front panel hole from the back, and tape it there.

Fasten the servo to a scrap piece of wood by putting a couple of wood screws through its ears on one side. Then tape the scrap to the base with packing tape.

Fasten the CRICKIT to the base with hook-and-loop tape, screws, or double-sided sponge tape. I used hook-and-loop for easy removal.

Plug the servo into Servo **Port 1** on the CRICKIT, with the yellow wire pointing to the outside. Attach three jumper wires to the NeoPixel screw terminals on the CRICKIT. Connect a **red** one to **+5V** , a **black** one to **GND** , and some **other color** to the **signal pin** (the arrow). Connect the alligator clips to their appropriate colors

Dress the wiring with tape for neatness.

![](https://cdn-learn.adafruit.com/assets/assets/000/070/165/medium800/micropython___circuitpython_circuspython-parts.jpg?1548730149)

## Attach the Servo Arm

Before you attach the servo arm, you need to set the servo to 0 degrees. Your servo should have come with a variety of plastic "horns", with mounting screws and possibly small metal sleeves for the screws. Slip a horn onto the servo shaft without a screw and turn the shaft clockwise until it stops. Don't force it. There will be a little resistance, but if you're not sure, try going back and forth to feel how it moves.

Then take the rod mentioned in the parts list and tape it to the horn, so that it points through the front panel hole. Reposition the horn if necessary, and then screw it on. Adjust the length of the rod so it will clear the top of the hole when it moves up.

Now cut out a Blinka picture and attach it to the end of the rod with tape. The PowerPoint file below has several Blinka pictures in various sizes (you can adjust the sizes), or find one on the [Adafruit website](https://www.adafruit.com/).

![micropython___circuitpython_circuspython-back-view.jpg](https://cdn-learn.adafruit.com/assets/assets/000/070/167/medium640/micropython___circuitpython_circuspython-back-view.jpg?1548731424)

![micropython___circuitpython_circuspython-side-view.jpg](https://cdn-learn.adafruit.com/assets/assets/000/070/168/medium640/micropython___circuitpython_circuspython-side-view.jpg?1548731586)

[Blinka.pptx](https://cdn-learn.adafruit.com/assets/assets/000/070/166/original/Blinka.pptx?1548731270)
OK, you're ready to try out the program now!

# CircusPython: Jump through Hoops with CircuitPython Bluetooth LE

## CircuitPython Code

## Getting Familiar

CircuitPython is a programming language based on Python, one of the fastest growing programming languages in the world. It is specifically designed to simplify experimenting and learning to code on low-cost microcontroller boards. Here are some guides which cover the basics:

- [Welcome to CircuitPython!](https://learn.adafruit.com/welcome-to-circuitpython)
- [Introducing the Adafruit nRF52840 Feather](https://learn.adafruit.com/introducing-the-adafruit-nrf52840-feather)

Be sure you have the latest CircuitPython loaded onto your board per the second guide.

CircuitPython is easiest to use within the Mu Editor. If you haven't previously used Mu,&nbsp;[this guide will get you started](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor).

## Download Library Files

Plug your nRF Feather board into your computer via a USB cable. Please be sure the cable is a good power+data cable so the computer can talk to the board.

A new disk should appear in your computer's file explorer/finder called **CIRCUITPY**. This is the place we'll copy the code and code library. If you can only get a drive named **FTHR840BOOT** , load CircuitPython per the guide above.

Create a new directory on the&nbsp; **CIRCUITPY** drive named **lib**.

![](https://cdn-learn.adafruit.com/assets/assets/000/070/277/medium800/micropython___circuitpython_circus.png?1548864704)

Download the latest CircuitPython libraries to your computer using the green button below. **Match the library you get to the version of CircuitPython you are using**. Save to your computer's hard drive where you can find it.

[Download the latest CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest)
With your file explorer/finder, browse to the bundle and open it up. Copy the following folder from the library bundle to your&nbsp; **CIRCUITPY** &nbsp; **lib** &nbsp;directory you made earlier:

- **adafruit\_ble** (folder)
- **adafruit\_bluefruit\_connect** (folder)
- **adafruit\_crickit.mpy** (file)
- **adafruit\_motor** (folder)
- **adafruit\_seesaw** (folder)

All of the other necessary code is baked into CircuitPython!

![](https://cdn-learn.adafruit.com/assets/assets/000/070/278/medium800/micropython___circuitpython_circus2.png?1548864798)

## CircuitPython Program

Download the **circuit.py** program below and save it on the&nbsp; **CIRCUITPY** &nbsp;flash drive as **code.py**.&nbsp;As soon as CircuitPython restarts, the servo arm will move into position, away from the NeoPixel ring.

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

## How the Program Works

The first part of the program sets up a `UARTService`, which is a BLE service that wirelessly sends streams of characters between a BLE device and a client computer (which could be a phone or tablet). The program then starts advertising its UART service to anyone listening. The client computer receives the advertisement, and tells the user it's available. The user can then choose to connect as a client of the service.

One a connection is established, the program code waits for incoming command packets from the client, specifically either a `ColorPacket` or a `ButtonPacket`. When one arrives, the program either adjusts the NeoPixel color, or sees which button has been pressed: up-arrow or down-arrow. If it's a button press, the code moves the servo one degree at a time in the specified direction, until it hits a limit. During the servo movement, the code continues to call `sparkle()` so that the "fire" animation will not stop.

# CircusPython: Jump through Hoops with CircuitPython Bluetooth LE

## Wire the NeoPixel Ring

# CircusPython: Jump through Hoops with CircuitPython Bluetooth LE

## Control the Circus with the Bluefuit LE Connect App

## Download the App

To control the servo and NeoPixels in CircusPython from a client computer (phone or tablet), you use the Adafruit&nbsp;[Bluefruit LE Connect App](https://learn.adafruit.com/bluefruit-le-connect-for-ios). Install it from the [Apple App Store](https://itunes.apple.com/us/app/adafruit-bluefruit-le-connect/id830125974) or [Google Play App Store](https://play.google.com/store/apps/details?id=com.adafruit.bluefruit.le.connect).

## Connect to CircusPython

Start the main program running on your CircusPython project. Then start up the Bluefruit LE Connect app, and make sure it's in Central Mode (left button on the bottom).&nbsp; When you start the app, you should see a device named **CIRCU** or **CIRCUITPY**. If there's a long list of devices, you can shorten it by turning on the " **Must have UART Service**" switch.

To connect to CircusPython, touch the **Connect** button. You should see " **Connecting**" and then " **Discovering Services**".

## Troubleshooting

If you don't see **CIRCU** or **CIRCUITPY** right away, try pulling down to refresh. If that doesn't work, try turning Bluetooth off and back on on your phone or tablet and restarting the app.

![](https://cdn-learn.adafruit.com/assets/assets/000/070/238/medium800/micropython___circuitpython_bluefruit-connect_half.png?1548800264)

## Device Menu

After you connect, you'll see a menu of how you can interact with the device.&nbsp;Choose **Controller**.

![](https://cdn-learn.adafruit.com/assets/assets/000/070/239/medium800/micropython___circuitpython_bluefruit-connect-menu_half.png?1548800333)

## Controller Menu

After you choose Controller, you'll see another screen with more choices. **Control Pad** and **Color Picker** are used for this project.

![](https://cdn-learn.adafruit.com/assets/assets/000/070/246/medium800/micropython___circuitpython_bluefruit-connect-controller-menu_half.png?1548801277)

## Move the Servo Arm

Here's the **Control Pad** screen. Use the **Up** and **Down** buttons to move the servo arm up and down and make Blinka jump through the NeoPixel ring.

![](https://cdn-learn.adafruit.com/assets/assets/000/070/241/medium800/micropython___circuitpython_bluefruit-connect-control-pad_half.png?1548800721)

## Change Color

To change the color of the NeoPixels, use the **Color Picker** screen. Choose a color and press **Send Selected Color**.

![](https://cdn-learn.adafruit.com/assets/assets/000/070/242/medium800/micropython___circuitpython_bluefruit-connect-color-picker_half.png?1548800782)

## Wow!

That's it! This simple project is only a jumping-off point. Add more servos or other things, and use the other buttons ([see the codes for the other buttons](https://learn.adafruit.com/bluefruit-le-connect-for-ios/controller#control-pad-8-11)) to control them.


## Featured Products

### 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 CRICKIT FeatherWing for any Feather

[Adafruit CRICKIT FeatherWing for any Feather](https://www.adafruit.com/product/3343)
Sometimes we wonder if robotics engineers ever watch movies. If they did, they'd know that making robots into servants always ends up in a robot rebellion. Why even go down that path? Here at Adafruit, we believe in making robots our&nbsp; **friends!**

So if you find...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3343)
[Related Guides to the Product](https://learn.adafruit.com/products/3343/guides)
### 5V 2A (2000mA) switching power supply - UL Listed

[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)
This is an FCC/CE certified and UL listed power supply. Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 2000mA. 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one...

In Stock
[Buy Now](https://www.adafruit.com/product/276)
[Related Guides to the Product](https://learn.adafruit.com/products/276/guides)
### NeoPixel Ring - 24 x 5050 RGB LED with Integrated Drivers

[NeoPixel Ring - 24 x 5050 RGB LED with Integrated Drivers](https://www.adafruit.com/product/1586)
Round and round and round they go! 24 ultra bright smart LED NeoPixels are arranged in a circle with 2.6" (66mm) outer diameter. The rings are 'chainable' - connect the output pin of one to the input pin of another. Use only one microcontroller pin to control as many as you can...

In Stock
[Buy Now](https://www.adafruit.com/product/1586)
[Related Guides to the Product](https://learn.adafruit.com/products/1586/guides)
### Standard servo - TowerPro SG-5010

[Standard servo - TowerPro SG-5010](https://www.adafruit.com/product/155)
This high-torque standard servo can rotate approximately 180 degrees (90 in each direction). You can use any servo code, hardware, or library to control these servos. Good for beginners who want to make stuff move without building a motor controller with feedback & gearbox. Comes with 3...

Out of Stock
[Buy Now](https://www.adafruit.com/product/155)
[Related Guides to the Product](https://learn.adafruit.com/products/155/guides)
### Small Alligator Clip Test Lead (set of 12)

[Small Alligator Clip Test Lead (set of 12)](https://www.adafruit.com/product/1008)
Connect this to that without soldering using these handy mini alligator clip test leads. 15" cables with alligator clip on each end, color coded. You get 12 pieces in 6 colors. Strong and grippy, these always come in handy! We often use these in conjunction with a multimeter so we...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1008)
[Related Guides to the Product](https://learn.adafruit.com/products/1008/guides)
### Premium Male/Male Jumper Wires - 40 x 6" (150mm)

[Premium Male/Male Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/758)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on either end and fit cleanly next to each other...

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

## Related Guides

- [Introducing the Adafruit nRF52840 Feather](https://learn.adafruit.com/introducing-the-adafruit-nrf52840-feather.md)
- [A Logger for CircuitPython](https://learn.adafruit.com/a-logger-for-circuitpython.md)
- [3D Printed Camera LED Ring](https://learn.adafruit.com/3d-printed-camera-led-ring.md)
- [Mario Magic Wand](https://learn.adafruit.com/mario-magic-wand.md)
- [Bluetooth Controlled NeoPixel Lightbox](https://learn.adafruit.com/bluetooth-neopixel-lightbox.md)
- [Pulse Oximeter Wireless Data Logger](https://learn.adafruit.com/pulse-oximeter-wireless-data-logger.md)
- [Celebration Spectacles](https://learn.adafruit.com/celebration-spectacles.md)
- [Getting Started with CircuitPython and Bluetooth Low Energy](https://learn.adafruit.com/circuitpython-nrf52840.md)
- [The PICsellator](https://learn.adafruit.com/the-picsellator.md)
- [CircuitPython 101: State Machines, Two Ways](https://learn.adafruit.com/circuitpython-101-state-machines.md)
- [BLE HID Keyboard Buttons with CircuitPython](https://learn.adafruit.com/ble-hid-keyboard-buttons-with-circuitpython.md)
- [UFO Drone](https://learn.adafruit.com/ufo-drone.md)
- [NeoPixels on Raspberry Pi](https://learn.adafruit.com/neopixels-on-raspberry-pi.md)
- [Unibeam](https://learn.adafruit.com/unibeam.md)
- [Neopixel Crystal Chandelier with CircuitPython Animations and Speed Control](https://learn.adafruit.com/neopixel-crystal-chandelier-with-circuitpython-animations-and-speed-control.md)
- [BLE Light Switch with Feather nRF52840 and Crickit](https://learn.adafruit.com/bluetooth-light-switch-with-crickit-and-nrf52840.md)
