• Tag Archives arduino
  • Arduino Flickering Code

    A number of people have asked me for the code for the Flickering LED for my Steampunk Tesla Cane.

    It’s a modified version of the standard “Fade” Arduino example code. The original code I borrowed appears to have disappeared, but this instructable (not mine) has some “flickering” sample code: that is very similar:

    Flickering Arduino Instructable

    Roughly, you make an array of values (the flicker[] below) and cycle through them. Some versions are far more complex, and generate a pseudo-random number for each step instead of a static set of values.

    int ledPin = 10;
    byte flicker[] = {180, 30, 89, 23, 255, 200, 90, 150, 60, 230, 180, 45, 90};

    void setup()
    pinMode(ledPin, OUTPUT);

    void loop()
    for(int i=0; i,7; i++)
    analogWrite(ledPin, flicker[i]);


  • Changing with the times: Tesla Cane electronics rebuild

    It’s been a busy few months without posts, but there is lots of stuff going on, some of it even coming off the back burner!

    Wild Wild West Con 4 is rapidly approaching…and since my Tesla Cane Mk II (with a copy of the Mk I electronics but with the original chip) is in the Sky Harbor Airport Steampunk Exhibition as I mentioned last time, I needed to rebuild the electronics for the Mk I cane itself. I somehow lost (or maybe they were …stolen by an Airship Pirate Gang?!?!) the original code for the flickering, I needed to recreate it. I actually found an earlier version I was fairly happy with in a separate backup, and it made sense to rebuild all the electronics using a Trinket instead of the barebones chip: easier programming (via the built-in mini-USB), battery/voltage management, easy reset, cleaner pinouts, etc.

    The Mk I electronics were very simple (see here): I used a bare Atmel ATTiny chip, a resistor, and LED. In the last few years Adafruit and other companies have come along and make really awesome low-cost ATTiny-based boards (I covered them in this post about what to do when an Arduino is too big for your project), and I’d pickup up a couple of the Trinkets to play with. Since a bare ATTiny chip is $2-4 individually and a Trinket is $8…that seems a decent deal.

    So, out with the old:

    Tesla Cane Mk I Electronics
    Tesla Cane Mk I Electronics

    And in with the new:

    Tesla Cane Mk II Electronics
    Tesla Cane Mk II Electronics

    The Trinket is slightly bigger, but being able to reprogram via USB is a great advantage!

  • Playing with a Neopixel Stick: Lithium Polymer (LiPo) battery sample use case

    In my last post, Batteries, batteries, batteries! (Or, how do I power this thing!?) I mentioned the power and flexibility of Lithium Polymer (LiPo) batteries for your projects, but said I mentioned that I hadn’t started to work with them.

    For an upcoming project, using an Arduino Gemma (which I talked about in my post about “But the Arduino is too big for my project!“) I decided to use a LiPo battery, since the Gemma conveniently has a JST battery connector on it.

    As a test,  I connected a NeoPixel Stick — another awesome piece of kit from Adafruit, to the Gemma. The Neopixel Stick, like all Adafruit’s Neopixels, is a string (in this case, a stick) of RGB LEDs with a built-in color controller. The Stick is 8 of these LEDs on a rigid circuitboard.  Each LED in the stick is really three sub-LEDs, one in Red, Green, and Blue (hence RGB). With these three sub-LEDs, you can make almost any color you can imagine. Because of the built-in color controller, you only need a single data pin (besides the two normal power connections) to control an entire group of LEDs!

    Adafruit NeoPixel Stick
    Adafruit NeoPixel Stick
    Rear (you only need 3 connectors)
    Rear (you only need 3 connectors)

    Note that if you are interested in NeoPixels (I learned about them from my friend Jeff McDaniel, who did the Teslapunk panel at Phoenix Comiccon) you should read Adafruit’s entire Uberguide, here. I’d call them a medium difficulty item, as there are some power requirements to be aware of…in short, the individual pins on an Arduino can’t handle the amperage for many of these LEDs, so you need to directly wire them to power.

    To test the LEDs, I connected the appropriate pads on the Stick to positive, negative, and D1 (digital pin 1) on the Gemma. I ran a “Larson Scanner” test — this is named after Glen Larson, who was the producer of the old Knight Rider and Battlestar Galactica TV shows, which both featured a red moving LED light (on KITT the car’s front bumper and the “eye” of the Cyclons). This test basically chased from one LED to another and altered the colors each time.

    Here’s a demo video of the setup:

    The Neopixel Stick is held in the grip, the little blue breadboard in the middle is just linking the soldered wiring to the alligator clips connected to the tiny Gemma board. Notice the silver LiPo battery pack powering the Gemma!


    I’ll mention the Neopixels are really bright, wow!

    The LiPo battery pack is 850ma, and cost around $8. So, take a guess at how long it ran that Neopixel test?

    Over 30 hours, wow!

    I think I’ll be using LiPo more in my projects!

  • But the Arduino is too big for my project!

    The Arduino is an amazing small single-board computer. The standard current generation Arduino Uno is roughly the size of a deck of cards: 3″ x 2″ x .6″, which is pretty darned small for a powerful self-contained computer. It’s much more powerful than the computers that controlled the Apollo spacecraft that went to the moon, for example!

    But…for many projects for Steampunk and Cosplay that’s still too big to hide!

    So, “back in my day” (2 years ago!) for projects like my  (like my Tesla Cane) the only choice was to use an Atmel ATTiny, the little brother of the Arduino’s microcontroller, the Atmel ATmega328, as a bare chip. The ATTiny is indeed tiny (an 8 pin chip) and I didn’t bother with any of the normal Arduino parts, such as a USB port for programming (and power), various power options (battery, etc), breaking out each pin, etc. Just the bare chip, power, and the single output to the LED. It is important to note that the chip cost me about $4 and a full Arduino Uno runs about $25.

    Full size ATmega chip vs the ATTiny
    Full size ATMega chip vs the ATTiny


    Importantly…I didn’t do several other things that I should have, like a 1uF capacitor to prevent power bounce, voltage protection, a reset pin, etc…My cane is the absolute barebones you can get. One day it’ll likely die for no reason at all because of something I didn’t do. It is, in fact, kind of the completely bad way of doing things…but at the time, I really didn’t have a choice because of the size! You should do all these things, but doing them yourself with a bare chip is a pain and not worth it! There is a better way!

    Today there are a fair number of full Arduinos and “sub” Arduinos that are amazingly small…many not much bigger than the ATTiny I used, and all much better!

    These include Adafruit’s wonderful Trinket and Gemma use the ATTiny like my cane does. The Trinket is designed more for permanent installation in objects while the Gemma (and it’s big sister, the Flora) are designed for wearables and clothing, but both work equally well for props. The most amazing part is the cost! The Trinket and Flora both run $7.95! There is no way I would have bothered with my barebones ATTiny if these things had been around then!

    Adafruit Gemma
    Adafruit Gemma
    Adafruit Trinket
    Adafruit Trinket

    If you need a little more memory for your complex program or, just as likely, more pins take a look at the Sparkfun’s Pro Mini – it’s a full-blown Arduino in a tiny package, and it’s $9.95!

    Sparkfun's Pro Mini
    Sparkfun’s Pro Mini

    Lastly, just how many Arduinos do you need? It’s a trick question! All of them!

    Just kidding.

    I have about 8 of them: A full size Arduino I’ve dedicated to programing the ATTiny chips, a couple of specialty Arduino clones I’ve purchased via Kickstarters, a pair of Arduinos with built-in special radios for a home automation project, a Gemma I just got to experiment with (love it!), and a specialty Arduino on order (via another Kickstarter) that has a tiny video screen just because it’s darned cool!

    My future projects will be built almost entirely on Trinkets, Gemmas, and Pro Minis…for their cost it just isn’t worth trying to do them yourselves with a bare chip!

  • TARDIS lantern necklace first look!

    This is a necklace I’m making for a friend. The lantern is a tiny little thing by Tim Holtz that came with an incandescent bulb. I replaced the bulb with a white LED and control the pulsing using an Arduino. I’ll eventually replace the Arduino with an ATTiny and run the whole thing from a 3v button battery.


  • Miniaturizing projects: the ATTiny85!

    A couple of the projects I’m working on will require very small electronics that still need some sort of microcontroller to do something smart, like pulse an LED, respond to a button press, etc…For larger things, I’m using the Arduino series of microcontroller boards, powered by the Atmel AVR MCU (MicroController Unit), but often the final project is to be embedded in something, like a cane, visor, or prop gun, and a full sized Arduino board is too large, even the smaller ones, like the nano, and too expensive ($30+ ) for a complete board…and they are probably overkill for what you need, having far more pins (inputs/outputs) and unnecessary parts (like headers, onboard LEDs, etc.)

    I happened across a Make Magazine article called “How-To: Shrinkify your Arduino Projects” that describes using Atmel’s ATtiny AVR chips, which are a much smaller (8 or 16 pin) and much cheaper (I got mine for less than $1 each on ebay) version of the brain of the Arduino, the ATMega328. You have less pins (2 digital, 3 analog on the 8-pin ATTiny8x series) but the darned thing is tiny, the size of my pinkie fingernail! Note that you could do this with the larger and more expensive ATmega chips, but if all you need is a simple microprocessor, the ATtiny is pretty awesome!

    The Make Article references a post from “High-Low Tech”, an MIT Research Group. The article has since been updated to reflect the support in the newest Arduino IDE (1.03 as of this post) and describes how to wire up the ATtiny to the Arduino and program it via the Arduino IDE.

    To program the ATtinys, you need an Arduino to serve as the programmer and you either wire up via breadboard the ATTiny or use an Arduino Shield for it. I got a shield from a Turkish Company, Flytron, for $20, that does both the 8 and 16 pin variants. After the Make article, lots of companies are making shields and programmers for the ATtiny platform (Sparkfun and Adafruit being the two most common and popular, but they are also all over ebay.) I do wish the shield I got had a ZIF (Zero Insertion Force) socket, as the pins bend easily taking the chip in and out, but other than that, its a nice little shield!

    So, without further ado, here is my first programmed Atmel ATtiny85, running the Arduino LED Fade sketch! Its currently powered from a full Arduino board just for convenience, but sans battery the entire setup is smaller than the 2″x1″ breadboard its running on!



  • Pip-boy fonts…

    Lots of online sources claim multiple different fonts for the pip-boy.

    Here are two of the major contenders prefaced by an in-game closeup of the same text for comparison. First is Gothic 821 BT Condensed (pay) and second is Monofonto (free):

    Font Comparison: In-game vs Gothic 821 and Monofonto
    Font Comparison: In-game vs Gothic 821 and Monofonto

    I can’t really imagine Bethesda using a free font, and the kerning/spacing on Gothic looks much better to me…but I’m not 100% convinced. I’ve seen a couple OCR fonts that look really close as well, including one that is already converted for use in the LCD I’m getting. Once I get the LCD I’ll see what that looks like. While I’m totally about authenticity in this stuff, there is diminishing returns: 90% accuracy for little work is more worthwhile that 100% accuracy for a lot of extra work. Time I could spend doing something else on the project…like making the background of scanlines work.

  • Pip-Boy: parts arrived, need more

    I ordered some parts from Sparkfun which arrived yesterday.

    The orange LED buttons I got are too small, and they don’t fit easily on a breadboard because of the arrangement of LED leads. I did get a little breakout board that helps now that a friendly EE soldered it up for me (I really need to get a soldering iron). It’ll at least let me test some things, hopefully.

    Orange LED button
    Sparkfun orange LED button (COM-10441)
    Example of the LED button on the breakout board









    The rotary encoders I got are “ok” — they may be a bit small, and the “click” when you turn them is pretty weak. They’ll do to start playing with things once I can get them working.

    I also got some green EL Wire and the appropriate connectors and inverter for the EL project.