All posts tagged NeoPixel

Toddler’s Cardboard Computer

My one-year old daughter looooooves buttons, and always wants in on the action when someone’s using a computer… so I transformed her new car seat box into the BABYTRON, inspired by the Burroughs B205.

It features a keyboard, arcade buttons, and a strip of LEDs from Blinkinlabs.

The LEDs have a built-in controller, so no wiring was required beyond USB power. In fact, the whole computer was assembled only using glue, tape, scissors, and string. The buttons don’t control anything — but they do make a satisfying “click” when pressed.

There are several ways to talk to the Blinkinlabs LEDs. I’m familiar with Adafruit’s NeoPixel library, so I told the Arduino IDE that it was a Leonardo, assigned data to pin 13, and uploaded my sketch. Code here.

I kept the brightness of each LED below 20 out of 255, because they’ll hurt your eyes if fully on. It’s also running off a portable USB battery pack, so I wanted to keep the power draw fairly low.

I did consider adding a tape drive, using a paper plate behind a round plastic cover from a food delivery container, powered by a LittleBits motor. Next time.

It turns out that this is ideal for someone who’s able to stand up while holding onto something, but can’t walk on their own. My daughter’s younger friends love it. But she’s now savvy to the buttons not doing anything, and is most interested in the power button — the one that mom and dad push. Time to build something else and recycle the BABYTRON.

Building a Ball Jar Lantern: Tutorial

Here’s how to build an LED lantern in a Ball jar, programmed to flicker like a candle. It involves a little bit of soldering and a little bit of programming, and will introduce you to Adafruit’s NeoPixel and Flora products.

LED Jar

PARTS LIST

From Adafruit:
Flora NeoPixel 4-pack (you just need one LED)
Gemma Microcontroller
2x Coin Cell Battery Holder with Switch

CR2032 battery (buy two)

From Elsewhere:
• Ball Jar and Lid
• #216 Diffusion or Tracing Paper
• Solid Core Hookup cable
• Solder
• Double-sided foam tape

Tools Used:
• Soldering Iron
• Soldering “Helping Hands”
• Wire Stripper
• Flush Cutters
• Tin Snip
• Ruler
• Scissors

WHAT IS A NEOPIXEL?

The NeoPixel is Adafruit’s brand of the WS2812 Integrated Light Source, which has a tiny driver built into an RGB LED. They’re addressable, so you can run a whole chain of them from one data pin on an Arduino or other microcontroller board. Plus, Adafruit has written a library, so the code is extremely simple.

For example, if you have three pixels chained together and want to make them green, yellow, and red like a stoplight, you would write:

strip.setPixelColor(0, 0, 255, 0);
strip.setPixelColor(1, 255, 255, 0);
strip.setPixelColor(2, 255, 0, 0);
strip.show();

The four variables are: pixel number (where the first pixel in the chain is 0), red value (from 0 to 255), green value (0 to 255), blue value (0 to 255).

Then strip.show(); executes those settings.

The NeoPixels are sold in different layouts, from flexible strips to matrices to rings. In this project we’ll use the Flora Series 2 NeoPixel, which is a single LED with four pads: power (+), ground (-), data in, and data out.

2-flora-pixels

The Flora series is mainly designed for wearable projects, so the pads are well suited for sewing onto clothing with conductive thread. They’re also very easy to solder.

GEMMA BOARD

The controller board we’re using is from the same series. It’s a Gemma, which is the tiny, inexpensive version of the Flora, also designed for wearables.

Gemma500A

This board runs most Arduino code, and is programmed from the Arduino IDE (programming environment). The thing is, it’s so small that it needs to use a special bootloader to upload code.

The easiest way to do this is to download Adafruit’s Arduino IDE.

https://learn.adafruit.com/introducing-trinket/setting-up-with-arduino-ide

