Saturday, January 30, 2016

Printrbot Lights


I'm a nerd, and I tend towards dark places - thus my desk, where I keep my Printrbot, tends to be poorly lit. After getting very tired of using a flashlight to monitor the progress of my prints I decided to design and print a lighting solution that could be mounted to the Z-axis of the Printrbot.

I recently upgraded my Printrbot Simple Metal with Printrbot's X and Z axis upgrades...the new print area is huge, so I designed the lights to be larger than a standard Printrbot Simple Metal's print area of 150cm3. While this design doesn't require the Z-axis upgrade, it does need the x-axis the width of the mounting bracket and light "sled" is > 220mm.


The most expensive part (aside from the Printrbot of course) is the LEDs that are mounted in the "sled." For these, there are lots of places to find strip LEDs, including sites like eBay. But I like to be cheap, so I found some Automotive Accent Lights at WalMart in the Clearance aisle.

However you find them, some important characteristics to keep an eye out for:

  • 12v input - this way you can hook them directly to an ATX PSU that you have powering the Printrbot (you DO have an ATX PSU, don't you?). Using automotive-based lights (typically) makes it easier, cause they're designed to plug straight into a 12v source. If they have the cigarette light adapter, check the adapter to see if there's any circuitry in there to step-down the power from the car's 12v source to 5v or something similar.
  • Cut-to-length - you'll want to be able to trim them to the appropriate length. The "sled" is allows for about 210mm of length for the LEDs, not including the tail where the wires come out.
  • Adhesive back - this will make sticking them to the sled easier - but you can also use some 2-sided foam mounting tape.

Aside from the LEDs, you'll need:

  • Printrbot Simple Metal with X-axis upgrade and the Aluminum handle for the Z-axis
  • (8) 10-12mm x 3mm hex cap screws
  • A spare 4-pin molex connector to wire the LEDs to
  • A soldering iron and some solder
  • Some heat-shrink and heat gun, or electrical tape to protect the exposed wires
  • Some zip-ties (optional)
  • Some 2-sided foam mounting tape (optional)


The lights are separated into two pieces - the bracket that mounts to the Printrbot, and the light "sled" that holds the LEDs.

Download the .STL files from Thingiverse

Printing is fairly straightforward - whatever settings work well for your printer, for producing a large, flat-based print. No supports are necessary, but if they make you feel better, the "sled" may benefit from them a little if you have problems with > 1cm bridges.


Start by threading the LED strips into the light sled to see where you need to trim them. Typically, cut-to-length led strips have lines on them where you should cut them - if not, a dead give away are the solder pads where the wire tails would be connected.

Make sure you're happy with the lengths, cut them and then thread them through into the sled, leaving the tails to stick out through the holes in the top of the sled.

Thread the wires through the channels.

You can screw the sled to the mounting bracket using 4 of the 3mm hex screws before threading the wires or after - your choice. But finish threading the wires through the channels on the mounting brakcet.

Now you'll need to cut-and-strip the ends of the leads to the LED strips, and also strip the leads to the Molex connector. I usually have a ton of these sitting around that have come with case fans, case accent lights, old adapters for powering hard drives etc. Here's one that I had left over from a fan adapter. You can just cut the 2 pin fan connector off to give you wires to connect the LED strips to.

You'll need to identify the positive/negative leads on the LED strip tails - in my case, the wires are both black - but the positive (12v) lead has a white strip. On the Molex connector, the red lead will be the positive (12v) connection, and the black will be the ground. Twist the 12v leads from the LEDs to the 12v (red) wire on the molex connector. Do the same for the ground leads to the black connector. Solder the leads together.

Optional: before you twist the leads together, I used two lengths of small-diameter heat shrink on the positive/negative leads of the Molex connector which will help protect the positive/negative connections. I also used a section of larger-diameter heat-shrink that will be slid over the two smaller sections, to keep everything in one nice package. Electrical tape could be used instead, but heat shrink is so much sexier.

Now use some zip ties to keep the wires nice and tidy. Or not...your choice.

Time to mount the lights! The mouting bracket has holes on both sides that line up with the 3mm holes in the aluminum mounting handle that goes on top of the Z axis of the Printrbot. Use 2 of the 3mm hex-cap screws on each side to mount the bracket.

Finally, plug the Molex connector into the ATX PSU, and you're done!

Wednesday, July 22, 2015

YAMC - Yet Another M___c____ Cube


This project started back around December of 2014. I was poking around on the various 3D printing sites, looking for a printable gift for a friend’s daughter for Christmas. There were tons of M___crafty things out there, and I thought “ of those ore nodes that has lights in it is kinda cool”. So I printed a couple, played with them, and decided it just wasn’t fancy enough.

But I’m definitely not the first.

There’s lots of them out there - most of them use LED tea lights or simple LED lights connected to coin cell batteries. In typical “Phill” fashion (as my wife likes to call it) I decided to over-engineer a solution that has way more functionality than necessary, while at the same time letting me play with lots of electronic components and microcontrollers in the process.

I went through several prototypes during the development of YAMC. A couple of different microcontrollers, a couple different kinds of LEDs, switches, power connectors, potentiometers, etc. I even at one point tried to include a microphone into the design.

So I eventually scaled back, decided on a final set of functionality (the three modes you see in the cube now), and limited the electronics. Mostly to cap things like “cost”.

That said, I really hope you make one of these and enjoy it. It was a lot of fun to design, a labor of love to force myself to complete, and a real challenge to stay “focused” on.

On to the good stuff!


Quick links for the impatient!

The Cube

The “Yet Another M___c____ Cube” (or YAMC) is made up of four main components:

Cube Top - print this in whatever color you would like. I highly suggest printing with 100% infill, and use the version of the cube that includes the built-in supports. If you want to roll your own supports or take your chances without them, you can use the non-supported version. Print it upside down so that the top is the base of the print.

Cube Base - this is where the electronics will be mounted. Print this one right-side up, and in the same color as the Cube Top. Again, I strongly suggest 100% infill, as this will help reduce/prevent “leakage” of the light from the LEDs

Cube Diffuser - this is the semitransparent portion of the cube. It slides up inside of the Cube Top, and should be printed from “Natrual” colored PLA. Print this upside down (with the top as the base), and 100% infill. Otherwise you might end up with some strange light pattern effects on the top - unless that’s what you’re looking for.

Knob (not pictured) - this is the control knob that is glued onto the rotary encoder. Print this face-down. I recommend printing in the same color as the cube, but if you want to mix it up, go nuts!


For this project, I you’ll need some rather specific parts, and some general ones that you can find just about anywhere. Also, depending on how you want to power and program your Pro Trinket, you’ll need an FTDI programmer cable, or a standard USB cable. You can power it from a standard USB port, or pick up a small USB brick to power the USB cable.

The most difficult/expensive portion of the project is the NeoPixels, and you’ll have a bit of a decision to make. In the design, I suggest using 5 NeoPixels. However, Adafruit only sells them in packs of 4, or sheets of 25. In my case, I knew I’d be making a few of these cubes, so I got a full sheet. You can opt for 4 NeoPixels instead, and just get one pack of 4, or get two packs of 4. Or get a full sheet and make some for your friends!

Parts like the 1000uF capacitor, 330ohm resistor, and hex cap screws you can find in a variety of places. I included links to places you can buy them in the BOM below.

Bill of Materials

Adafruit NeoPixel5
Rotary Encoder1
1000uF Electrolytic Capacitor1
330 ohm through-hole resistor1
M2x6mm Hex Cap Screw3
M3x8mm Hex Cap Screw2
Optional Parts
USB Cable1
USB Power Brick1

Circuit Diagram

Unfortunately, Fritzing doesn't have a good part for a single Neopixel, so I just used the strip. For each Neopixel, you need to wire the Dout from one to the Din to the next, +5v to +5v and GND to GND. Pretty simple!


Not all of the tools are “required” per-se, but you’re going to have a hard time building this without things like a soldering iron!

  • Soldering Iron
  • Exacto Knife
  • Wire cutters
  • Wire strippers
  • Flush Cutters
  • Hex drivers
  • Hot Glue Gun
  • Breadboard (1/2 size sufficient)
  • Needlenose Pliers
  • Small files
  • Panavise/Suction Cup Vise/3rd hand
  • A 10mm deep socket (optional, but really helps!)
  • Heat Gun (optional, but if you’re using heat shrink you better have one!)


You’ll need some consumables as well.

  • Blue Painters Tape or Electrical Tape
  • Heat Shrink - optional but suggested
  • Solder
  • Hook up wire (multiple colors REALLY helps).
  • Hot Glue Sticks

Let’s get started!

Step 1 - Print and Clean Your Cube

As I mentioned earlier, I STRONGLY suggest printing all the components with 100% infill. This will help reduce light "leakage" through the plastic. The LEDs will show through pretty easily, and if you use something like a honeycomb infill, you'll see it pretty clearly. Or maybe that's the look you were going for?

The Cube, Bottom, and Knob can be printed of whatever color material you'd like (I use PLA on my PrintrBot Simple Metal). The Diffuser should be printed from clear (natural) PLA, or another equivalent clear-ish material.

After printing, the cube will probably have lots of “spiderwebs” in it. At least mine did. And if you print it with the designed-in supports, you’ll need to clean those up.

I usually remove the threads with a longer-bladed knife by “scraping” them off the inside. An exacto or some files can help.

Next you’ll need to remove the supports. I use the horizontal “flush” cutters for this, and ship each side of the support off.

Once the supports are all removed, trim the leftovers off with an exacto knife, and then file or sand them down so they’re nice and flush. Take your time so it looks spiffy!

Once you’ve cleaned the Cube Top, you may have to do some cleanup on the diffuser, base, or knob. In my case, they typically come out pretty clean, so you’ll have to use your own discretion in cleaning them up.

Before moving to the next step, go ahead and slide the diffuser into the cube top. If you’ve cleaned the top well enough, it should slide in with just a little resistance.

Step 2 - Mount the Encoder

Let’s turn our attention to the base. The first thing we’ll need to do is mount the rotary encoder. This little knob will control the “mode” of the cube, and will make changes like speed up or slow down the color speeds depending on the mode.

Take the encoder and slide it into the center hole in the back face of the base (from inside out). Once you’ve slid it through, drop in the small threaded nut and tighten it into place. This is where a 10mm “deep” socket will REALLY help. The hole should be large enough to fit the socket in and tighten the nut. If you don’t have a socket, you can probably do this with a pair of REALLY small needle nose pliers.

Step 3 - Solder FTDI Header to ProTrinket

This step is optional, depending on how you plan to program your trinket. If you’re using the FTDI pins to program the Trinket instead of USB, you’ll need to mount the headers.

Start by cutting off a 6-pin section of the header that is included with the ProTrinket. Press the section of header into your breadboard.

Flip the TrinketPro over and position it with the FTDI pins (at the end of the Trinket) over the header.

Solder the header in place.

And you’re done! Set the Trinket aside for now. Don’t screw it into the base yet - it’ll just get in the way while you’re wiring the rest of the base.

Step 3 - Assembling the NeoPixel Strand

Now we’ll start assembling the NeoPixel strand (I refer to it as the Matrix in the code) for the Cube. This is the LED strip that we’ll eventually mount on top of the pedestal that is part of the base.

Start by 12 2cm or so lengths of hook-up wire. This is where multiple colors comes in handy - because we’re going to need 4 pieces for the positive connections between the LEDs, 4 pieces for the GND connections, and 4 pieces for the data connections. I’ve used Red/Blank for +/gnd, and green for the data in/out lines.

Strip a small bit (a few millimeters) of the insulation off each end of each section of wire.

Next, take a section of red wire (+), black wire (gnd), and green wire (data) and bend one end of each at a 90 degree angle. Slide the bent end of each wire through the corresponding hole in the NeoPIxel. Note that we’re working on the “data out” side of the NeoPixel, so the green wire will go in the “Out” hole, and the red/black will go in the +/gnd holes correspondingly, with the direction of the wire going from the front of the NeoPixel (the side with the LED), through and out the back.

This is where electrical tape or blue painter's tape will come in handy. Tear off a small piece of tape, and use it to hold the wires in place. I place the tape on the front and hold the wires in place straight-out from the PCB.

Clamp the PCB into your panavise. If you don’t have one...well, I highly recommend picking one up.

Solder the ends of the wires in place on the back of the NeoPixel PCB, and you can pull off the piece of tape.

Bend the other end of the wires that have been soldered into the NeoPixel PCB at a 90 degree angle. The bend should face the same way as the previous bend.

Grab another NeoPixel, and slide it onto the wires you just bent. The red wire should go through the corresponding + in the PCB, the black wire through the GND, and the green wire through the Data IN. What we’re doing here is chaining the NeoPixels together, so that the Data Out from the previous NeoPixel is connected to the Data In on this NeoPixel. Use a small piece of painter’s tape to hold the NeoPixel in place.

Now go ahead and solder them in place.

Grab 3 more sections of wire (red/black/green), bend one end at a 90 degree angle, and slide them into the +/gnd/data out holes of the second NeoPixel. Solder them in place, and continue the process until you’ve soldered the 5th NeoPixel into place.

And the final product! When you’re done, you should have 5 NeoPixels connected together with 4 sets of 3 +/gnd/data wires.

Step 4 - Adding the Capacitor and Resistor

In this step, we’ll be (shockingly) adding the cap and resistor to the NeoPixel string. For this step, you’ll need the 1000uF capacitor, the 330ohm resistor two lengths of wire for power/ground (red/black) that are about 8cm long, and two sections of data wire (green) about 4-5cm each. Note: the picture only shows one section of green data wire.

Start by cutting the power/gnd/data wires. Specifically, you’ll need:

(1) 8cm or so section of wire for power (red)
(1) 8cm or so section of wire ground (black)
(2) 4 to 50cm or so sections of data wire (green)

Take the wire to be used for power (red in this case) and strip a few mm of insulation from one end, and about 15mm of insulation from the other. Then, using your wire strippers, cut into the insulation and strip it down towards the end you stripped the 15mm of insulation from.

The idea is to create a section of bare wire in the middle.

Repeat this step with the ground wire (black).

Next, take the capacitor and twist the positive lead (the long one) around the center of the red (power) wire. Do the same with the ground lead (the short one) and the black wire. Make sure you’re careful to observe the polarity of the capacitor and connect the leads to the correct wires!

Clamp the capacitor and leads into your panavise and solder the leads to the wires.

Snip the remaining ends of the leads off.

Cut off a two sections of heat shrink tubing that are long enough to cover the exposed solder joints for the power and gnd connections. If you don’t have heatshrink, you can use electrical tape for this.

Using your heat gun, shrink the heatshrink into place.

Remove the capacitor and leads from the panavise. Grab the two sections of data wire (green), and strip a few mm of insulation from one end of each, and about a cm of insulation from the other end of each. The idea is to create a longer exposed section of each wire that we will then use to attach the resistor. Take the resistor and twist one end of the resistors lead to one wire, and the other lead to the other wire.

Clamp the wire/resistor assembly into place and solder the resistor leads to the wires. Cut off any excess. Cut a section of heatsrhink tubing that is long enough to cover the exposed wires and resistor. If you don’t have heatshrink tubing, you can use electrical tape instead.

And using the heat gun, shrink the tubing in place.

Remove the resistor assembly from the panavise. Next, take the capacitor and leads assembly, and bend one end of the power wire and one end of the ground wire at a 90 degree angle. Taking the NeoPixel strand, connect the power and ground wires to the Data In end of the NeoPixel strand. Position the wires so that the bent ends enter from the front of the NeoPixel passing through to the back. Note, the NeoPixel strand has two “ends” at this point. One end with an empty “data in” connection, and one end with an empty “data out” connection. Be careful to position the power/ground leads on the “data in” end of the NeoPixel Strand. Also, be careful to make sure you have the power wire connected to the + connection on the NeoPixel, and the gnd wire connected to the gnd connection on the NeoPixel.

Position the capacitor/NeoPixel strands in your 3rd hand, panavise, or otherwise support them so you can easily access the back of the NeoPixel, and solder them in place.

Take the data wire/resistor assembly and bend the wire at one end at a 90 degree angle. Slide the bent end through the “Data In” connection of the NeoPixel that you just connected the power/gnd wires to. Again, be careful to make sure you’re attaching the wire to the “Data In” connection. Solder the connection in place.

As the last step of this sub-assembly, let’s clean up the solder connections, Using your flush cutters, snip off the excess wire sticking through the solder joints. If you don’t have a flush cutter, you can use a wire cutter to get pretty close. You just don’t want any excess wire sticking through and potentially causing a short.

Step 5 - Wiring the Rotary Encoder

In this step, we’re going to add the wiring to the Rotary Encoder. This will let us (finally!) start tying all the components together!

First, take a look at the Rotary Encoder’s pins. It has two distinct “sides”. One side has three pins - these are the connectors for the rotary encoder itself. They detect the rotation (left or right) of the shaft. The side with only two pins is to detect the button in the encoder, aka when you push it in.

The simpler side to understand is the switch side - one side will be wired to a GPIO pin on the TrinketPro, and one to ground.

The three-pin side is a little more complex (it has three pins instead of two!). The center pin is the ground pin, and the top/bottom pins are for detecting the direction of rotation of the shaft. These two pins will be connected to GPIO pins on the TrinketPro.

Let’s start by wiring the grounds of both sides of the encoder. Cut a 6 cm length of wire (I used black for ground), and using the same trick we used back when wiring the Capacitor, trim a few mm of insulation off of one end, about 15mm of insulation off the other end, and then strip the center to expose some bare wire in the middle.

Back on the encoder, bend out the center pin on the shaft-side (3-pin side) of the encoder. This will make it easier to work with.

Now we’re going to “tin” the pin. Since we’re working with the encoder mounted, it’d be really hard to get a 3rd hand in there to hold the wire, while holding solder and a soldering iron. Take your soldering iron and solder, and add a good dollop of solder to the center pin of the encoder.

Pick up the ground wire you cut, and hold one end against the tinned grounding pin of the encoder. Make sure you point the long end of the wire towards the “inside” of the base to make subsequent wiring of the shaft-side ground easier (see photo). Using the Soldering Iron, heat up the bare end of the wire while pressing against the tinned ground pin of the encoder, and the solder bead should “melt” between the two. Remove the iron and hold it in place for a moment until the solder solidifies.

Flip the base around so you can access the button-side of the encoder. Bend the ground wire around behind the encoder, and wrap the center exposed portion of the ground wire around one of the two encoder pins (doesn’t matter which).

Solder the ground wire in place.

Flip the base back around to access the shaft side of the encoder pins. Using the solder tinning method from earlier, add a bead of solder to the top and bottom pins of the encoder.

Cut two longer lengths (8cm or so) of wire. I used yellow and blue here. Strip off a few mm from each end of both wires.

This is where you need to be a little careful of how you wire the encoder. We’ll need to connect the pins from the encoder to specific GPIO pins on the ProTrinket. If you’re facing the shaft of the encoder, the shaft-side pins should be on your left. We’ll refer to the top pin as Encoder Pin 1 and the bottom pin as Encoder Pin 2.

Solder the yellow wire to Encoder Pin 2, and the blue wire to Encoder Pin 1.

Now we’ll connect the data wire for the pushbutton side of the encoder. Flip the base back around to access the button side of the encoder pins. Using the solder tinning method, add some solder to the other pin of the button side of the encoder. Cut a length of hookup wire (4 or 5 cm), strip both ends, and solder one end to the just-tinned-pin of the encoder. I used white hookup wire for this.

Step 6 - Mounting the ProTrinket and connecting the encoder

Time to return to the ProTrinket and start getting everything connected! Start by mounting the ProTrinket to the base using the 3 M2x6mm hex head screws. Don’t overtighten, but make sure it’s snug. The idea is to keep it firmly in place so that (eventually) when connecting the USB cable to power it, the board doesn’t move out of place.

Next, we’ll connect the encoder shaft pins pins to the ProTrinket. Start by connecting Encoder Pin 2 (the top pin - I used a yellow wire) to Digital GPIO Pin 5 of the ProTrinket. A little trick to this is to not bend the wire, but slide it down into the hole so it sticks out the other side a millimeter or so. Too much further and you’ll run the risk of making accidental contact between wires while you’re soldering, creating shorts, etc. After inserting the wire, bend it outwards using the hole in the ProTrinket PCB to bend the angle. Bend the wire down so it’s parallel or a little lower, and it will tend to stay right in place, allowing you to easily solder it without any additional assistance from tape or 3rd hands.

Repeat the process, connecting the data wire from the pushbutton side of the encoder to Digital GPIO 4 (the white wire), and Encoder Pin 1 to Digital GPIO Pin 3 on the trinket (the blue wire).

Step 6 - Mounting and connecting the NeoPixel Strand

Time to finally mount those NeoPixels! Grab the NeoPixel strand you assembled a few steps ago, along with the capacitor and resistor. You’re going to want to bend the wires so that the first four pixels in the strand (with the capacitor/resistor being at the “front”) in a square. The idea is to get them to fit into the little slots at the top of the pedestal on the Cube base. The last pixel will sit on top of the pedestal. A picture in this case is worth a thousand words...or a handful of bends.

Use the top of the pedestal to help you form the shape. The edge of the PCB should slide down between the little raised tab on the four outside edges of the pedestal, and the center pillar near the top.The 5th pixel will bend at a 45 degree angle to the 4th, and sit on top of the pedestal.

Now it’s time to fire up your hot glue gun. Get it nice and toasty, and drop a good dollop of hot glue in the four slots where the NeoPixel PCBs go. Slide the NeoPixel “hat” in place and hold it there until the glue sets.

I also suggest adding a good drop of hot glue behind the back of the PCB and the upper edge of the pedestal, just to give it some extra grip.

Place a good-sized drop of hot glue on the very top of the pedestal, and fold the last NeoPixel over on top of the glue, and hold it in place until the glue sets.

Let everything set well before you continue. It should only take a few minutes. Next, you want to take the ground wire from the NeoPixel strand and wrap it around the ground ground connection of the pushbutton side of the encoder. Solder it in place.

Take the positive wire from the NeoPixel strand, and the ground wire from the rotary encoder, and solder them into the 5v and GND connections of the ProTrinket.

Last wire to solder! Solder the green Data In wire that leads to Pixel #1 of the NeoPixel strand (the one with the resistor in-line) to Digital GPIO Pin #6 on the ProTrinket.

Time to glue on the knob. Make sure the knob fits over the shaft of the encoder. Clean/ream out any excess plastic from the print if necessary. It should fit rather loosely, and stick out about 2-3mm from the back of the Cube base when bottomed out on the encoder shaft.

Once you’re happy with the fit, go ahead and drop a good amount of hot glue into the knob, and slide it into place on the encoder shaft. Hold it there for a minute and let it set.

At this point, you can decide to attach the Cube top to the base and test the fit, or continue on to programming. If you decide to test the fit, just remember you’re going to have to open it back up before you can program it!

Slip the top of the cube down over the pedestal of the base, and back so that the little legs at the back of the base slot into the top. Flip the cube over and attach the base to the top using the M3x8mm hex cap screws.

And you’re done with the assembly of the cube!

Step 7 - Setup Arduino IDE and install necessary libraries

If you’re comfortable downloading libraries programming arduino-like devices, then you can probably skip most of this and get the code, the libraries, and getting the cube up and running without reading this section. Just download the code, and go nuts!

For everyone else, first, install the Arudino IDE from Adafruit which includes support for their various Arduino-compatible boards. If you’re a true newbie to this, I suggest following the “Super Easy Installation” instructions.

Make sure to go through all of the requisite steps, including the installation of the USB drivers (if you’re using the USB cable to program). If you’re doing this via the FTDI cable, you’re probably ahead of the curve anyway!

Next, you’ll need to download the necessary libraries for everything.

Adafruit NeoPixel Library -
YAMC Library -
Rotary Button Library -

Arduino Libraries are installed in the Arduino “sketches” folder on your computer. In windows, this is typically the My Documents -> Arduino -> libraries folder. Adafruit has a nice tutorial on installing libraries that can be found here:

After installing the libraries, remember to restart the Arduino IDE.

Step 8 - Loading the YAMC Example Sketch

Start up your Arduino IDE, and connect the ProTrinket with your programming cable of choice (USB or FTDI). In the IDE, chose the ProTrinket board from the Tools -> Board menu (again, USB or FTDI). Chose the appropriate COM port, and you’re ready to program.

Once you’re ready to program, open up the YAMC Example sketch in the Arduino IDE. You can find it under File -> Examples -> YAMC -> YAMC_Example. Once the sketch has opened, you should be able to program without any changes, and watch your cube glow!

The cube starts up in “shift” mode, where it shifts slowly between 6 pre-defined colors; blue, cyan, green, yellow, red, and magenta (ok, that’s what I call them, and those are the hex values). Turning the encoder one way will increase the speed of the shifting, turning it the other way will slow it down.

Pressing the encoder button will change it to “twinkle” mode. In this mode, you can chose one of the six solid colors by turning the encoder, and the color will subtly “twinkle”.

The third and final mode is the Rave mode. The cube will chose a random color from the color list, choose a random pixel, and flash the color on that pixel. Turning the encoder will cause the cube to flash faster/slower. Make sure you bring your glow stick!

Step 9 - Tweaking to your Cube

There are several settings/adjustments/changes you can make to your cube, all of which are controllable from the #define values in the sketch. Let’s go over them now.

The first section defines the pins on the ProTrinket that the various components are connected to. Change these values accordingly if you’ve connected them differently than the instructions.

#define DATA_PIN      6          // Neopixel data pin
#define ENC_PIN_A     5          // Rotary Encoder Pin A
#define ENC_PIN_B     3          // Rotary Encoder Pin B
#define ENC_PIN_X     4          // Rotary Encoder Push-button pin

The next section controls the various speeds, brightness, and number of colors in the cube. If you want the “default” speed of the cube to be faster/slower for example, adjust the SHIFT DELAY and HOLD_DELAY.

If you decided to build your cube with more than 5 pixels (and blind yourself in the process), increase the NUM_PIXELS accordingly.

To add additional colors, increase the SEQUENCE_SIZE, and them add your colors to the sequence array (we’ll talk about this next).

#define NUM_PIXELS    5          // Number of pixels in the matrix
#define SHIFT_DELAY   20         // Default Delay between steps in a color shift (smaller is faster)
#define HOLD_DELAY    1000       // Default Amount of time to hold at a color (milliseconds)
#define RAVE_DELAY    50         // Default Number of millis the color will be displayed on the pixel during rave mode
#define SEQUENCE_SIZE 6          // Number of colors in the sequence
#define BRIGHTNESS    255        // Sets the intensity of the neopixels. 0 is off, 255 is brightest

To modify the colors of the cube, add new colors, etc., you need to adjust the following array. If you add/remove colors, make sure you adjust the SEQUENCE_SIZE #define to match. The colors can be set in hex, or if you go digging, you can set them as RGB values, but you get the same effect.

The order is important - that’s the order the “shift” mode will shift through. It’s also the order in the “twinkle” mode as you turn the encoder. The total list of colors is the random universe that the “rave” mode selects from.

  YAMC_RGB(0x0000FF),        // Blue
  YAMC_RGB(0x00FFFF),        // Cyan
  YAMC_RGB(0x00FF00),        // Green
  YAMC_RGB(0xFFFF00),        // Yellow
  YAMC_RGB(0xFF0000),        // Red
  YAMC_RGB(0xFF00FF)         // Magenta

If you want to increase the number of “steps” in the encoder, change the ENC_MAX value to your liking. This will only affect the speed of the “shift” and “rave” modes. The “twinkle” mode bases its encoder position based on the SEQUENCE_SIZE #define. Finally adjusting the MAX_MULTIPLIER #define will increase the max/minimum speed of the shifting in “shift” mode and speed of the “rave” mode.

#define ENC_MIN       0          // Encoder minimum value (for speed control)
#define ENC_MAX       20         // Encoder max value (for speed control)
#define ENC_DEBOUNCE_DELAY 20    // Encoder push-button debounce delay (millis)
#define MAX_MULTIPLIER 3         // Multiplier for the speed changes in the cube, based on encoder position

Finally, if you get really advanced, you can design your own modes! Create a new mode function, add a new #define for it, and then add the new mode and method to the main program loop() function.

// Modes for the lamp. Press the encoder button to change modes
#define MODE_NORMAL   0          // Normal operation will shift through the defined matrix colors in order
#define MODE_TWINKLE  1          // Pick a color using the encoder from the color sequence, and it'll twinkle on that color
#define MODE_RAVE     2          // Get out your glow stick!

Step 10 - Uh, something went wrong...

Ok, you’re sure you did everything correctly...right?

Uh right.

Ok, so here are some “gotcha’s” and hints that I’ve learned along the way that you might run into.

When you first program it nothing happens. Ok, I’m not sure why, but almost every time (but not EVERY time) I first program the microcontroller, the LEDs don’t light up. Try resetting it (hit the little reset button on the TrinketPro) and letting it reboot. Just like Windows, sometimes you just gotta reboot it. After you do it once, I’ve never had to do it again.

The LEDs don’t light up/stay one color (probably blue). When wiring, it’s easy to mix up the pins for the various connections. As long as you’ve got the power/ground connections right, and you’ve managed to get the DATA pin for the NeoPixel strand in a PWM pin (the ones that have a little ~ next to them), then you don’t have to desolder anything.

Go back to your ProTrinket and take a close look at which pin you connected the first NeoPixels’ DATA IN pin to. It should be PIN 6 on the ProTrinket. If it’s not connected to Pin 6, check the #define DATA_PIN line in the sketch to the corresponding pin, assuming it’s a PWM pin. If it’s not, you’re going to have to desolder the wire and connect it to 6 (or another PWN pin).

There’s a handy schematic showing the pinouts of the TrinketPro here:

The LEDs light up, but are stuck on a single color/each one is a different color/they’re not “shifting”. Ok, this one’s a little harder, but something I’ve run into on a couple. Chances are you’ve got a short between one of your data wires and the ground wire. Take a REALLY close look at your solder joints and make sure none of them are touching. Also make sure that any exposed wire is either safely away from other wires (thus avoiding a short) or cover it up with some handy hot glue.

The Push Button on the Rotary Encoder doesn’t do anything. Chances are, the nut on the encoder shaft is too tight (insert snarky joke here). It’s easy to overtighten the nut and cause the mechanism in the shaft to get “stuck”. Try loosening the nut a little bit. If this doesn’t do the trick, double check the Pin you have the encoder pushbutton connected to. If it’s not Pin 4, switch the #define ENC_PIN_X value in your sketch accordingly.

The rotation direction of the Rotary Encoder is backwards. First, define “backwards”. Second, switch the #define entries for ENC_PIN_A and ENC_PIN_B.

If one of these doesn’t fix your problem, drop me a comment/email and I’ll do my best to diagnose your long as it pertains to the YAMC ;)