All posts tagged Adafruit

Highchair Blinky

Here’s my third baby/toddler blinky toy, and first official entry to the canon of IKEA hacks… the blinking high chair, aka the Antiloputer.

This is four arcade buttons and four smart full-color LEDs, drilled into an IKEA Antilop high chair (a spare tray is $5). The brain is a 5v Adafruit Pro Trinket, powered by four AA batteries.

The default mode is the same as the blinky my dad made for me long ago: press the red button and the red light lights up, press the green button and the green light lights up, and so on.

Holding down all the buttons at once lets you switch modes: mode two is like mode one, except each light stays on until the next one is pressed. Mode three is like a typewriter, and mode four is a step sequencer.

This was my first time programming with the FastLED library to control the LEDs. Download the code here.

highchair

I suspect the high chair wouldn’t make it through airport security — below is what it looks like inside… Normally, baby legs are protected from the electronics (and vice versa) by a piece of heavy cardboard.

highchair-inside

The buttons are attached between the regulated 5v power rail on one side, and pins 10-13 on the other, with a 10k ohm resistor running to ground from each. The LED data is on pin 9, and power for the LEDs also comes from the 5v power rail, through the Trinket. I did this since the 6v coming directly from the batteries is too much for the NeoPixels.

The Trinket can only provide 150 mA, which is pushing what four LEDs will draw at max brightness. Fortunately, the FastLED library has a line where you can specify the max current, and it will dim the LEDs as needed. Genius.

highchair-board

The LEDs are below the high chair tray, aimed up through small holes. I hot glued translucent plastic containers from an art store over the holes, which glow nicely. Be warned, babies are stronger than hot glue, although there’s no danger if the containers get ripped off. You could probably skip the holes and containers, since the LEDs are bright enough to show through the tray.

Also check out the BABYTRON for more blinking.

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.

(Wire) Stripper Cake

This is a case of knowing your audience: my friend Matt is deeply involved in the world of creative DIY electronics, and appreciates a good (ie. terrible) pun. So for Matt’s bachelor party, fellow groomsman Ethan and I arranged for a stripper to pop out of a cake — but in this case, it was a wire stripper (an electrician’s tool) animated by a jumble of electronics, in a cake which we built.

After dinner, we lit the candles on the cake (it was also Matt’s birthday), and in the dim light of the BBQ joint, the illusion was convincing.

Cake

But once Matt made his wish and blew the candles out, the top opened up revealing a stripper dancing on a stage, complete with flashing lights and music!

Cake

The cake’s frosting is a sheet of white foam material from an art store, held on with Velcro stickers. The decorative chocolate frosting is brown caulk.

Beneath the frosting is a laser-cut plywood frame, with threaded dowels, nuts and washers. The top has a hinged lid with the stage slotted and glued inside.

Cake

Cake plans
Cake plans
Cake plans

A hidden power switch in the back provides 6V from four AA batteries to an Arduino Duemilanove microcontroller, which we programmed to run the show.

Cake

First, all the lights flash red, as a motor with built-in gear reduction box pulls a string attached to the lid’s counter-lever, opening the lid and raising the stage. (We used this motor driver).

Cake

Cake

Once the stage is up, the lights change to a cycling rainbow pattern. We used four of Adafruit’s 8-NeoPixel strips, all chained together in series. The first NeoPixel strip is on stage, lighting up the wire stripper.

Cake

Other NeoPixel strips are on the middle ring, lighting the inside of the cake in all its mad scientist glory. The white foam frosting is translucent, so the whole cake glows brightly on the outside.

Cake

Beneath the stage, a motor with an elliptical wheel makes the wire stripper kick its leg and dance the can-can.

The original plastic geared motor for this section melted when we tried to solder on the power cables. The Radio Shack replacement didn’t have enough torque. So we used a spare littleBits motor. It later burned out because we’d run out of time and didn’t regulate the voltage, but by then it had done its job.

Cake

Music is from a chip I ripped out of a greeting card years ago, wired up to a small speaker. It plays the theme from “The Good, The Bad, and The Ugly.”

Cake

When you’ve had enough of the show, you can reach in through the top and press a microswitch (center of the picture, on the middle ring), which stops the dancing, turns all the lights to blue, and closes the cake up again.

Cake

We built the whole thing in very little time, and it has a cobbled-together, hot glue aesthetic. Not the finest engineering, but Matt loved it, which is all that matters.

Cake

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.

Azimuth Video Installation