As a bonus, this comes with the NeoPixel library installed. If you’re using NeoPixels with a full-sized Arduino board, you’ll need to install the library separately (https://github.com/adafruit/Adafruit_NeoPixel).

If this is your first time using the Arduino IDE and you’re on a Mac, it may not let you launch the software. Go to System Preferences / Security & Privacy / General, and change “Allow applications downloaded from:” to “anywhere.” You may need to click on the padlock to select this button.

We’ll come back to this, but now it’s time to connect the NeoPixel.

WIRING

First we need to attach wire leads to the Flora NeoPixel, and then attach that to the board.

Cut three pieces of solid core wire, around 3 inches long, and strip 1/4″ or so off one end of each.

LED Jar

From the back of the pixel, solder wires to: ground (-), power in (+), and data in. Data in is the one with an arrow pointing from the wire to the pixel. Data out has an arrow pointing out.

It’s easier if you solder one wire on at a time, using helping hands to hold the parts in place. Be sure to clip onto a solder pad on the NeoPixel so you don’t crush any tiny components.

LED Jar

In the pictures, I use black for (-), red for (+), and yellow for data.

With a flush wire cutter, snip off the short wire ends.

LED Jar

Now, clip the wires to the same length, about an inch and a half long, long enough for the pixel to be centered above the Gemma with the wires reaching to the soldering pads around the edge. Strip 1/4″ off the ends.

LED Jar

Solder the black (-) wire to GND, the red (+) wire to 3Vo, and the yellow (data) wire to D0. Snip off the wire ends.

LED Jar

LED Jar

ABOUT POWER

The Flora NeoPixel is rated at 5V, but a small number of pixels can be powered by a lower voltage like the 3.3V regulated output from the Gemma’s 3Vo pin. This pin can provide up to 150mA of current. The Flora NeoPixel will draw 60mA at its brightest, so if you build a project with more than two pixels, they should be powered separately.

Also for larger projects, Adafruit recommends adding a resistor between the data pin and the data in, and a capacitor bridging the power and ground on the strip. And, you need to make sure that the data voltage is close to the power voltage: running a 5V strip from a 3.3V Gemma board might be unreliable.

Check out Adafruit’s NeoPixel Überguide for details about all of this.

CODE

Download the Arduino code here:

https://github.com/timpear/NeoCandleWorkshop

“NeoPixel_Basic_Setup” is the basic setup you need for any NeoPixel project. It calls up the library and initializes the NeoPixel strip. The only things you would need to change for most projects are the data PIN number on the board (here it’s soldered to D0, so we have it set to 0), and the number of pixels in the strip. The content in the void loop() section is just a sample.

“CandleWorkshop1” steps the pixel through a sequence of different colors.

Upload this file to the Gemma board to test it out.

The process of uploading is slightly different than with a normal Arduino. In the Adafruit Arduino IDE menus, select Tools / Board / “Gemma 8MHz,” and Tools / Programmer / “USBtinyISP.”

Now, connect the Gemma with a USB mini cable. There is a tiny button on the Gemma, and pressing it enters bootloader mode for 10 seconds. The red light lets you know that it’s listening. While it’s in this mode, press the upload button on the Arduino IDE.

For more detailed instructions, visit https://learn.adafruit.com/introducing-trinket/starting-the-bootloader. They talk about the Trinket, which is the Gemma’s less-wearable sibling, available in 3.3 or 5V versions.

LED Jar

If all goes well, your pixel should be changing colors. Try uploading different color combinations and timing. The RGB values can be anywhere between 0 and 255, not just one or the other like in the sample.

At this point, you can upload “NeoCandle_1” to the Gemma and skip ahead to ASSEMBLE THE JAR. But if you want more of an explanation of what’s going on in the code, read on.

“CandleWorkshop2” introduces a few more concepts that are used in animating flicker.

First, the same color sequence from the previous sketch has been removed from the main loop, and turned into a function. It has a new name: colorStep(). So now, when you run colorStep() in the main void loop(), it will call it up and run through it once. Additionally, it will accept a variable: an integer named “pause.” So when you type colorStep(2000), it will hold each color for 2 seconds.

Second, there is a function called fader(), which is a standard for-loop, fading the red and green pixels from 0 to 255 and back down again.

Third, the function fadeRepeater() nests the fader() function, repeating it a variable number of times. All of these can be called from the main loop, keeping it tidy.

So with that in mind, load “NeoCandle_1” onto the Gemma. It’s much more complicated, but uses the same ideas.

It starts with an RGB mix of 255, 135, 15, which looks like a good candle-flame orange to my eye. This is set as variables at the top (redPx, grnHigh, bluePx), so it can be adjusted without having to go through the entire code. Then, the green value dips down and back up again, simulating the flicker of a candle; as it looses oxygen, it gets darker and redder.

The function burnDepth sets how many steps below grnHigh the green value will dip during the normal burn effect.
flutterDepth is a more dramatic flicker effect.
cycleTime is how long each fade cycle lasts. The default is 120 ms, so it will flicker eight times per second.

The next set of functions are used for calculations in the setup. There is a flickerDepth which is a little more than half way between burnDepth and flutterDepth. And the delays are calculated from the cycleTime and number of steps green needs to dip. For example, if burnDepth is 14 and flutterDepth is 30, the fade effect will take over twice as long for flutter than burn. To prevent it from slowing down, the delay time in the flutter for-loop is cut in half.

Once all this math is taken care of, the animation becomes simple. In the main loop, you just call up the different flicker modes, with the duration you want each one to last, in seconds.

ASSEMBLE THE JAR

Once the code is uploaded to the Gemma, you can remove the USB cable and power it from a battery. The two CR2032 coin batteries provide 6V of power, which is more than you need, but very convenient. Put the batteries in the holder and plug it into the white power jack on the Gemma. The battery holder has a tiny power switch.

Next, cut a small wedge in the jar lid, big enough for the cable to pass through. Be careful of sharp edges!

LED Jar

Use double-sided foam tape to attach the Gemma to the inside of the lid, and the battery holder to the outside. You may want to loop the power cord around the Gemma, tucking it beneath or taping it down.

LED Jar

LED Jar

LED Jar

Finally, cut an 8″ by 4-1/2″ piece of paper to line the inside of the jar. I used tracing paper for my first jar, but prefer theatrical lighting diffusion (#216 is full diffusion, and is sold in sheets at theatrical or film lighting sources like B&H). Also cut a circle of white paper to rest on the bottom of the jar, to reflect light back up.

LED Jar

LED Jar

I use my lantern when wandering around at night. I also made a light painting using the same parts, minus the jar.