FastLED for the Apple II: Hack to the Future!

These days, I hack LEDs.  I’m the co-author (with Daniel Garcia) of the FastLED library for driving tons of high speed LED pixels and strips using microcontrollers like Arduino and Teensy.

But back in the day, I hacked a lot of Apple II.  I published a couple of shoot-em-up games (with Geoffrey Engelstein), all written in lovingly hand-crafted 6502 assembly language.

Finally I decided it was time to link the present to the past: to connect a hundred high-speed RGB LEDs to an Apple II, somehow, and ‘port’ our FastLED library to 6502 assembly language.

Well, I did it, and it works.  My new creation, “FastLED6502”, can drive a hundred 24-bit RGB pixels at more than 30 frames per second from an Apple //e :

The Details

Here are the details of “FastLED6502”:

  • “FastLED6502” is a lightweight port of FastLED’s core functions to 6502 assembly language for the Apple ][, Apple ][+, Apple //e, and Apple //gs.
  • Supports APA102 / Adafruit DotStar LED strips, as well as LPD8806 and WS2801 (though those two are not fully tested yet).
  • The LED strip is connected to the Apple II using the 16-pin DIP game port on the computer’s motherboard.  The 9-pin DB joystick/mouse port on the back of the //c, //c+, and //gs cannot be used, as it lacks the TTL digital output signals needed to drive the LED strip.
  • 24-bit FastLED Rainbow colors are included, along with FillRainbow, Random8 and a number of other useful functions from FastLED’s main library.
  • Everything had to be re-written from scratch in 6502 assembly language.  Luckily(?), I still remember how to do that.
  • The assembly code knows the binary serial protocols for the APA102 (Adafruit DotStar), LPD8806, and WS2801 LED driver chips.  Depending on which one you select, FastLED6502 transmits the LED colors in the correct protocol over the game port TTL digital output lines.
  • Considering that the Apple II sports a 1MHz 6502 so slow that even a “NOP” takestwo cycles, overall performance is pretty good: more than 30 frames per second for a 100-pixel strip.
  • Speaking of speed, or lack thereof, “three-wire” clockless LED strips such as the WS2811 NeoPixel are not supported now, nor will they ever be.  The CPU is would need to be at least 20X faster to support them, and it isn’t.  For that you want an Arduino or Teensy, and FastLED proper:
I gave the code its public debut at Veracode Hackathon 7.  (The theme was “Cozy Cabin” — I don’t usually wear plaid.)
I don't usually wear plaid.

FastLED6502 at Veracode Hackathon 7

How’s it work?

So how does this all work? Well, you connect the CLOCK and DATA_IN pins from the LED strip to a couple of pins on your Apple II’s DIP game connector port, add power, and you’re ready to go.  The Apple II’s game connector not only has inputs for joysticks, paddles, buttons, and so on, but it also has a few digital outputs — and that’s what FastLED6502 uses to deliver signals to the LED strip.  On all the 16-pin DIP Apple II game ports (except for the //gs!), there’s even one pin that delivers a super-fast digital pulse; pin 5 is the C040STROBE line, which can pulse twice as fast as the other digital outputs.  If you choose that for your CLOCK pin, the FastLED6502 code automatically shifts into high gear, and you get faster performance.   FastLED proper does this, too, in a much fancier way; it’s amusing that ‘little’ FastLED6502 does some of this, too.

The Code

The code is in the “extras” directory here (and eventually on FastLED’s main branch, but not yet)
Here’s the FastLED6502.s65 source code itself: here’s the RainbowDemo.s65, as shown in video:

This is Crazy

Overall, this bit of code is completely nuts, and we don’t expect anyone to use it.  At all.  Ever.  Accordingly, we’re not going to really support it, either.  At all.  Ever.  It was a labor of love and a creation of pure modern retrocomputing insanity.  But here it is, in all it’s insane glory, “FastLED6502”.
And now, if you cut me, I’ll bleed 16,777,216 colors at thirty frames a second.

Iteration impels improvement.

This thing that I am casually holding up in one hand is an 7′ x 3′ LED tapestry, plus diffuser, plus controller box, plus all mounting hardware, plus power supply and extension cord (rolled up inside for easy transport). It’d fit in the carrying bag for a folding camp chair.


Now, truth be told, I’m not crazy about the layout of LEDs on it (too gridular)…


…so there will be at least one more iteration of this “small” one before I build the “big one” for playa. But. It feels good to have come this far: the previous incarnation had to be wheeled around in a suitcase, and required complicated mounting due to it’s own weight.

Next iteration will focus on making the layout more ‘organic’ (the way I like it), and continuing to rethink how the diffuser is held at the right distance from the light.

Lanyard-mountable LED throwies

At the last “HacKidThon”, we showed a passel of kids how to make LED “throwies”. Each one is a nothing more than an LED, a coin cell battery, and a magnet so the contraption can stick to metal surfaces, walls and buildings, and hang there glowing.

This week, someone asked me if we could modify the classic design somehow so that the LEDs could be attached to lanyards, instead of magnets. We wanted it to be as cheap and easy as the rest of the “throwie” recipe.

A little brainstorming with Eleanor, and we came up with this: plastic-coated paperclips!


The paperclips actually help hold the LED leads in place; we put tape around them as usual, though that’s not shown in the picture. The plastic coating keeps the paperclip from shorting out the positive and negative battery terminals.

The coated paperclips cost less than a penny apiece, and come in colors that match the LEDs. Victory!

Easter Egg Hunt Rules, 2014.

We love doing Easter egg hunts.  But as the girls get faster, smarter, and more wily, merely finding the eggs is no longer challenge enough.  I’ve gotta slow ’em down somehow, and this is how I do it: each girl gets an empty basket (I use traditional Jack-O-Lantern baskets), and sheet of instructions helping her know which eggs are for her, and which are for her step-sister.  Each year, the instructions require more careful reading and invoke increasingly complicated rules.

New this year: the contents of two of the eggs altered the interpretation of rules, retroactively. This fact itself was part of the published rules… this time.




The best part was watching the girls excitedly pounce as they found the first eggs, and then stall completely as they had to stop and puzzle out exactly who’s egg it actually was that they’d just found.





P.S. Here are the previous year’s Egg Hunt Rules (2013):


Fire2012: an open source fire simulation for Arduino and LEDs

I’ve built and programmed a couple of different ‘fire’ simulations for Arduino and LEDs, and I’ve had numerous requests over the years to share the source code.  I’ve always been happy to share my work; the holdup has been that before I share my code for the world to peer at, I like to clean it up a little.  I like to give the code a clean shave and scrub under its fingernails before it steps out onto the wide open Internet where it might have an audience with Her Royal Majesty, The Queen of England.  It could happen.

Anyway, I finally cleaned up the code for one of my simplest and most legible ‘fire’ simulations, and I give it to you, your Majesty, and everyone else, too. Here’s a video of the code in action on a 30-pixel strip of WS2812B LEDs (or maybe WS2811) and an Arduino.  Source code link is below the video.

Full source code is here:  The simulation itself is only about 25 or 30 lines of code.  It uses our (open source) FastLED library to drive the LEDs.

Discussion about the code and how to port it and use it are here on the FastLED discussion group on G+




If I’m confused, it must be playtime.

Some things we try because we have a clear idea where we want to be and a clear idea how to get there.

Some things we try because we’re suddenly shocked to find that the heretofore completely impossible has suddenly and surprisingly come within practical reach.

And some things we try just to play, and to explore what if. We start with our heads full of simple ideas that turn out to be wrong, and we awkwardly replace them in torn out bunches with new confused half-understandings that, later, will let us reach something wholly unexpected.

I’m not sure which of these things in doing here, which means it’s probably that last one.


Running 2 Amps of LEDs through an Arduino Nano

The Arduino Nano provides up to 0.5 Amps of regulated +5v output, on it’s “+5V” pin, which can drive between 10-30 addressable LEDs, depending on your chosen brightness and animation patterns.  Even if you connect a 2 Amp USB power supply (e.g. an iPad charger), the Nano’s little voltage regulator will overheat if you try to draw more than 0.5 Amps from the “+5V” pin on the Arduino.

However, you can ‘tap’ the pre-voltage-regulator power traces on the Nano’s circuit board, and drive 2 Amps of LEDs (over 100) ‘through’ the Nano, and do it in a way that keeps your wiring simple.  Basically, you can find the places on the Nano’s board where the raw USB power connections are exposed, and tap into them there.


But, OK, if you wish to continue…

1. Flip the Nano over so you’re looking at the bottom side.

Two Amp Arduino Nano

2. The unfiltered, unregulated +5 signal from the USB port is available on the board near the base of the D2 pin.  Carefully solder a wire (red, for +5v) directly to the exposed component pin on the circuit board.

3. A convenient companion GND connection can found on the center pin of the power regulator itself.  Solder a wire (black, for ground) to this pin.

4. By powering your LEDs from these direct-power traces (and thus directly from the USB power source), instead of through the Nano’s half-amp-max voltage regulator, you can drive up to about two Amps worth of LEDs, provided that you plug the Nano into a 2 Amp USB power adapter.

I’ve used this technique in probably six or eight Arduino Nano projects, and nothing’s caught fire (yet).  With a little probing around, you can also find similar ‘hacks’ for other models of Arduino, e.g., the Uno, Leonardo, etc., but since power is handled differently on each board, you’ll have to figure it out differently for each board design.

Good luck!


Get every new post delivered to your Inbox.

Join 867 other followers