Azimuth is a video capture and playback installation with simple wireless controllers. It’s based on the Déjà View Master, modified for the art show “Being and Time.”

The basic layout is a webcam feeding into a Mac Mini running a Max/Jitter patch, controlled by three wireless Arduino-based devices, and displayed on two monitors: a Zenith television on a table, and a projector mounted under the table, projecting onto the floor.

azimuthshow2

The screen normally displays a frozen image of the empty room. As you turn the clock-like controller, you scrub back and forward through a constantly-recording half-hour video buffer. The frames flash on screen as long as you’re moving the hand, but it fades back to the frozen frame when movement stops.

To add an element of unpredictability, it sometimes scrubs through a pre-recorded video of walking to the venue, or operates normally but with the image sliding off the TV and onto the floor via the projector.

Jitter works by using a matrix of pixel information to manipulate video. In Azimuth, the video buffer is accomplished by recording sequentially-numbered Jitter binary files (each matrix file is one video frame) to a hard drive, and separately reading the matrix files back and displaying them. Once the maximum number of frames has been written, the counter resets and writes over the first frames, letting you record in a loop.

Here are the basic components of this operation, set to record one minute at 15 fps (900 frames), and read back and display other frames, chosen by the number box on the right.

maxbufferrecord

Grab this Max patch here

———-begin_max5_patcher———-
976.3oc0XFsbiaBEF9Z6mBFM8RWM.BPhdU5ywNcxfjHNxUVxKBuwa2Ye26Aj
sih2HY4Ta4zKhmHDF94iCmyu4GymEjVuS2Df9CzWPyl8i4yl4ax0vr8OOKXs
ZWVopw2sfpsqS0lfEsu5o5JaSw+ncuhPCw6aF5TQUo15+Jj8MVu0BMY+9Fc6
7ETTYCVfBRUUKCP+09dsQYydtnZ4iFclssiBXj4LRR7BDg4lDTRh6SJNDe76
Uj6kWc5pemE7pLZmTuNnczbkZsWEA+ooPUFbbtMP6Vs4QckJsz2Cr6U+b9b2
GKFKizu.53vnZ067KjfUE1vWJpxqeAsoT88TU1eid.ff1rAQtJD0iR.oChSF
U3wICHXRjCjDgbHdRuXddcY1Zk0TrCwPYOqLnDdDhkfuJ7BF8GaG8KhZrnPJ
iwEI.5hFDcB4GMVLqtr1zN0X2LfCShjThv8eXIi5la2b9AP8ZcSiZo9WXsQq
xQ+FYApMLZ77k1GeGMQI7Pojw4QvYatOjL48AZL98AJYJBFypWmVToQvh4YD
D2fvnvU6dB8vFUdNr3fmwHN72CPH0xkZSChdIbj0KGufnSB.PIDpv4.WkCln
LlLEmrS2Zs0UAWdhrgVvwhPIIFNEBKXh.NNFwYh1U5.mF6I145EgTuQWkCbp
dI5o5x7qRRpQUirKOXvltDS4.OjzA2+Y2wL6Y0ack9PR7EkKmeF2DG9y83P.
CvSHki4IuEXwrAcVP64DC6pRr9RPmUV2nu8IlEQghHHZBRfvfzJQ3DobApsP
We4kID9EmXtyxa01FawSEYJaAjp3CdlrOr4NTd6oFjA1QM1ITKdXpIt6T6+V
stIuRW2DccqzM7OIHdR7v1W.3KlBqFbVc6CB6PGJARkISjNOA7nA8Twuidp9
zXvuK5X7PlLJNlcVC9DJ4SnC+AX8WsgKMpz6Ek6jkLgExSDIdOq33ggr3+OP
9qq0VSMRHtJm1OqwuN9X5T1QvGlmxo3Dusd4xRcvEemPi01Vxwk6v194mI+1
4t1G+XFTBUCO4lx75y09agPS8VS1gEz9KjB8pxx0PU6pi0r+xq+VLD8XmdtH
OW6e+g3k7hFm3x6+RoFqbbWJwY0C8M84VJm3QimIRO3QnmSX3MUOjwvG7joG
uU+yJHeN6ISQhOaJhNNEMcQ07wsoMgg0zwDVymN8v+jsic5lw6qH1DpnSmqd
1ynSVkrwgno7f+XN1eRAu6es0OZs9ViQpMa9l1zreL8RA7Atp01sXg+whp1G
8VtBL5uUbn+scPY.idVvk2VSqoycIBvxILO+b9+Bn2hk4C
———–end_max5_patcher———–

