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 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
from rainbowio import colorwheel
import board
import neopixel
from digitalio import DigitalInOut, Direction
pixpin = board.D1
numpix = 5
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=True)
def colorWipe(color, wait):
for j in range(len(strip)):
strip[j] = (color)
time.sleep(wait)
def rainbow_cycle(wait):
for j in range(255):
for i in range(len(strip)):
idx = int((i * 256 / len(strip)) + j)
strip[i] = colorwheel(idx & 255)
time.sleep(wait)
def rainbow(wait):
for j in range(255):
for i in range(len(strip)):
idx = int(i + j)
strip[i] = colorwheel(idx & 255)
time.sleep(wait)
while True:
colorWipe((255, 0, 0), .1) # red and delay
colorWipe((0, 255, 0), .1) # green and delay
colorWipe((0, 0, 255), .1) # blue and delay
rainbow(0.05)
rainbow_cycle(0.05)
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 22, 2025
Text editor powered by tinymce.