Overview

Goggles are a great accessory for dressing up your costume -- be it for Halloween or cosplay. There are many styles and genres which can be enhanced by goggles, including cypberpunk, steampunk, dieselpunk, Burning Man, mad science, and clockwork, to name a few.

This year, our daughter decided to be a "steampunk girl" for Halloween! So, we decided to dress up her prop costume goggles with some LED rings animated with a sort of clockwork ticking pattern.

Using a Gemma M0 running CircuitPython is a great way to drive the pair of 16 NeoPixel rings, particularly because CircuitPython makes it so fast to iterate on color and timing in our program.

Follow along with this simple build to make your own stylish clockwork cog goggles!

You can supply your own goggles, or pick up a set of welding-style costume goggles in the Adafruit store.

In addition to the parts listed here, you will also want some foam stick tape to attach the electronics to your goggles, as well as a small drill bit and drill to run the wiring through.

You'll need a soldering iron and solder, as well as some wire cutters and strippers.

1 x Adafruit GEMMA M0
Miniature wearable electronic platform -- CircuitPython capable!
2 x NeoPixel Ring - 16 pixel RGB LED
LED rings with integrated drivers
1 x Lithium Ion Polymer Battery
3.7V 500mAh battery
1 x Silicone Cover Stranded-Core Wire
2m of black 26AWG wire
1 x Silicone Cover Stranded-Core Wire
2m of yellow 26AWG wire
1 x Silicone Cover Stranded-Core Wire
2m of green 26AWG wire
1 x USB cable
A/MicroB for programming the Gemma M0
The Trinket M0 is another great choice for this project, particularly if you plan to add a few more buttons or sensors, since it has more IO pins available.

Assemble Circuit and Goggles

The circuit we'll make is pretty simple. Each NeoPixel ring will have three connections to the Gemma M0:

  • GND to GND
  • V+ to VOUT
  • Digital In to D1 or D0 respectively for the left and right ring

The LiPo battery will provide power to the Gemma M0 and the NeoPixels

Start by cutting a 6" lengths each of red, black, and yellow wire. Then, cut a 4" length each of red, black, and green wire. Strip a 1/4" of insulation from both ends of each wire.

Now, solder the 6" wires to the left NeoPixel ring, following the guide and circuit diagram from above.

Then, solder the 4" wires to the right NeoPixel ring.

The "LEFT" and "RIGHT" sides are relative to the goggles while being worn.

Drill three holes in each goggle "lens" if you're using molded plastic prop goggles. These need to align with the wire placement of each NeoPixel ring.

 

Or, if you're using goggles with removable lenses, remove/unscrew them now -- the wires will simple drop inside the goggle "cups".

Place each NeoPixel ring over the goggle lenses, and pass the wires through to the inside. This is where the Gemma M0 and battery will live.

Flip over the goggles, and then solder the wires on as shown in the diagram.

 

NOTE: the photos show the NeoPixels being powered by the 3.3V pad on the Gemma M0, which works, but soldering to the VOUT is preferable.

Plug in the battery, and then affix the Gemma M0, NeoPixel rings, and battery to the goggles with double stick foam tape, making sure to leave the on/off switch exposed and the USB port accessible.

Next, you'll plug the Gemma M0 into your computer with a USB cable and begin programming it!

CircuitPython Setup and Code

Now it's time to set up the Gemma M0 for use with CircuitPython and our cog animation code.

If you haven't already, follow this guide to preparing the Gemma M0, including updating it with the latest version of CircuitPython.

After prepping the Gemma M0 to run CircuitPython we'll also need to add a NeoPixel library. This guide tells you how, as well as providing a good primer on using NeoPixels on the Gemma M0 with CircuitPython.

Download the adafruit-circuitpython-bundle-2.0.0-20170915.zip (or newer) from the releases directory and then unzip it somewhere easy to find, such as your desktop. Then, copy the neopixel.mpy file to your CIRCUITPY's lib directory on the Gemma M0.

Finally, trash the neopixel.py file that was already in that same lib directory.

