For social distant trick or treating, we thought we’d make a BLE controlled servo claw using the Circuit Playground Bluefruit.

We put our project on this flying ghost prop we got from our local halloween shop.

It moves up and down along a rope that's strung across our porch.

We tied one end to a tree and the other to a lamp post on the side of the house.

The servo is triggered using our mobile phone with the Bluefruit connect app.

This is a 3d printed claw gripper that we designed to hold a small bag of candy.

We think this is a fun way to give out candy that could be adapted for all sorts of projects.

The BLE libraries for Circuit Python makes it easy to control servos using the Bluefruit app.

In the code, the up and down buttons are set up to trigger the servo when they’re pressed.

The angle of the servo is tuned for the gripper so it doesn’t stress out the motor.

In the Bluefruit app you can press the up and down buttons to open and close the gripper.

We think this is a quick and easy way to make a BLE controlled servo project.

Parts

Circuit Playground Bluefruit is our third board in the Circuit Playground series, another step towards a perfect introduction to electronics and programming. We've...
$24.95
In Stock
Add more power to your robot with this metal-geared MG90D servo. The tiny little servo can rotate approximately 90 degrees (45 in each direction) and works just like the standard...
$9.95
In Stock
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This...
$7.95
In Stock
Totaling 420 pieces, this M3 Screw Set is a must-have for your workstation. You'll have enough screws, nuts, and hex standoffs to fuel...
$16.95
In Stock
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

 

 

1 x Small Flying Ghost
Small Flying Ghost Decoration
4 x M3x10mm Screw
M3x10mm Screw
1 x M3x6mm Screw + Nut
M3x6mm Screw
2 x M2.5 x 6mm Screw
M2.5 x 6mm Screw
1 x 1.25mm Pitch 3-pin Cable Matching Pair
1.25mm Pitch 3-pin Cable Matching Pair

The diagram below provides a visual reference for wiring of the components. This diagram was created using the software package Fritzing.

Adafruit Library for Fritzing

Use Adafruit's Fritzing parts library to create circuit diagrams for your projects. Download the library or just grab individual parts. Get the library and parts from GitHub - Adafruit Fritzing Parts.

Connect the Circuit Playground Bluefruit to the servo's wires as shown in the diagram above.

  • Red goes from VOUT to servo red voltage wire
  • Black goes from GND to servo brown ground wire
  • Yellow goes from A3 to servo yellow signal wire

Install or Update CircuitPython

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

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! :)

Once your CPB is set up with CircuitPython, you'll also need to add some libraries. Follow this page for info on how to download and add libraries to your CPB.

From the library bundle you downloaded in that guide page, transfer the following library folders onto the CPB board's /lib directory:

  • adafruit_ble
  • adafruit_bluefruit_connect
  • adafruit_motor

Before continuing, please be sure your board's CIRCUITPY drive has a /lib folder with the three folders listed above. Please do not copy the files out of those folders to put in the /lib directory.

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.

Code.py

Copy the code below and paste it into Mu. Then, save it to your CPB as code.py. Alternatively click  Download: Project Zip or code.py links to download the file to your computer.

import time
import board
import pwmio
from adafruit_motor import servo
from adafruit_bluefruit_connect.packet import Packet
from adafruit_bluefruit_connect.button_packet import ButtonPacket
from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService

ble = BLERadio()
uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)

pwm = pwmio.PWMOut(board.A3, duty_cycle=2 ** 15, frequency=50)

my_servo = servo.Servo(pwm)

while True:
    print("WAITING...")
    # Advertise when not connected.
    ble.start_advertising(advertisement)
    while not ble.connected:
        pass

    # Connected
    ble.stop_advertising()
    print("CONNECTED")

    # Loop and read packets
    while ble.connected:
        if uart.in_waiting:
            packet = Packet.from_stream(uart)
            if isinstance(packet, ButtonPacket):
                #  if buttons in the app are pressed
                if packet.pressed:
                    if packet.button == ButtonPacket.DOWN:
                        print("pressed down")
                        for angle in range(90, 170, 90):  # 90 - 170 degrees, 90 degrees at a time.
                            my_servo.angle = angle
                            time.sleep(0.05)
                    if packet.button == ButtonPacket.UP:
                        print("pressed up")
                        for angle in range(170, 90, -90): # 170 - 90 degrees, 9 degrees at a time.
                            my_servo.angle = angle
                            time.sleep(0.05)
    # Disconnected
    print("DISCONNECTED")

Bluetooth App

This project uses the Adafruit Bluefruit LE connect app (available free for Android and iOS) to trigger the servo. It uses the control pad to open and close the servo claw. If you haven't downloaded the app yet, use the button below to install it on your mobile device.

Connect to Circuit Playground Bluefruit

Turn on the Circuit Playground Bluefruit by either connecting it via USB to your computer or with the 500mAh battery.

Using Bluefruit LE Connect App

Open the Bluefruit LE connect app and locate the device named CIRCUITPY and tap the connect button. Locate and tap on Controller. Under module, tab on Control Pad

Use the UP and DOWN arrow buttons to trigger open and close the servo claw. 

Parts List

STL files for 3D printing are oriented to print "as-is" on FDM style machines. Parts are designed to 3D print without any support material. Original design source may be downloaded using the links below.

  • servo-holder.stl
  • arm-sm.stl
  • arm-lg.stl
  • case-cover.stl
  • case-btm.stl

Slicing Parts

Slice with setting for PLA material. The parts were sliced using CURA using the slice settings below.

PLA filament
215c extruder
0.2 layer height
10% gyroid infill
60mm/s print speed
60c heated bed

CPB wires

Follow the circuit diagram and tin and solder wires to each pad on the Circuit Playground Bluefruit.

 

Servo Wires

Shorten the cables on the servo to keep the circuit tidy.
Use heat shrink to insulate the connections. 

Servo Hardware

An M3 nut is place in the servo holder part.

The servo is press fitted into the holder with the shaft fitted through the opening.

The arm of the claw is fitted over the shaft and secured with one of the servo horns.

Servo Horns

The included servo horn press fits over the claw. Use the shorter included screw to secure the horn and claw.

 

Second Arm

The other arm is secured to the mounting hole using an M3 screw and nut.

 

 

Attach Servo to Case Lid

The top cover of the case is secured to the servo holder using M2.5 screws.

The Circuit Playground Bluefruit sits in the enclosure with the wires fitted through the hole in the cover.

Case 

The lipo battery is place in the middle of the case. Coil the wires around the case. Fit the wire over the vertical cutout on case.

Lid

Place the lid over the case. Thread the wires on the Circuit Playground Bluefruit through the Lid.

Case Screws

The top cover is secured to the enclosure using M3 screws.

The servo can then be plugged into the Circuit Playground Bluefruit.

 

Attach Case

The enclosure is secured to the battery cover of the flying ghost using double-sided foam tape.

Complete!

 

This guide was first published on Oct 26, 2020. It was last updated on Oct 26, 2020.