Project Overview

The NeoTrellis is controlled by the Adafruit Feather M0 Express via Circuit Python. An LED push button acts as an input. Toggle switch for powering the circuit on and off. This basic set of parts is all we need to build a little game project. This uses slightly modified demo code from the NeoTrellis guide. Special thanks to John Park and Kirby Griese Jr

DIY NeoTrellis Game

Color matching games are fun and easy to play. This project plays on the basic concept and makes use of the full color NeoPixel LEDs. On start, a single pixel will light up in a random color. Press all of the buttons and try to match the first color. Random colors will be triggered the more you press buttons. Match all buttons to the first color to win! Press and hold the push button to reset. 

Using the Adafruit Feather M0 Express, we employ a 1200mAh lithium polymer battery to make this portable – Recharge the battery over USB. An LED metal push button is used to reset the game. A mini toggle switch is used to power on the game on and off. All of the electronics are housed in a snap fit 3D printed case. 

Prerequisite Guides

If you're new to Adafruit Feather M0 Express, CircuitPython or soldering, take a moment to walk through the following guides to get you started.

Circuit Diagram

This provides a visual reference for wiring of the components. They aren't true to scale, just meant to be used as reference. This diagrams was created using Fritzing software.

Powering

The Adafruit Feather M0 Express can be powered via USB or JST using a 3.7v lipo battery. In this project, a 1200mAh lipo battery is used. The lipo battery is rechargeable via the USB port on the Adafruit Feather.

Wired Connections

Use the list below to reference the wired connections. If using an LED push button, be sure to power the LED via 3V and GND pins on the Feather (resistor is built-in).

  • SDA (Feather) to SDA (NeoTrellis)
  • SCL (Feather) to SCL (NeoTrellis)
  • 3V (Feather) to VIN (NeoTrellis)
  • GND (Feather) to GND (NeoTrellis)
  • #5 (Feather) to INT (NeoTrellis)
  • EN (Feather) to Switch
  • GND (Feather) to Switch
  • #6 (Feather) to NO (LED Push Button)
  • GND (Feather) to  COM (LED Push Button)
  • 3V (Feather) to LED+ (LED Push Button)
  • GND (Feather) to LED– (LEDPush Button)

Wire Lengths

Connections for the toggle switch and push button are the same. The NeoTrellis requires longer wires to compensate for components proximity inside the enclosure.

  • 74mm (2.9in) push button and switch
  • 128mm (5in) NeoTrellis

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.

CIRCUITPY

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)

What If I Don't Have A 3D Printer?

Not to worry! You can use a 3D printing service such as 3DHubs or MakeXYZ to have a local 3D printer operator 3D print and ship you parts to you. This is a great way to get your parts 3D printed by local makers. You could also try checking out your local Library or search for a Maker Space.

3D Printed Parts

The enclosure is comprised of four parts. Each part is listed below with a description. Parts with mounting holes and standoffs can be tapped with an M2.5 size screw tap – This creates precise threads needed for fastening screws. These parts are designed for FDM style 3D printers. 

Glitter Infused Filament from Fillamentum

The material used to print the parts in this project are from Fillamentum. From the PLA Extrafill line of filaments, Vertigo Galaxy PLA,  Rapunzel Silver PLA, and Vertigo Gery were used. Material comes in 2.85mm and 1.75mm diameters. 

nt-top.stl

Top cover snaps onto frame. Includes cutouts for elastomer buttons.

nt-tray.stl

Houses the Adafruit NeoTrellis PCB. Snaps into frame.

nt-frame.stl

Buttons and switch mount to the sides. Includes USB port cutout.

nt-bottom.stl

Houses Adafruit Feather and battery. Snaps onto frame.

Snap Fit Tolerances

The four parts are designed to snap fit together. Chamfered tabs on the inside edges of the frame lock into indentations along the lip of the top and bottom covers. To produce these tolerances, you may need to adjust printer's slice settings.

Slice Settings

Use these settings as reference. Values listed were used in Ultimaker's CURA 3.X slicing software.

  • 0.2mm Layer Height / 0.4mm nozzle
  • 0.38mm Line Width (inner & outer widths)
  • 60mm/s printing speed
  • 60% infill
  • No support materials required

Design Source Files

