Coding

This project uses the neopixel library from the CircuitPython. For more information on NeoPixel animations, check out the LED animation guide and the NeoPixel Uber Guide.

Download the Adafruit CircuitPython Library Bundle

In order to run the code, we'll need to download a few libraries. Libraries contain code to help interface with hardware a lot easier for us.

Use the Feather nRF52840 page on Installing CircuitPython to get the library that matches the major version of CircuitPython you are using noted above.

To run the code for this project, we need the three libraries in the Required Libraries list below. Unzip the library bundle and search for the libraries. Drag and drop the files into a folder named lib on the CIRCUITPY drive (which appears when your board is plugged into your computer via a known good USB cable) if the directory is not already on the Feather nRF52840).

Required Libraries 

  • adafruit_led_animation
  • neopixel.mpy

The Mu Python Editor

Mu is a simple Python editor that works with Adafruit CircuitPython hardware. It's written in Python and works on Windows, MacOS, Linux and Raspberry Pi. The serial console is built right in, so you get immediate feedback from your board's serial output! While you can use any text editor with your code, Mu makes it super simple. Instructions for Mu are available here.

Installing or Upgrading CircuitPython

You should ensure you have CircuitPython 5.0 or greater on your board. Plug your board in with a known good data + power cable (not the cheesy USB cable that comes with USB power packs, they are power only). You should see a new flash drive pop up.

If the drive is CIRCUITPY, then open the boot_out.txt file to ensure the version number is 5.0 or greater. 

Download: file
Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit Feather nRF52840 Express with nRF52840

Click on the download link below to grab the project code directly from GitHub.

Upload Code

Ensure the file is named code.py and drop it onto the CIRCUITPY drive main (root) directory that appears when your Feather is plugged into your computer via a known good USB data cable. The code will run properly when all of the files have been uploaded including libraries.

import time
import board
import neopixel
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.pulse import Pulse
from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.animation.rainbow import Rainbow
from adafruit_led_animation.animation.colorcycle import ColorCycle
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation import helper
from adafruit_led_animation.color import PURPLE, AQUA, RED, JADE, ORANGE, YELLOW, BLUE

#Setup NeoPixels
pixel_pin = board.D6
pixel_num = 16
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=.9, auto_write=False)

#Setup NeoPixel Grid
pixel_wing_vertical = helper.PixelMap.vertical_lines(
    pixels, 8, 2, helper.horizontal_strip_gridmap(8, alternating=True)
)
pixel_wing_horizontal = helper.PixelMap.horizontal_lines(
    pixels, 8, 2, helper.horizontal_strip_gridmap(8, alternating=True)
)

#Setup LED Animations
rainbow = Rainbow(pixels, speed=.001, period=2)
pulse = Pulse(pixels, speed=0.1, color=RED, period=3)
blink = Blink(pixels, speed=0.5, color=RED)
colorcycle = ColorCycle(pixels, speed=0.4, colors=[RED, ORANGE, YELLOW, JADE, BLUE, AQUA, PURPLE])
comet_v = Comet(pixel_wing_vertical, speed=0.05, color=PURPLE, tail_length=6, bounce=True)

#Setup the LED Sequences
animations = AnimationSequence(
    rainbow,
    pulse,
    comet_v,
    blink,
    colorcycle,
    advance_interval=5.95,
)

#Run ze animations!
while True:
    animations.animate()
This guide was first published on Sep 01, 2020. It was last updated on Sep 01, 2020.
This page (Code) was last updated on Sep 01, 2020.