GEMMA M0 boards can run CircuitPython — a different approach to programming compared to Arduino sketches. In fact, CircuitPython comes factory pre-loaded on GEMMA M0. If you’ve overwritten it with an Arduino sketch, or just want to learn the basics of setting up and using CircuitPython, this is explained in the Adafruit GEMMA M0 guide.

These directions are specific to the “M0” GEMMA board. The original GEMMA with an 8-bit AVR microcontroller doesn’t run CircuitPython…for those boards, use the Arduino sketch on the “Arduino code” page of this guide.

Below is CircuitPython code that works similarly (though not exactly the same) as the Arduino sketch shown on a prior page. To use this, plug the GEMMA M0 into USB…it should show up on your computer as a small flash drive…then edit the file “code.py” with your text editor of choice. Select and copy the code below and paste it into that file, entirely replacing its contents (don’t mix it in with lingering bits of old code). When you save the file, the code should start running almost immediately (if not, see notes at the bottom of this page).

If GEMMA M0 doesn’t show up as a drive, follow the GEMMA M0 guide link above to prepare the board for CircuitPython.

# SPDX-FileCopyrightText: 2017 Leslie Birch for Adafruit Industries
#
# SPDX-License-Identifier: MIT

# Jewel Hairstick by Leslie Birch for Adafruit Industries
# Based on NeoPixel Library by Adafruit

import time

import board
import neopixel
from digitalio import DigitalInOut, Direction

pixpin = board.D1
numpix = 7

led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# defaults to RGB|GRB Neopixels
strip = neopixel.NeoPixel(pixpin, numpix, brightness=.1, auto_write=True)
# uncomment the following two lines for RGBW Neopixels
# strip = neopixel.NeoPixel(
#   pixpin, numpix, bpp=4, brightness=.3, auto_write=True)

# You can have fun here changing the colors for the code
color1 = (236, 79, 100)  # Salmon Pink
color2 = (246, 216, 180)  # Cream
color3 = (174, 113, 208)  # Lavendar
color4 = (182, 31, 40)  # Red
color5 = (91, 44, 86)  # Purple

while True:
    # the first number is the pixel number for Jewel. O is the center one
    strip[1] = color1
    strip[2] = color1
    strip[3] = color1
    strip[4] = color1
    strip[5] = color1
    strip[6] = color1
    strip[0] = color2
    time.sleep(3)

    strip[1] = color2
    strip[2] = color2
    strip[3] = color2
    strip[4] = color2
    strip[5] = color2
    strip[6] = color2
    strip[0] = color3
    time.sleep(3)

    strip[1] = color3
    strip[2] = color3
    strip[3] = color3
    strip[4] = color3
    strip[5] = color3
    strip[6] = color3
    strip[0] = color4
    time.sleep(3)

    strip[1] = color4
    strip[2] = color4
    strip[3] = color4
    strip[4] = color4
    strip[5] = color4
    strip[6] = color4
    strip[0] = color5
    time.sleep(3)

This code requires the neopixel.py library. A factory-fresh board will have this already installed. If you’ve just reloaded the board with CircuitPython, create the “lib” directory and then download neopixel.py from Github.

This guide was first published on Mar 30, 2015. It was last updated on Apr 18, 2024.

This page (CircuitPython Code) was last updated on Apr 18, 2024.

Text editor powered by tinymce.