Software apps and online services
Hand tools and fabrication machines
My wife had a big birthday coming up (ends with zero), and I wanted to give her something special, something unique and personal. Think, think, think... Butterflies are kind of her "spirit animal", a symbol of change. Maybe something butterfly themed?
I first thought of doing a butterfly bracelet years ago, using a leather band as the bracelet with NeoPixels shining through shirt buttons shaped like butterflies. That didn't work out for technical reasons, especially making an enclosure for the electronics. Fast forward, and I'm following Noe & Pedro from Adafruit (Layer by Layer). They created round cases for the Gemma and Circuit Playground microcontrollers. That had possibilities...
The Circuit Playground round case was too big for my initial thought, a bracelet. The Gemma main enclosure was small enough. But when I started thinking about it, I couldn't cram everything, like NeoPixels AND the Gemma AND a battery, into that single case. The Adafruit Team solved the problem by separating the glowy part and the Gemma/battery into two pieces, a pendant and an unseen microcontroller and battery.
Well. Does it have to be a bracelet? How about a pin of some kind, like a brooch? Yeah, that could work, if it isn't too big. I found free clip art of a suitable butterfly image, tracing it out in CorelDraw. playing with scale. Yep, that could work!
Easy to Intermediate, you be the judge: 3D print the case, solder some components, load a program to an Adafruit Trinket microcontroller. The "Intermediate" challenge is fitting everything into the tiny, curved space of a case shaped like a butterfly. You'll have to measure your wire lengths carefully and there are lots of fiddly bits. Slow down and focus, and you'll be good.
Parts will cost about $50 USD, depending on what you already have on hand and not including the 3D printed case. I printed my own. If you don't have a 3D printer, you can try 3D Hubs or Shapeways. Yeah, that's a little expensive. But, do you know someone else who has their own light up butterfly jewelry?
The 3D print of the case and back cover take about 3 hours altogether on my small, slow printer - your time may vary.
- 2 hours - soldering
- 2 hours - testing (total, done in steps)
- 1 hour - final assembly
This project requires a light diffuser of some kind. The butterfly-shaped diffuser outline drawing is included in the github diffuser folder. You can print this out on heavy card stock and cut by hand. The best diffuser, though, is laser-cut 0.8 mm white Delrin. If you don't have access to a laser cutter, feel free to create an account and upload the design to ponoko.com, which has local factories around the world. Getting a product made at Ponoko has some lag time, from 1 to 2 weeks. You can pay extra fees to speed things up. Plan your build time accordingly.
The Trinket sets the colors based on RGB values sent to 6 NeoPixels. There are some sample colors stored in an array in the code. Read the code and you'll find it's pretty easy to add custom RGB colors. Just google for the RGB value of the color you want, add a uint32_t variable named for the color and add that name to the colors array. You'll also need to change the MAXCOLORS variable.
The first color in the array will display about 4 seconds after start-up on battery power. Make your favorite color the first entry in the array, so it will show on start-up. Each press of the push button will cycle through the colors in the array. At the end of the array, the first color will be displayed again.
The tiny 150mAh battery will last about 2.5 hours on full charge. The NeoPixels will remain lit while the battery is charged via USB cable, no way to turn them off. More on how to check for charging/charged state of the battery later.
Load code, solder and test, especially after soldering these parts:
- 3 NeoPixel cut strips from 60 LED per meter strip
- Push Button to change colors
- On/off switch to LiPo Back Pack
This will ease troubleshooting if you run into any problems. You'll know what works already.
I tried to keep the height of the butterfly brooch just tall enough to squeeze in the components. Otherwise, it might feel like wearing a brick.
Due to the limited (height) space in the case, I used NeoPixels cut in 3 strips of two LEDs each from a one meter strip. These LEDs are mounted on coated copper foil and are very thin. The full meter strip is $24.95 USD from Adafruit, and I already had one. You might be able to get by cheaper with Adafruit Product 1312, RGB Smart NeoPixels at $7.95 USD/pack of four. These are just slightly thicker because they use a PCB instead of the coated foil. These will be more work because you will have to solder 6 individual NeoPixels for both Data In/Data Out. The cut-strip NeoPixels only need 3 Data In/Data Out solder connections.
I tested each finished component on a Trinket with headers soldered on, using a breadboard. There won't be enough room in the case to deploy the same Trinket with headers already soldered on. Leave your wire leads long where they will connect to the Trinket and hook them up to the breadboard to test. You can trim the wires after you know the components work, but you'll want to measure carefully!
The Trinket has a single GND output, but for this project we need 3 GND connections: NeoPixels, LiPo Back Pack and push button. The NeoPixels will be soldered directly to the Trinket GND. You'll need at least a GND wire on the Data Out pads of the last strip in the chain (slide switch side), to connect to the LiPo Back Pack. That takes care of two GND connections. For the push button, we'll "fake" a GND by using a Trinket pin set LOW.
Print the case in black PLA. Another option is just print in whatever color you have in your printer and spray paint the case black. That worked for me! Two coats of Krylon Black does the job.
My 3D printer is... limited. So, I always print with at least a brim. On this print, that still left quite a bit of support material in the open scales of the butterfly. Use a sharp hobby/Xacto knife to clear that away - takes about 15-20 minutes for a proper clearing job.
You should have the printed case ready when you build the electronics. You'll need to check the fit of the components in the case as you go.
The case STL file is in the github STL_and_Cura folder, along with the Cura settings.
Cut 3 strips of NeoPixels with 2 LEDs per strip. Solder the wires on the back of the strips (side without LEDs). Tin both the NeoPixel solder pads and wires with plenty of solder. Helping Hands are very useful for this. Press the tinned wire into the pad with the soldering iron, remove the iron and hold stable for a few seconds for a good joint.
Arrange the NeoPixels in a kind of tilted "H" pattern, to fit into the wings of the butterfly, like so:
Gently(!) bend/form the soldered wires to curve into the walls of the butterfly. Here, I've used hot glue on the solder connections as strain relief and insulation, and to hold the cut strips together in the right shape. The pieces of white electrical tape in the picture cover the 3 unused, bare copper solder pads in the middle of the cut strips, to prevent shorts.
Attach a USB cable to the Trinket. Load up the butterfly brooch sketch from github, attach the Trinket with soldered headers to a breadboard.
- GND GND
- 5V 3V
- D IN PIN 2
After about 10 seconds from a reset, you should be rewarded with a nice, purple glow.
LiPo Back Pack
Cut the thin trace on the LiPo Back Pack between the switch holes, next to the 5V solder pad:
- Place the slide switch in its case cut-out and put the LiPo Back Pack, at a slight angle, in the upper wing part on the same side as the switch.
- Measure out two wires to go from the LiPo Back Pack to the switch, leaving a little slack and some extra room for solder connections.
- Test fit the wires from the switch to the Back Pack.
- Attach the 150mAh battery to the JST jack on the Back Pack to see if the battery will fit neatly in between the switch and the Back Pack.
If the battery fits flat in-between the LiPo Back Pack and the switch, you're good to solder the switch wires to the Back Pack. Remove the battery before soldering!
You should end up with something that looks like this:
Trim two pins from opposite sides of a 6 mm tactile button, as close to the body of the button as possible. Cut two long pieces of wire and create pig-tails to fit around the remaining wires. I wrapped the wires around a straight pin to form them:
- Solder the wires to the push button
- Apply heat shrink to the solder joints
- Connecting to the breadboard Trinket, attach one wire to Pin 0 and the other to Pin 3. Pin 0 will start up set LOW, faking a GND connection. Pin 3 is a pull-up.
- There's no orientation here - It doesn't matter which wire goes to which pin.
Plug in the USB cable to the breadboard Trinket (with NeoPixels still attached) and press the button a few times. It should cycle through from purple to red, green, etc. - all the items in the colors array. When you reach the end of the array, you should see purple again.
Fit the tactile button into the 6 mm cut-out on the side of the case. Measure and cut the wires from the push button to reach Pin 0 and Pin 3 on the Trinket to be mounted in the case. To help fit the Trinket in the case properly, attach an unpowered USB cable to it and make sure it clears the USB cut-out, sitting at a very slight angle in the case. Solder the push button pins to the Trinket.
- Measure and cut two more wires for BAT and USB on the LiPo Back Pack
- Solder them to the Back Pack and the Trinket for the case
At this point, the wiring should resemble this:
- Fit the NeoPixels in the case and place the wired-up Push Button/Trinket/Back Pack on top of them
- Measure and cut the GND wire from the NeoPixel closest to the slide switch, to attach to the G(ND) pad on the Back Pack.
- Solder this GND wire to G on the Back Pack
First install your diffuser in the bottom of the case, over the butterfly "scale" cut outs. I left the backing paper on the laser-cut diffuser. That makes for a nice glow. Fit in the NeoPixels. Insert the slide switch and push button into their cut-outs and fit the Back Pack into the butterfly wing. For now, bend the remaining unsoldered NeoPixel wires near the Trinket out of the way, so you can seat the Trinket.
Make SURE the battery is not attached to the Back Pack at this time! You don't want to risk shorting it out while soldering.
Place the Trinket, with USB cable attached (but NO power), into its case cut-out. Press down gently so the Trinket lies deep and flat in the case.
Measure. trim and solder the NeoPixel wires to the Trinket pins: NeoPixel DIN to Pin 2, "5V" to "3V", and GND to GND.
Now, test the LiPo Back Pack. Insert the battery plug into the JST connector. The slide switch should turn the Trinket on. The NeoPixels will light up, too, after about 4 seconds. Use the push button to cycle through the NeoPixel colors. Also, test the charging part of the circuit by applying USB power.
If you're happy with the arrangement and everything works, apply hot glue to the edges of the boards closest to the case to keep things in place. Pay special attention that nothing is sticking up above the edges of the case, so the cover can lie nice and flat. Also apply hot glue (or superglue, if you like that) to attach the push button and slide switch.
Hey, you made it!
Here's what it looks like with everything in the case:
Not so fast, though, Sparky - you're not done yet!
Use two M3/5mm black machine screws to attach the cover to the case. Center the foam-tape backed part of the magnetic badge on the cover and attach. Try it out... To remove the magnet, slide it apart, don't pull it apart.
OK, now you're done.
If you look closely at the slide switch side of the case when the USB cable is attached, you can just detect a faint glow of red (charging) or green (charged) underneath the back cover.