There is more math involved in keeping track of the current frame and rolling back through zero.

The projection on the floor is black, but image appears where the camera picks up movement. The patch subtracts the 8-bit value of each pixel of the previous frame from the current frame: where the pixels are the same, the value will be zero. Where the value is different, it will light up. It’s like velociraptor vision.

azimuthscreen

The button controller swaps the output monitors, putting the frame differencing on the TV screen and the freeze frame on the floor via the projector. The frame differencing is quite popular: the kids love dancing in front of it. But it has a practical function too. Part of the Max patch adds up the value of all the cells in the frame to determine whether anyone is in the room. The more movement, the higher the total value. If the number stays below a set threshold for more than a few minutes, it will assume that the room is empty and update the freeze-frame.

The other control box has a knob, which switches between five channels. Some channels read back from other matrix “banks,” where the five-digit matrix file begins with a different number. The main video loop is 10000-17200 (add 10000 to the counter value, max of 7200 for 30 minutes at 15 fps), a busy time saved from the show’s opening is 20000-27200 (add 20000), a pre-recorded movie of riding the subway and walking to the venue is 50000-53400, and so on. Another channel adds vertical roll to the live video feed, like an old TV. All adjust the brightness and color in some way.

Any controller will take over whatever’s happening in screen, and the result of pressing the button or knob will time out and revert to the empty frame if left alone.

azimuthboxes1

The boxes are all handmade oak frames with laser-cut semi-transparent acrylic front and back, echoing the Zenith television.

The big box has a rotary encoder with a clock hand attached, so it can spin continuously in either direction. The encoder is connected to a Teensy 3.0 microcontroller which runs Arduino code. It sends one command repeatedly if turned clockwise, and another command if turned counterclockwise, via a serial connection with an XBee wifi radio and adapter.

It’s powered by a 2,500mAh lipo battery (the Teensy and XBee operate at 3.3v), and uses Sparkfun’s Wake on Shake as a power switch. This device is brilliant. It has a gyroscope, and turns on if there’s any movement. It then stays on as long as there is power going to the wake pin — this comes from one of the Teensy pins, which is programmed to stay on for 15 minutes after the last time the controller’s been used.

I used a breadboard with power rails removed to hold the Teensy and XBee, since it provides a flush, solid connection. Double-sided tape, industrial strength Velcro, and hot glue keep everything in place. The back panel is held on with machine screws.

boxAinside2

The smaller boxes are similar, but use an Adafruit Trinket for the logic. One has a 10k linear potentiometer, and the other uses an arcade button. Each has a panel-mount power switch on the bottom of the box.

boxBinside

The receiver uses a Teensy 3.1, which relays incoming serial messages from the XBee to the Mac Mini over USB. I’d normally send a serial connection directly into Max, but since this installation needs to run reliably without supervision, I set the Teensy to appear as a standard keyboard. Messages from the controllers are sent as keystrokes, and the Max patch responds accordingly. This also made programming easier, since I could emulate controller action with keystrokes.

The receiver is housed in a spare Raspberry Pi case with a hole cut in the top for the XBee. I also added a kill button to stop the patch from running and quit Max by sending another keystroke. The Mac Mini is set to launch the Azimuth patch on startup, so between that and the kill button, no keyboard or mouse is needed from day to day.

Arduino code for the controllers and receiver is here.

azimuthRcv

The Mac Mini connects to the Zenith TV via a series of adapters: mini display port to VGA, VGA to RCA, and RCA to RF (on channel 3). The projector is configured as the second monitor, with a direct HDMI connection. I don’t recommend working on a complex Max patch on a 640 x 480 screen.

All in all, the installation runs well. Video is stored on a solid state laptop hard drive in a USB 3 enclosure, and most of the video processing happens on the GPU using the Gen object (jit.gl.pix) in Jitter. Some people were tentative when using the controllers, but others dove in and had a good time.

Blinky Love Note

I made a blinky love note for my sweetheart this Valentine’s Day, because what’s more romantic than Morse code?

morseblinky

A single LED paints a 6″ x 6″ canvas with light. It first tells a story through color, and then slowly pulses a secret message in Morse code, fading from deep to light pink.

The smart LED is run from a 5v Adafruit Trinket, powered by 4 AA batteries. Download the code here. (This just blinks “hello world.” The secret message will remain secret).

LED Strip Clock