Once you've got things working, you can edit the main.py file on the Gemma M0 to adjust what it actually does. No need for a software IDE, complaining tools, or flashing the chip -- when you code with CircuitPython all you need is a text editor. Edit the code, save it to the Gemma M0, and it immediately runs!

The incredible ease of editing files, even when you're on the go, makes Gemma M0 running CircuitPython the perfect combination for cosplay effects and props!

Copy the code from below, and then paste it into your text editor. Then save the file to your Gemma M0 as main.py.

# CircuitPython Gemma Gear goggles
# uses two 16 NeoPixel rings (RGBW)
# connected to Gemma M0 powered by LiPo battery

import time

import board
import neopixel

pixpinLeft = board.D1  # Data In attached to Gemma pin D1
pixpinRight = board.D0  # Data In attached to Gemma pin D0
numpix = 16

# uncomment the lines below for RGB NeoPixels
stripLeft = neopixel.NeoPixel(pixpinLeft, numpix, bpp=3, brightness=.18,
                              auto_write=False)
stripRight = neopixel.NeoPixel(pixpinRight, numpix, bpp=3, brightness=.18,
                               auto_write=False)


# Use these lines for RGBW NeoPixels
# stripLeft = neopixel.NeoPixel(pixpinLeft, numpix, bpp=4, brightness=.18,
#    auto_write=False)
# stripRight = neopixel.NeoPixel(pixpinRight, numpix, bpp=4, brightness=.18,
#    auto_write=False)


def cog(pos):
    # Input a value 0 to 255 to get a color value.
    # Note: switch the commented lines below if using RGB vs. RGBW NeoPixles
    if (pos < 8) or (pos > 250):
        # return (120, 0, 0, 0) #first color, red: for RGBW NeoPixels
        return (120, 0, 0)  # first color, red: for RGB NeoPixels
    if pos < 85:
        return (int(pos * 3), int(255 - (pos * 3)), 0)
        # return (125, 35, 0, 0) #second color, brass: for RGBW NeoPixels
        # return (125, 35, 0)  # second color, brass: for RGB NeoPixels
    elif pos < 170:
        pos -= 85
        # return (int(255 - pos*3), 0, int(pos*3), 0)#: for RGBW NeoPixels
        return (int(255 - pos * 3), 0, int(pos * 3))  # : for RGB NeoPixels
    else:
        pos -= 170
        # return (0, int(pos*3), int(255 - pos*3), 0)#: for RGBW NeoPixels
        return (0, int(pos * 3), int(255 - pos * 3))  # : for RGB NeoPixels


def brass_cycle(wait, patternL, patternR):
    # patterns do different things, try:
    # 1 blink
    # 24 chase w pause
    # 64 chase
    # 96 parial chase
    # 128 half turn
    # 230 quarter turn w blink
    # 256 quarter turn
    for j in range(255):
        for i in range(len(stripLeft)):
            idxL = int((i * patternL / len(stripLeft)) + j)
            stripLeft[i] = cog(idxL & 64)  # sets the second (brass) color
            idxR = int((i * patternR / len(stripRight)) + j)
            stripRight[i] = cog(idxR & 64)  # sets the second (brass) color
        stripLeft.show()
        stripRight.show()
        time.sleep(wait)


while True:
    brass_cycle(0.01, 256, 24)  # brass color cycle with 1ms delay per step
    # patternL, patternR

The code will start running immediately, and the two rings will begin animating!

if you'd like, you can edit the colors and patterns of the cog animation to suit your costume. Look at the comments in the code to see how to make adjustments.

Rock the Goggles

All that remains is to don the goggles, turn on the switch on the Gemma M0, and look the part!

Any time you want to adjust the animations, you can simply plug in the Gemma M0 to any computer and tweak the main.py file in a text editor!

Or, try to adjust the code so that the D2 pad on the Gemma M0 acts as a capacitive touch input button to toggle the different animation patterns.

This guide was first published on Oct 03, 2017. It was last updated on Oct 03, 2017.