The enclosure assembly was designed in Fusion 360. This can be downloaded in different formats like STEP, SAT and more. Electronic components like the board, displays, connectors and more can be downloaded from our Fusion 360 CAD parts github repo.

JST Wired Connections

This project uses JST-PH2 connectors to make wiring assembly more efficient. Pre-made JST-PH2 extension wires will work, but custom wires can use silicone cover stranded wires for stronger and more flexible connections. This silicone covered ribbon cable is used to create connections for the button and switch. Sets of two wires can be pulled/peeled apart from the ribbon and used to create our connections. Groups of wires are great for maintaining organized connections. 

We'll need three sets of JST-PH2 connections (female/male) to wire all of the components. Each connection will need to be long enough to reach, but short enough to reside within the enclosure.

  • 74mm (2.9in) – Suggested Wire Lengths for Button and Switch

Pre-Made JST PH 2-Pin Cables

Adafruit carries a few pre-made 2-pin JST PH2 cables. These are great for connecting the button and switch to the Adafruit Feather.

Top view shot of JST PH 2-Pin Cable - Male Header - 200mm.
For a really long time we assumed that the JST PH didn't have a free-hanging male header version. But then we found this JST-PH 2-pin Male Cable, and we were...
$0.75
In Stock
Top view shot of a red and black JST PH 2-Pin Cable to Female Connector - 100mm.
Red and black tinned wires with a 2-pin JST PH connector on the end. 4" / 100mm long. Matches up nicely with our Lipoly chargers!
$0.75
In Stock
Front shot of JST-PH Battery Extension Cable.
By popular demand, we now have a handy extension cord for all of our JST PH-terminated battery packs (such as our LiIon/LiPoly and 3xAAA holders). One end has a JST-PH compatible...
Out of Stock

DIY JST PH2 **Silicone Cover Wires**

I really enjoy using silicone cover stranded wire for these projects. Combine them with JST-PH2 connectors and you get really strong and flexible wires.

Wire Stripping

Before making wired connections, we'll use a wire stripper to remove insulation from the tips of the wires, exposing the strands of wire. The wire gauge should match the gauge on the wire strippers. 

Tinning Wires

To prevent the wires from fraying (and to make soldering easier) we'll add a bit of solder to the exposed tips. Use third helping hands to assist in holding the wires in place while soldering.

PRO TIP: Apply heat shrink tubing to the clips of the third helping hand to prevent bite marks on your wires.

Wiring JST Connectors

Bare female JST connectors are soldered directly to the wires. These are normally attached via crimping. When soldering wires to them, tinning the connectors will make it easier to attach the wires. Tweezers can assist in better handling of the wire while soldering.    

A male jumper wire secured to third helping hands is used to hold the JST connector in place and prevents bending while soldering.

3d_printing_fJST-wire-prep.jpg

3d_printing_fJST-header-install.jpg

3d_printing_fJST-wire-header.jpg

Install Female JST Connector

The bare metal female terminals are press fitted into the plastic connector. The orientation must be correct in order for the terminals to properly lock into place. A small protrusion on the outside of the terminal is fitted through a tab in the connector – This will prevent the terminal from slipping out. 

Wiring Male JST Connectors

Male JST connectors are pre-assembled and wires can be directly soldered to the terminals. 

Apply Heat Shrink Tubing

Pieces of heat shrink tubing are added to each wire before making wired connections. This will insulate the bare exposed metal and prevent shorts. Be cautious not to apply heat to the tubing or it will shrink. 

Prep Male JST Connector

The plastic housing of the male JST connector is prone to melt when tinning the terminals with solder. A workaround is to plug it into a female JST connector. This will keep the metal terminals in place. Apply a bit of solder to the terminals. 

Solder Wires to JST

The wires are soldered directly to the terminals. The heat shrink tubing is then slipped over the exposed metal and heated to shrink and tighten around the connection. 

Male/Female JST Wires

Polarity only matters to the LED connection. The switch and button don't require specific polarity. Just be aware of which set of JST cables will be used for connecting the LED in the push button (if using the LED rugged metal push button). This first set of JST connectors can be used with either button, switch or LED. In the next pages, we'll wire up these components and create more sets of JST cables.

Button Wiring Preparation

