Overview

You can build a wireless remote control RGB LED NeoPixel color mixer using two Circuit Playground Bluefruit boards and some slide potentiometers. Using Bluetooth LE, the boards can communicate wirelessly with no need for a computer or mobile phone or tablet!

Thanks to the Adafruit Bluefruit Connect and BLE libraries in CircuitPython, setup and coding are incredibly simple. You can get started quickly and then extend this code to all sorts of other remote projects!

Parts

First of all, you'll need two Circuit Playground Bluefruit boards:

Circuit Playground Bluefruit - ALPHA - Bluetooth Low Energy

PRODUCT ID: 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...
OUT OF STOCK
2 x Circuit Playground Bluefruit BLE
ALPHA - Bluetooth Low Energy

To control the color settings, you'll need three slide potentiometers. These short ones work on a breadboard quite well, any longer and you'll need to come up with more involved solutions for mounting.

Slide Potentiometer with Plastic Knob - 35mm Long - 10KΩ

PRODUCT ID: 4271
Slip slidin' away Slip slidin' away You know the nearer your resistance The more you're slip slidin' awayIf you're...
OUT OF STOCK
3 x Slide Potentiometer - 35mm Long
10KΩ with Plastic Cap

Half Size Breadboard + 78 Piece 22AWG Jumper Wire Bundle

PRODUCT ID: 3314
This is a cute half-size breadboard with an assortment of small jumper wires, great for prototyping. Breadboard is 2.2" x 3.4" (5.5 cm x 8.5 cm) with a standard double-strip...
$9.95
IN STOCK

Or, if you already have jumper wire:

Half-size breadboard

PRODUCT ID: 64
This is a cute half size breadboard, good for small projects. It's 2.2" x 3.4" (5.5 cm x 8.5 cm) with a standard double-strip in the middle and two power rails on both...
OUT OF STOCK

Small Alligator Clip to Male Jumper Wire Bundle - 6 Pieces

PRODUCT ID: 3448
When working with unusual non-header-friendly surfaces, these handy cables will be your best friends! No longer will you have long, cumbersome strands of alligator clips. These...
$3.95
IN STOCK

Optional

Adafruit Circuit Playground Express Enclosure

PRODUCT ID: 3915
We've got nice cases for many of our beloved boards, but the Circuit Playground Express has been left out of couture enclosure...
$4.95
IN STOCK

Fully Reversible Pink/Purple USB A to micro B Cable - 1m long

PRODUCT ID: 4111
This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also fully reversible! That's right, you will save seconds a day by...
$3.95
IN STOCK

CircuitPython on Circuit Playground Bluefruit

Install or Update CircuitPython

Follow this quick step-by-step to install or update CircuitPython on your Circuit Playground Bluefruit.

Circuit Playground Bluefruit requires CircuitPython 5.0+. CircuitPython 5.0 is currently in alpha. This means we're still working on adding features and fixing issues. If you run into any problems, please contact us on the Discord at https://adafru.it/discord in the #help-with-circuitpython channel, or file an issue on GitHub at https://github.com/adafruit/circuitpython/issues.
In addition, if you want to use the Bluetooth (BLE) features of this board, you'll need the pre-release version of the adafruit_ble library. Choose the latest pre-release version from https://github.com/adafruit/Adafruit_CircuitPython_BLE/releases

Click the link above and download the latest UF2 file

Download and save it to your Desktop (or wherever is handy)

Plug your Circuit Playground Bluefruit into your computer using a known-good data-capable USB cable.

A lot of people end up using charge-only USB cables and it is very frustrating! So make sure you have a USB cable you know is good for data sync.

Double-click the small Reset button in the middle of the CPB (indicated by the red arrow in the image). The ten NeoPixel LEDs will all turn red, and then will all turn green. If they turn all red and stay red, check the USB cable, try another USB port, etc. The little red LED next to the USB connector will pulse red - this is ok!

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

(If double-clicking doesn't do it, try a single-click!)

You will see a new disk drive appear called CPLAYBTBOOT.

 

 

 

Drag the adafruit_circuitpython_etc.uf2 file to CPLAYBTBOOT.

The LEDs will turn red. Then, the CPLAYBTBOOT drive will disappear and a new disk drive called CIRCUITPY will appear.

That's it, you're done! :)

Code the Color Remote with CircuitPython

Libraries

Once you've gotten CircuitPython onto your Circuit Playground Bluefruit boards, it's time to add some libraries. You can follow this guide page for the basics of downloading and transferring libraries to the board.

From the library bundle you downloaded in that guide page, transfer the following libraries onto the CPB boards' /lib directories:

  • neopixel.mpy
  • adafruit_bluefruit_connect

We also need to get a specific version of the adafruit_ble library that is not yet in the bundle as of this writing. You can get this by going here and downloading the adafruit-circuitpython-ble-5.x-mpy-2.0.1-alpha.2.zip file.

Unzip that file and copy the adafruit_ble folder to your CPB boards' /lib directories.

Text Editor

Adafruit recommends using the Mu editor for using your CircuitPython code with the Circuit Playground Bluefruit boards. You can get more info in this guide.

Alternatively, you can use any text editor that saves files.

Central

Next we'll code the CPB that will act as the Central/client device. This is the one that will have the slide pots on it and will send out RGB color data packets to the peripheral device.