I just put together a clock with Adafruit’s 60-NeoPixel LED strip, running off a Teensy 3.0 microcontroller. The flexible 1-meter strip has 60 RGB lights, so different colors represent the second, minute, and hour — you can read it like a normal clock if it’s in a circle, but you can also leave it in a straight line or drape it over something for the Salvador Dalí look.

Version 1 of the clock code advances the second using the delay() command, and moves the minute every 60 seconds and hour every 60 minutes. It’s a good exercise in procedural logic, but loses time quickly.

Version 2 uses a crystal soldered directly onto a Teensy 3.0, which will keep time if you attach a watch battery. Look at the Teensy Time Library page for more info.

The LED clock lets you pick different color schemes, add faint dots every 5 or 15 minutes (or none), and turn on blinking hour “chimes.” Right now you need to set these options in the Arduino IDE and re-upload, but I’ll add the ability to change that with buttons or a knob at some point.

View or download the code here.

pixelclock1

I don’t have any pictures of the final clock in action — I gave it to my dad.

pixelclock2

[UPDATE 5/24/14]

I’ve discovered some design problems with this project. First, Adafruit recommends adding a capacitor between the – and + on the NeoPixel strip, and a 300 to 500 ohm resistor between the Teensy’s data pin and the NeoPixel data-in (at the NeoPixel end of the connection). This doesn’t affect the clock’s performance, but protects the NeoPixels from damage.

Second, I’ve gotten reports from someone who built this project that occasionally the second-hand LED stays on until the next time it passes by. I got a lot of glitches the first time I had v1 hooked up, but that got resolved when I used a different power supply. But the Teensy 3.0 uses 3.3V logic, and the NeoPixels are powered at 5V.

The Adafruit NeoPixel Überguide says that the data has to be at least 70% of the power or its message will get lost, and 3.3V / 5V is 66%. Close enough to work most of the time, but I’m guessing that the glitches occur when the signal doesn’t get through.

The best thing to do is add an I2C-safe Bi-directional Logic Level Converter to boost the 3.3V data to 5V. But if you’re using a Teensy 3.1 which has 5V tolerance on all digital pins (and presumably won’t get damaged by talking to a 5V device), then try this revised code for v2. I added redundancy to the erase and write message, to give it a better chance of getting through.

I’m checking to make sure that, glitches aside, nothing will get damaged with this setup. Stay tuned…

LED Candle in a Jar

I’ve been wanting to create a small light with realistic fire animation, so hot off the workbench in time for mid-winter: a flickering LED candle.

Its brain is a programmable microcontroller, running a smart RGB LED via a single data pin, housed in the lid of a jar. I used Adafruit’s Atmel-powered Trinket — a tiny, inexpensive board available in 3.3V or 5V flavors.

Here are three prototypes:

1) A self-contained 3.3V candle with a single Flora NeoPixel, powered by a tiny rechargeable 150mAh lipo battery inside the lid, with a pushbutton toggle power switch hot glued to the outside of the lid.

lantern3v

2) A 5V single-pixel candle, with Trinket on the outside for powering via USB, plus an extra 2.1mm socket for external wall or battery power. I used a nail to punch holes in the lid for the wires, and a diagonal cutter for the power socket. The Trinket is held down with hot glue.

lantern5v1

3) A 5V 8-pixel candle using Adafruit’s 8 NeoPixel Stick, with all electronics inside the lid and a 2.1mm power socket on top. The Trinket can handle 150mA output, which is right around the stick’s draw when all pixels are set to candle flame yellow (R=255, G=100, B=10) — but the stick jumps over 200mA when fully lit, so it gets its power upstream from the Trinket.

lantern5v8

The jars have a white paper disc at the bottom and a tracing paper tube running the jar’s height. I plan on replacing them with some theatrical lighting diffusion so nothing bursts into flame — probably not a risk, but you never know.

The Arduino code runs a basic fade on the green pixel, causing it to dip down and back every 120 milliseconds, roughly 8 times per second. When the green dips, the light gets dimmer and redder, as if it’s losing oxygen.

An RGB mix of 255, 100, 10 (on a scale of 0 – 255) looks like a pretty good candle flame yellow to me. The starting green pixel value is “grnHigh.” You then set how much below grnHigh the green pixel should dip for normal burning, and when it’s flickering more. “grnLow” is grnHigh minus the dip value.

The main function is a basic for-loop, called fire()