JST-PH2 connections are used to make assembly more efficient. If using an LED push button, we will need two separate connections – Voltage and ground for the LED, and common and normally open for the button. For the wires, we're using 28AWG silicone cover stranded wire. For making the male/female connectors, we used a JST-PH2 kit

Button JST Connections

Two sets of JST cables are used to connect the LED push button to the Adafruit Feather. Use the same process from previous page to create these connections.  

Wire LED

If you decide to go with the LED metal push button, start with wiring the voltage and ground terminals. These are labeled (+ and – symbols) on the outside of the button. You can decide which JST connector, male or female, to use. Tinning the terminals with a bit of solder will help attach the wires.

Wire Button

The metal push button has three available connections: COM (ground), NO1 (normally open) and NC1 (normally closed). In this project, we'll use the COM and NO1 pins (leaving the NC1 pin unused). Polarity does not matter for this connection.

Wired Button

Inspect the wires and ensure the correct connections are made. For extra protection, use heat shrink tubing to insulate the exposed contacts. With the button wired up, we can proceed to the next steps.

Wiring Toggle Switch

The toggle switch needs a single set of JST connections. These can be the same wire lengths as before (74mm / 2.9in).

Toggle Switch Connections

We'll need a set of JST cables to connect it to the Adafruit Feather. Following the same process as before, create a new pair of JST wires.

Toggle Switch

The switch features three pins – only need two of them. The middle pin and either the far left or right pins. Apply a bit of solder to the pins to make attaching the wires easier. A panavise jr can hold the switch in place while soldering.

Wired Toggle Switch

Inspect your connections to ensure the solder joints are solid. The switch will be on the ON state when it's toggled to the middle and outer pins. OFF state (current photo) is active when the two pins are not tied.

Ribbon Cable

The NeoTrellis requires a total of five connections. To help tell the connections apart, colored jumper wires were used. A set will contain 40 wires, 5 pieces of the ten rainbow colors. Peeled off a set of five connection. Cut the set down so it's 128mm (5in) in length.

Tinning Wires

Using wire strippers, remove a bit of insulation from the tips of each wire – You may need to peel the ends apart.  Both ends of the wires will need to be tinned with a bit of solder to prevent the strands of wire from fraying. Third helping hands can assist while soldering.

Colored Connections

Take a moment to map the colors to the pins on the Adafruit NeoTrellis PCB. Common colors are red for voltage, black for ground but feel free pick your own colors. 

Tinning Pads

The Adafruit NeoTrellis features sets of pads on each side of the PCB. We'll use the five pads to the left of the text label, "Adafruit NeoTrellis". Apply a bit of solder to the five pads – This will make soldering the wires to the pads easier. 

Solder Wired Connections

The wires are soldered to the pads in particular orientation. This allows the PCB to be secured into a 3D printed tray – Wires soldered outside the PCB will not fit! Attach the wires to the five pads by soldering them in place. A pair of tweezers can assist in holding wires with fine control.

Wired NeoTrellis

Inspect your solder joints to ensure they're solid. Double check the correct set of pads are used. 

Feather JST Connections

The remaining JST connections will need to be soldered to the Adafruit Feather. There's three connections in this project: push button, LED, and toggle switch. The connection for the LED will need have the correct polarity.

LED Connection

Starting with the LED, the JST cable will connect to the 3V and GND pins on the Adafruit Feather – The ground and voltage strips are used for simplicity. Connect the JST cable from the LED to ensure the polarity is correct. Apply a bit of solder to the pins on the Feather to make attaching the wire easier.

Button Connection

Pins #6 and ground on the Feather will be used for the button connection. Polarity does not matter for this connection. If you want to use a different pin, the software will need to be changed to reflect that.

Enable Connection

The JST cable for the toggle switch will need to be wired to the EN and ground pins on the Adafruit Feather. Polarity does not matter for this connection.

NeoTrellis Connection

In preparation of connecting the NeoTrellis PCB to the Adafruit Feather, get familiar with the five connections: INT, VIN, GND, SCL and SDA.

Solder NeoTrellis Wires

Panavise Jr can help assist while soldering connections from the NeoTrellis to the Feather. Follow these connections.

  • INT to Pin #5 on Feather
  • VIN to 3V on Feather
  • GND to GND on Feather
  • SCL to SCL on Feather
  • SDA to SDA on Feather