Copy the code below and paste it into Mu. Then, save it to your CPB as code.py.

"""
Demonstration of a Bluefruit BLE Central/client. Connects to the first BLE UART peripheral it finds.
Sends Bluefruit ColorPackets, read from three potentiometers, to the peripheral.
"""

import time

import board
from analogio import AnalogIn

#from adafruit_bluefruit_connect.packet import Packet
# Only the packet classes that are imported will be known to Packet.
from adafruit_bluefruit_connect.color_packet import ColorPacket

from adafruit_ble.scanner import Scanner
from adafruit_ble.uart_client import UARTClient

def scale(value):
    """Scale an value from 0-65535 (AnalogIn range) to 0-255 (RGB range)"""
    return int(value / 65535 * 255)

scanner = Scanner()
uart_client = UARTClient()

a3 = AnalogIn(board.A4)
a4 = AnalogIn(board.A5)
a5 = AnalogIn(board.A6)

while True:
    uart_addresses = []
    # Keep trying to find a UART peripheral
    while not uart_addresses:
        uart_addresses = uart_client.scan(scanner)
    uart_client.connect(uart_addresses[0], 5)

    while uart_client.connected:
        r = scale(a3.value)
        g = scale(a4.value)
        b = scale(a5.value)

        color = (r, g, b)
        print(color)
        color_packet = ColorPacket(color)
        try:
            uart_client.write(color_packet.to_bytes())
        except OSError:
            pass
        time.sleep(0.3)

Peripheral

The second CPB will act as a peripheral device. It will receive the RGB color data packets from the client and update the NeoPixel color to match the data.

Copy the code below and paste it into a new document in Mu, then save it to your second CPB as code.py.

"""
Used along with cpb_remote_color_client.py. Receives Bluefruit LE ColorPackets from a central,
and updates NeoPixels to show the history of the received packets.
"""

import board
import neopixel

from adafruit_ble.uart_server import UARTServer
from adafruit_bluefruit_connect.packet import Packet
# Only the packet classes that are imported will be known to Packet.
from adafruit_bluefruit_connect.color_packet import ColorPacket

uart_server = UARTServer()

NUM_PIXELS = 10
np = neopixel.NeoPixel(board.NEOPIXEL, NUM_PIXELS, brightness=0.1)
next_pixel = 0

def mod(i):
    """Wrap i to modulus NUM_PIXELS."""
    return i % NUM_PIXELS

while True:
    # Advertise when not connected.
    uart_server.start_advertising()
    while not uart_server.connected:
        pass

    while uart_server.connected:
        packet = Packet.from_stream(uart_server)
        if isinstance(packet, ColorPacket):
            print(packet.color)
            np[next_pixel] = packet.color
            np[mod(next_pixel + 1)] = (0, 0, 0)
        next_pixel = (next_pixel + 1) % NUM_PIXELS

Next we'll assemble the parts to use our color mixer!

Build the Color Remote

I love using slide potentiometers (a.k.a. faders) for this type of project, because at a glance you can tell how much of each color is selected. One problem that can arise, however, when using slide pots, is that they don't usually fit to easily on a breadboard or perma proto board. These adorable little 35mm faders solve this problem! Since the bottom pin that is labeled "3" is the ground pin, all of the faders can share the common ground rail on the breadboard!

Slide Pots

Each slide potentiometer will act as a voltage divider, with the Circuit Playground Bluefruit analog pins reading the wiper's varying output.

The pin assignments are as follows:

  • Pin 1 = 3.3VDC
  • Pin 2 = wiper (to analog input)
  • Pin 3 = ground

Insert the three slide potentiometers into the breadboard as shown. You want the pin 3 legs of all three pots to be placed into the ground rail (next to the blue line).

Insert pins 1 and 2 so there is a free row of breadboard pins above them, this is where you'll make the wired connections to the CPB.

 

Wiring to Voltage

Use three small jumper wires (sometimes called "staples") to connect the pin 1 of each slide pot to the red +V rail of the breadboard as shown here. Looking from the top down, pin 1 is the pin on the left at the top of each slide pot.

Connections to Circuit Playground Bluefruit

Now we can use alligator clip leads with male header pins to connect the sliders to the CPB.

Insert the red lead into the breadboard's top red +V rail.

Insert the black lead into the breadboard's bottom black ground rail.

Insert the yellow lead into the left slider's pin 2 column on the breadboard.

Insert the green lead into the middle slider's pin 2 column on the breadboard.

Insert the blue lead into the right slider's pin 2 column on the breadboard.

Now, you can connect the alligator clips to the associated pads on the Circuit Playground Bluefruit:

  • red to 3.3V
  • black to GND
  • yellow to A4
  • green to A5
  • blue to A6

Power

You can now power up the Circuit Playground Bluefruit boards -- here I've used 3.7VDC LiPoly batteries plugged into the battery JST-SH ports. You can also use AA or AAA battery packs, or power over the USB port.

Remote Color Mixing

After a moment, the two boards will start up, and the mixer CPB will begin sending Bluetooth LE packets containing RGB color data based on the slider positions. The other CPB will listen for those packets and light up its NeoPixels in accordance with the RGB values.

Here you can see each slider used individually for pure red, green, and blue values, and then a mix of partial red and blue for a pink color. Try different combinations to mix your own colors!

This guide was first published on Oct 22, 2019. It was last updated on Oct 22, 2019.