void fire(int grnLow) {
  for (int grnPx = grnHigh; grnPx > grnLow; grnPx--) {
    strip.setPixelColor(0, redPx, grnPx, bluePx);
    strip.show();
    delay(fDelay);
  }  
  for (int grnPx = grnLow; grnPx < grnHigh; grnPx++) {
    strip.setPixelColor(0, redPx, grnPx, bluePx);
    strip.show();
    delay(fDelay);
  }
}

So green starts at grnHigh, the max green value, and decreases until it reaches grnLow, then goes back up again. fDelay is calculated by doing some math with the number of steps to keep the cycle time constant.

The next set of functions all call fire() with adjusted dip and delay time. Your options in increasing amount of animation are: on(), burn(), flicker(), and flutter().

The main loop just looks something like this, with the variable as the number of seconds you want each animation to run:

void loop() {
  burn(10);
  flicker(5);
  burn(8);
  flutter(6);
  burn(3);
  on(10);
  burn(10);
  flicker(10);
}

The Adafruit NeoPixels officially run on 5V, but according to the power page of the Adafruit NeoPixel Überguide, small numbers of NeoPixels can run off 3.7V. (I’m powering them from the 3.3V pin on the 3.3V Trinket, and it seems to work). The thing to consider is that green and blue pixels draw more power, so they’ll be dimmer and the whole RGB effect will be warmer. So grnHigh, bluePx, burnDepth, and flutterDepth all need to be tuned higher for the 3.3V version. I eyeballed 3.3V next to 5V, and include both values in the sketch’s comments.

lanternOn

For the 8-pixel strip (above), I created a color and flicker-depth gradient that was more exaggerated toward the top, and not at all at the bottom. It’s supposed to look like the flame height is dancing. It looks more convincing, but the portability of the battery-powered 3.3v model’s pretty nice — and the lid fits on any Ball jar (below).

ITPjar

Get the full code here: https://github.com/timpear/NeoCandle

Asteroids Controller with Raspberry Pi

The 1979 arcade version of Atari Asteroids is a beautiful thing.

A white triangle battles lethal polygons on the glowing phosphors of a vector display. The two-note pulse of the music is syncopated by the “pew pew pew” of your effort to stay alive. The controls are as minimal as the graphics, and yet the game itself is complex, never the same twice.

I am a fan.

Years ago, I wired up parts from a scrapped Asteroids machine to control a computer via USB. It’s a beast. So when I had access to the resources at NYU’s ITP Camp, I decided to learn some new tools and make a refined desktop version. This one is designed for a tiny Raspberry Pi computer running an arcade machine emulator (MAME), so all you need to provide is power in and audio/video out.

Asteroids Pi

I’ve included links to design files throughout this page — be sure to open the PDFs in a program that can handle layers. Or, here’s a zipped folder with all the files in one place:

DesktopAsteroidsPlans.zip

The Design

First up, I made vector artwork of the Atari Asteroids control panel by tracing a photo in Illustrator. (I’d actually done this a few years ago for a different project).

measuring

Asteroids Control Art

asteroids_controls.pdf (editable PDF)
asteroids_controls_cs3.ai (Illustrator file)

I decided how small the face could be and still have a comfortable layout, and how tall the controller needed to be to house all the components. From there I sketched up the basic design, and started fabrication with the frame.

The Frame

The acrylic faceplate wraps around 3/4″ plywood end caps, which are connected with two 1.5″ x .5″ plywood rails.

The end pieces have 3/8″ grooves for the acrylic and rails. The CNC machine (robot miller) carved these first, before making a deeper pass to cut the outer shape.

CNC_asteroids_sides.pdf

CNC1
CNC2
CNC3

That done, it needed some good old cabinet art. I made a black and white vector image from the original arcade marquee, and etched that with the laser cutter in raster mode.

asteroidsmarquee_BW_vectors.svg
LASER_asteroids_sideart.pdf

Image link: marquee art
Image link: screen bezel art

marquee
sides etched

Finally, I carved out the rails with a table-mounted router. Nothing computer-driven here, but I did make a diagram. The slots are for removable acrylic shelves.

SHOP_asteroids_rails

The Faceplate

I used 1/4″ clear acrylic for the faceplate to show off the components. The control panel file has layers for raster etching (the artwork) and vector cutting (edges and button holes) with a laser cutter. The plans are flopped so the art is etched on the inside.

There are also 3 shelves that slide into the grooves in the wood. The smaller ones have mounting holes for a breakout board and terminal.

LASER_asteroids_faceplate.pdf
LASER_asteroids_shelves.pdf

LASER_asteroids_faceplate

cut acrylic

