Setup Adafruit Feather M0 for CircuitPython

Your Feather M0 should already come with CircuitPython but maybe there's a new version, or you overwrote your board with Arduino code! In that case, see the below for how to reinstall or update CircuitPython. Otherwise you can skip this and go straight to the next page.

CircuitPython Libraries

Install the Adafruit NeoTrellis library for Circuit Python by downloading the latest bundle. Unzip the file and locate the NeoTrellis library. Drop the library into a folder named "lib" on the CIRCUITPY drive.

For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:

  • adafruit_neotrellis
  • adafruit_seesaw
  • adafruit_bus_device

Before continuing make sure your board's lib folder or root filesystem has the adafruit_seesaw, adafruit_neotrellis, and adafruit_bus_device files and folders copied over.

Upload The Code

Copy and paste the code below into a new text document (we recommend using Mu as your editor, which is designed for CircuitPython.). Save the file and name it as main.py

Once the files has been uploaded to the drive, the board will automatically reboot and run the code.

NeoTrellis Demo

This is a modified version of the Circuit Python NeoTrellis demo code. On start, the NeoPixels run through a wipe animation. On press down, the buttons will light up white. On release, the NeoPixel will light up in a random color. Press and holding the reset button while pressing any of the elastomer buttons will reset the grid and light up that button in a random color. This makes for a simple color matching game – The point of the game is to match all of the button colors to the first pixel.

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

import time
import random
import board
from board import SCL, SDA
import digitalio
import busio
from adafruit_neotrellis.neotrellis import NeoTrellis

# create the i2c object for the trellis
i2c_bus = busio.I2C(SCL, SDA)

# create the trellis
trellis = NeoTrellis(i2c_bus)

button_pin = board.D6

button = digitalio.DigitalInOut(button_pin)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

# some color definitions
OFF = (0, 0, 0)
RED = (25, 0, 0)
YELLOW = (25, 15, 0)
GREEN = (0, 25, 0)
CYAN = (0, 25, 25)
BLUE = (0, 0, 25)
PURPLE = (18, 0, 25)
WHITE = (127, 127, 127)

PUSH_COLOR = GREEN
ANIM_COLOR = WHITE

COLORS = [RED, YELLOW, GREEN, CYAN, BLUE, PURPLE]


# this will be called when button events are received
def blink(event):
    # turn the LED on when a rising edge is detected
    if event.edge == NeoTrellis.EDGE_RISING:
        if button.value:
            trellis.pixels[event.number] = WHITE
        else:
            for j in range(16):
                trellis.pixels[j] = ANIM_COLOR
                time.sleep(.05)
                trellis.pixels[j] = OFF
                time.sleep(.05)

    # turn the LED off when a rising edge is detected
    elif event.edge == NeoTrellis.EDGE_FALLING:
        trellis.pixels[event.number] = random.choice([RED, YELLOW, GREEN, CYAN, BLUE, PURPLE])

for i in range(16):
    # activate rising edge events on all keys
    trellis.activate_key(i, NeoTrellis.EDGE_RISING)
    # activate falling edge events on all keys
    trellis.activate_key(i, NeoTrellis.EDGE_FALLING)
    # set all keys to trigger the blink callback
    trellis.callbacks[i] = blink

    # cycle the LEDs on startup
    trellis.pixels[i] = ANIM_COLOR
    time.sleep(.05)

for i in range(16):
    trellis.pixels[i] = OFF
    time.sleep(.05)

while True:
    # call the sync function call any triggered callbacks
    trellis.sync()
    # the trellis can only be read every 17 millisecons or so
    time.sleep(.02)

This guide was first published on Oct 09, 2018. It was last updated on Oct 09, 2018.

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

Text editor powered by tinymce.