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 GEMMA M0 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 GEMMA M0).

Required Libraries 

  • adafruit_dotstar.mpy
  • adafruit_pypixelbuf.mpy
  • 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. 

Adafruit CircuitPython 5.3.1 on 2020-07-13; Adafruit Gemma M0 with samd21e18

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

Upload Code

Ensure the file is named and drop it onto the CIRCUITPY drive main (root) directory that appears when your GEMMA M0 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.

# SPDX-FileCopyrightText: 2020 Noe Ruiz for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
import neopixel
import adafruit_dotstar

LED = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1) #Setup Internal Dotar
LED.brightness = 0.8 #DotStar brightness

NUMPIX = 7        # Number of NeoPixels
PIXPIN = board.D2  # Pin where NeoPixels are connected
PIXELS = neopixel.NeoPixel(PIXPIN, NUMPIX) # NeoPixel object setup

RED = 7 #Number of pixels to be red
BLUE = 0 #First pixel

while True:  # Loop forever...
    #Make the internal dotstar light up.
    LED[0] = (100, 0, 255)

    #Select these pixels starting with the second pixel.
    for i in range(1, RED):
        # Make the pixels red
        PIXELS[i] = (100, 0, 0)

    #Make the first neopixel this color
    PIXELS[BLUE] = (0, 0, 100)

This guide was first published on Aug 25, 2020. It was last updated on Nov 27, 2023.

This page (Code) was last updated on Nov 27, 2023.

Text editor powered by tinymce.