ITP has a large strip heater for bending acrylic. I heated up the laser-cut piece along one seam, holding it just above the heater. I flipped it over every minute or so to heat it evenly and prevent warping or blistering.

bending acrylic

Eventually it was soft enough to flex slowly. I put the shorter edge on the table, and holding the sheet evenly, pressed it forward. Holding a piece of wood along the seam helped start the crease straight. I had to re-heat the fold throughout the process, using the heater on the outside and a heat gun along the inside.

I matched the folds to the curve of the plywood end pieces. There was eyeballing involved. It’s not perfect but it’s secure, shiny, and strong.

bent acrylic
assembled1

Assembly and Wiring

I finished the wood with Briwax and glued it all together. The faceplate’s curved shape is enough to hold it in place, but it’s still easy to remove by lifting up on the front edge.

I wired up the buttons with quick disconnects and it looked like this:

final
21_final

The buttons are from an original Asteroids arcade machine, so they’re the old leaf switch type. You can’t get much simpler: a spring-loaded plunger presses two pieces of metal together. This was standard in arcade games until the mid-1980s, when they were replaced with micro-switches. The leaf switch is easier for rapid-fire and finesse. The micro-switch is more compact and goes “click.”

24_final

I scrounged my old buttons at Vintage Arcade Superstore in Glendale, California. The leaf switch buttons were meant for a thin metal plate, and just barely fit around the 1/4″ acrylic. A major supplier of new parts is Suzo-Happ.

I also got two original cone-shaped Atari start buttons. They’re supposed to blink when you insert a coin, but the old parts box I went through didn’t have any with working lights.

A micro-switch inside a hole on the front signals that a coin’s been inserted.

25_final

I wired the buttons to a small Perma-Proto Raspberry Pi Breadboard from Adafruit (details below), which was mounted to the acrylic shelf with 1/4″ standoffs. I also ran wires to a terminal on the other end, in case I ever want to attach the buttons to something other than a Raspberry Pi.

19_final
20_final

When it’s all put together, the Raspberry Pi computer sits on the large center shelf, with access for video, audio, and power cables running out the back.

26_final

Raspberry Pi

The Raspberry Pi is a tiny, inexpensive ($30 or $40, depending on the model), project-friendly Linux computer that came out in early 2013.

Adafruit has an excellent tutorial on setting up a Raspberry Pi to play classic arcade games, written by Phillip Burgess. It leads you through setting up a RasPi from scratch, installing a MAME (Multi Arcade Machine Emulator), and getting arcade buttons to work.

I modified the button wiring plan to suit the Asteroids controls. The buttons are wired to the RasPi like this:

Raspberry Pi pin, Asteroids function
#17, Hyper-Space
MOSI (GPIO 10), Thrust
MISO (GPIO 9), Right
#23, Fire
#24, insert coin
#25 (GPIO 25), Left
#4 (GPIO 4), Two Players
CE1 (GPIO 7), One Player
GND, ground rail

And I changed the appropriate lines of the “retrogame” utility code to this:

struct {
        int pin;
        int key;
} io[] = {
//        Input    Output (from /usr/include/linux/input.h)

        {  17,      KEY_SPACE     },
        {  10,      KEY_LEFTALT     },
        {  9,      KEY_RIGHT     },
        {  23,      KEY_LEFTCTRL     },
        {  24,      KEY_5     },
        {  25,      KEY_LEFT     },
        {  4,      KEY_2     },
        {  7,      KEY_1     }
};

Instructions for doing this are in the tutorial.

At some point I might add two more internal switches to trigger KEY_ESC and KEY_ENTER, to quit and shutdown (using an alias/shortcut) with just the controller.

I had a bit of trouble getting the MAME ROM (game file) to work. In the end, I had to unzip the Asteroids Rev. 2 folder, change the file extensions so the names matched the missing file names that the MAME asked for, re-compress the folder, and put that zipped file into the roms folder on the RasPi. The MAME complains that two of the files are funky, but it seems to run fine.

Finally, once everything was working, I set the RasPi to boot directly into Mame4All when it’s turned on. Instructions are here. Since everything is stored on a cheap SD card, I have one dedicated to Asteroids.

Hello World, Goodbye Asteroid

It works!

I mainly built this to learn some new tools. Maybe next I’ll learn Python and write a new game for five buttons, or maybe I’ll use it to run live visuals.

As for now, it’s time to break out a projector and throw a rooftop Asteroids party.

For more Asteroids love, check out AtariAsteroids.net. (I run the site. Like I said, I’m a fan).