Wired NeoTrellis and Feather

Take a moment to review your work. Make sure the connections from the NeoTrellis to the Feather are solid.

Components Review

Take a moment to gather the wired components. Check your work by connecting the various JST cables together and see if everything matches up. Now is a good time to take a moment and rework any of the connections.

Securing Feather

The Adafruit Feather will need to be secured to the bottom cover of the 3D printed case. 4x M2.5 metric machine screws are used to secure the PCB to the standoffs built into the bottom cover.

Secured Feather

Orient and place the Feather PCB on top of the four standoffs. The USB port should be facing the edge of the bottom cover. While holding in place, insert and fasten M2.5 x 5mm machine screws until fully tightened. The length of the screws matter here – 5mm is the length of the whole screw (Flat head style machine screws) any longer will not be able to fasten all the way.

Install Components to Box

The toggle switch and LED push button are panel mounted to the 3d printed box frame. The toggle switch uses a 6mm diameter hole. The push button uses a 16mm diameter hole. These include the specific hardware (washers/nuts) for panel mounting.

3d_printing_box-switch-install.jpg

3d_printing_box-switch-secured.jpg

3d_printing_box-switch-installed.jpg

Install Toggle Switch

Remove the washer and nut from the toggle switch. Then, insert the toggle switch through the inside of the box with the actuator going in first. Orient the position of the actuator to your liking. While holding in place, install the washers and fasten the nut by hand tightening or wrench for tighter hold. 

3d_printing_box-btn-install.jpg

3d_printing_box-btn-secured.jpg

3d_printing_box-btn-installed.jpg

Install Push Button

Remove the hex nut from the threading of the push button. Insert the push button into the box frame, from the outside with the JST wires going in first. While holding the button in place, thread the hex nut through the JST wires and twist to fasten onto the threading. Fasten all the way and use a wrench to fully tighten.

Install NeoTrellis PCB

Get familiar with the top and bottom of the box frame. The top side has an edge along the inside of the frame that will keep the 3d print tray in place – this prevents the tray from falling through the frame. Insert the neotrellis PCB through the bottom side. 

NeoTrellis Tray

The tray is designed to house the NeoTrellis without any hardware. The edges of the PCB snap fits to the tray. Insert the PCB through the try so the side with the NeoPixels are facing up with the lip of the tray.

Installing NeoTrellis Tray

The bottom of the tray features a cutaway for the wires to pass through. Align the neotrellis PCB so the wiring is fitted through the notch. Press the PCB down into the try to snap it into place. If it doesn't quite fit, use a filing tool to stand away the edges of the PCB (must do this in a ventilated area).

Install Tray to Box

With the neotrellis PCB fitted into the tray, press the try down into the box frame. The tray will rest of the ledge inside the box frame. The tolerances are fairly tight so you may need to firmly press down on the tray to get it to pass through the nubs on the side of the box frame.

Install Elastomer Pad

The silicone elastomer button pad features nubs that are press fitted through holes on the NeoTrellis PCB. Orient the elastomer pad so the nubs match up with the corresponding holes on the NeoTellis PCB. Lay it on top of the PCB and press down.

Install Top Cover

Orient the top cover with the box frame so the nubs along the inside match up with the indentations on the lip of the top cover. Lay the top over the elastomers and press down to lock the cover onto the box frame.

Install Battery

The bottom cover is designed to house a 1200mAh battery. Insert the battery into the built-in holder so the cable fits through the cutaway. Another cutaway, on the side, can be used to pop the battery out. Plug in the JST connector from the battery to the JST port on the Adafruit Feather – This will power on the circuit immediately.

Plug In JST Connections

Follow the wiring and sets of JST cables from the Adafruit Feather and match them up with the components. Ensure the connections for the LED are correct. Plug them together – The toggle switch can now turn the circuit off.

USB Port

The USB port from the Adafruit Feather should be oriented with the cutout on the side of the box frame. This allows access for programming and charging the battery.

Closing Box

Be considerate of the wiring before closing the box. All of the wires need to be fitted inside the box frame. Press the bottom cover onto the box frame.

Assembled Case

The top and bottom covers can still be opened by pulling them apart. A finger nail or thin tool should be able to get in-between the parts. Flip the toggle switch and test out the circuit.

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