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.
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.
Page last edited January 18, 2025
Text editor powered by tinymce.