Overview

This guide provides two soundboards based on the Adafruit NeoTrellis M4. they each speak phrases for each letter of the english alphabet from A to Z.

The first soundboard is animal themed and based on the book The ABC book by C. B. Falls, published in 1923 and out of copyright. It is available in the Internet Archive.

The second is robot themed based on the book, Ladyada's E is for electronics, is published by Adafruit which is under a Attribution-ShareAlike 3.0 Unported license.

Both books can be downloaded for free in PDF form and they have black and white drawings suitable for coloring!

Parts

This project requires the Adafruit NeoTrellis M4 package. You will need a known, good USB A to micro-B cable to load software.

Other parts depend on if you'd like your project portable or not. You can select headphones or speakers. If you want portability, a cell phone recharge battery is ideal, otherwise you'll need 5V power for the speaker and for the NeoTrellis.

You can buy a pre-printed E is for Electronics coloring book or download a PDF later in this guide.

Adafruit NeoTrellis M4 with Enclosure and Buttons Kit Pack

PRODUCT ID: 4020
So you've got a cool/witty name for your band, a Soundcloud account, a 3D-printed Daft Punk...
OUT OF STOCK

USB cable - USB A to Micro-B

PRODUCT ID: 592
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or...
$2.95
IN STOCK

Coloring book - "Ladyada's E is for electronics"

PRODUCT ID: 1000
Ladyada's "E is for Electronics" is a coloring book adventure with electronic components and their inventors.Makers of all ages can learn, color, and share...
$9.95
IN STOCK

Pick your sound output:

USB Powered Speakers

PRODUCT ID: 1363
Add some extra boom to your audio project with these powered loudspeakers. We sampled half a dozen different models to find ones with a good frequency response, so you'll get...
OUT OF STOCK

Cell-phone TRRS Headset - Earbud Headphones w/ Microphone

PRODUCT ID: 1966
These earbud headphones are the perfect accessory for your FONA - they've been tested to work with our modules - but can be used with any iOS or Android device that uses a TRRS...
$3.95
IN STOCK

Pick Your power, to stay or to go:

5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable

PRODUCT ID: 1995
Our all-in-one 5V 2.5 Amp + MicroUSB cable power adapter is the perfect choice for powering single-board computers like Raspberry Pi, BeagleBone or anything else that's power...
OUT OF STOCK

USB Battery Pack for Raspberry Pi - 10000mAh - 2 x 5V outputs

PRODUCT ID: 1566
A large-sized rechargeable battery pack for your Raspberry Pi (or Arduino, or
$39.95
IN STOCK

Enclosure Assembly

The acrylic enclosure is quick and easy to assemble. Each part is horizontally symmetrical, so there is very little worry about placing them in a "wrong" direction.

Prep

First, you have the satisfying task of peeling off the protective paper from the acrylic pieces. If you peel off all of the paper without tearing them you will have seven weeks of good luck. Do not squander them.

adafruit_products_IMG_2337_2k.jpg

adafruit_products_IMG_2338_2k.jpg

Elastomer Pads

Place both of the button pads into the top piece as shown. Note, there are two pairs of rubber registration nubs which must align with their associated holes on the Trellis M4 board, so match the orientation as seen in the photos.

adafruit_products_IMG_2344_2k.jpg

adafruit_products_IMG_2345_2k.jpg

Place the Trellis M4

Place the Trellis M4 board down onto the elastomer pads with the NeoPixels and button contacts aligned with the buttons as shown. Make sure all of the sixteen registration nubs fit into their associated holes on the PCB.

Frame Layer

Now, place the frame layer which helps hold the board in place.

adafruit_products_IMG_2348_2k.jpg

adafruit_products_IMG_2352_2k.jpg

Penultimate Layer

This next layer has some large cutouts in it to allow for parts clearance.

adafruit_products_IMG_2353_2k.jpg

adafruit_products_IMG_2354_2k.jpg

Back Layer

It's the final layer! Lay it down and get ready for some fastening action.

adafruit_products_IMG_2355_2k.jpg

adafruit_products_IMG_2356_2k.jpg

Fasteners

Place the five nylon M3 screws through their holes from the front of the case toward the back, then thread the nuts onto them and finger tighten.

adafruit_products_IMG_2359_2k.jpg

adafruit_products_IMG_2360_2k.jpg

adafruit_products_IMG_2362_2k.jpg

adafruit_products_IMG_2371_2k.jpg

adafruit_products_IMG_2372_2k.jpg

Your Trellis M4 is ready for use!

Customization

Are you the sort of tinkerer who feels the urge to customize things? We knew it! In case you want to try your hand at building a custom enclosure for your Trellis M4, and make all your other DJ/Producer friends jealous, here are the CAD files to get you started. Use them on a laser cutter to created a unique wooden faceplate. Or, print the top piece out with ill graphics on a color printer, trim the button holes and screw holes, and make a cool skin. You might even want to use the templates as a reference for 3D modelling a case!

It's easy to press the Trellis M4's reset button through the case using a small object such as a headphone plug, chopstick, or 5mm LED. But, if you're doing a lot of development in Arduino and resetting a lot, you may want to make a button extender. Here's a file you can 3D print for that!

Setting up CircuitPython and Troubleshooting

After assembly, plug your NeoTrellis into a computer (mac/PC/Linux) and look for a new flash drive in the operating system file explorer/finder program. It should be named CIRCUITPY. If you browse the files on this new drive, you'll see a file named boot_out.txt. If you see this, then you should be set. If not, go to troubleshooting below.

CircuitPython

The NeoTrellis M4 Express will be programmed using CircuitPython, the easy to use language on Adafruit's Express products. Are you new to using CircuitPython? No worries, there is a full getting started guide here, although you can start without editing any code.

The code is in text files so you can easily make changes with your favorite text editor. Adafruit suggests using the Mu editor to edit your code and have an interactive REPL in CircuitPython. You can learn about Mu and its installation in this tutorial.

This project requires CircuitPython version 4.0.0 alpha or later which does ship with NeoTrellis. Please do not use an earlier version of CircuitPython or libraries as they will not provide the functionality needed for this project.

Libraries

The code uses several libraries for helper code. Please go to the CircuitPython libraries releases page and download the zip file for CircuitPython 4.x to your computer hard drive. It will have a name similar to adafruit-circuitpython-bundle-4.x-mpy-20181211.zip but the date will most likely be different (as Adafruit adds more features),

Go into the library zip file and copy the following files to your NeoTrellis CIRCUITPY drive into a subdirectory named /lib:

  • Directory adafruit_bus_device
  • Directory adafruit_fancyled
  • adafruit_matrixkeypad.mpy
  • adafruit_trellism4.mpy
  • neopixel.mpy

Troubleshooting

You can use the serial capability in Mu or a serial terminal program to connect to the NeoTrellis M4 to interact with the CircuitPython prompt. You can see error messages, restart the program, etc. If you use a terminal program, set it to the COM port that appears when the device is plugged in. In Windows, Device Manager will show a keyboard when NeoTrellis is plugged in. Right click, Properties, Hardware will show the COM port. Connect at 9600 baud.

Problem: I don't see the CIRCUITPY drive when I plug the NeoTrellis M4 into my computer or I see a drive named TRELM4BOOT instead.

Solution: Ensure CircuitPython is installed via this guide.

Problem: The code does not run.

Solution: Check the files on the CIRCUITPY drive.  /lib should have the latest CircuitPython 4.x libraries and you have placed code.py in the main (root) directory.

Problem: Not enough disk space for all the files.

Solution: If you have files from another NeoTrellis project, you may have to remove some or all of the other project-specific files to load files specific to this project.

If you use your own phrases, you cannot use long stereo clips or songs for each button, there is not enough flash disk space. You can reduce the number of files below 32. You can trim your clips to make them shorter. You should ensure all your clips are mono instead of stereo. 

Problem: My board isn't booting up!

Solution: Make sure your /lib folder is set up with the libraries in the 4.0 latest release and includes adafruit_trellism4.mpy in its contents.

Problem: I'm not hearing any sounds!

Solution: Ensure you have copied the sound files to the appropriate directories: /animal holds the 32 animal ABC files and /electronics holds the 32 "E is for Electronics" book sound files. The files are in GitHub in a ZIP when you download the code.

Ensure you have headphones or powered speakers plugged into the sound output jack and that the volume is set appropriately. If you have put custom sounds on the NeoTrellis, check that all your files are formatted as Mono 16-bit, 22,050Hz, PCM. 

Problem:

AttributeError: 'WaveFile' object has no attribute 'channel_count'

Solution: You should update the NeoTrellis firmware as described in https://learn.adafruit.com/adafruit-neotrellis-m4/circuitpython.

Time to download the software and sounds. Click on the Download Project Zip button in the top left of the code listing below to get the code.py file and two subdirectories: /animals and /electronics.

Open the ZIP file in your computer File Explorer/Finder. Plug in your NeoTrellis and open the CIRCUITPY flash drive that appears when NeoTrellis is plugged in.

Copy code.py to the root/main directory.

Copy each directory of sounds, /animals and /electronics to the root directory so you'll have those two subdirectories. Each of those directories have files named the same, but one set is female voiced (E is for Electronics) and the other one male voiced (Animal ABCs).

Files that have a period in the first character of the filename may be made on Mac computers, no worries.

Click Download Project Zip below to get the full project with all the files
# Talking A, B, Cs Soundboards: Animal ABCs and "E is for Electronics" ABCs

import time
import board
import audioio
import adafruit_fancyled.adafruit_fancyled as fancy
import adafruit_trellism4

# Custom colors for keys
RED = 0xFF0000
MAROON = 0xFF0044
ORANGE = 0xFF6600
YELLOW = 0xFFFF00
BROWN = 0x8B4513
GREEN = 0x008000
AQUA = 0x33ff33
TEAL = 0x66ffff
BLUE = 0x0000FF
NAVY = 0x24248f
PURPLE = 0x660066
PINK = 0xFF66B3
WHITE = 0xFFFFFF
EXTRA = 0x888888

# Select the folder for the ABC files, only define one,
#   the other line should have a # to comment it out
#SAMPLE_FOLDER = "/animals/"
SAMPLE_FOLDER = "/electronics/"

# This soundboard can select up to *32* sound clips! each one has a filename
# which will be inside the SAMPLE_FOLDER above, and a *color* in a tuple ()
SAMPLES = [("A.wav", RED),
           ("B.wav", MAROON),
           ("C.wav", ORANGE),
           ("D.wav", YELLOW),
           ("E.wav", BROWN),
           ("F.wav", GREEN),
           ("G.wav", AQUA),
           ("H.wav", TEAL),
           ("I.wav", BLUE),
           ("J.wav", NAVY),
           ("K.wav", PURPLE),
           ("L.wav", PINK),
           ("M.wav", RED),
           ("N.wav", MAROON),
           ("O.wav", ORANGE),
           ("P.wav", YELLOW),
           ("Q.wav", BROWN),
           ("R.wav", GREEN),
           ("S.wav", AQUA),
           ("T.wav", TEAL),
           ("U.wav", BLUE),
           ("V.wav", NAVY),
           ("W.wav", PURPLE),
           ("X.wav", PINK),
           ("Y.wav", RED),
           ("Z.wav", MAROON),
           ("01.wav", EXTRA),  # Keys beyond the 26 alphabetic keys
           ("02.wav", EXTRA),
           ("03.wav", EXTRA),
           ("04.wav", EXTRA),
           ("05.wav", EXTRA),
           ("06.wav", EXTRA)]

# For the intro, pick any number of colors to make a fancy gradient!
INTRO_SWIRL = [RED, GREEN, BLUE]
# The color for the pressed key
SELECTED_COLOR = 0x333300

PLAY_SAMPLES_ON_START = False  # Will not play all the sounds on start

# Our keypad + NeoPixel driver
trellis = adafruit_trellism4.TrellisM4Express(rotation=0)

# Play the welcome wav (if its there)
with audioio.AudioOut(board.A1, right_channel=board.A0) as audio:
    try:
        f = open(SAMPLE_FOLDER+SAMPLES[27][0], "rb")  # Use 02.wav as welcome
        wave = audioio.WaveFile(f)
        audio.play(wave)
        swirl = 0  # we'll swirl through the colors in the gradient
        while audio.playing:
            for i in range(32):
                palette_index = ((swirl+i) % 32) / 32
                color = fancy.palette_lookup(INTRO_SWIRL, palette_index)
                # display it!
                trellis.pixels[(i%8, i//8)] = color.pack()
            swirl += 1
            time.sleep(0.005)
        f.close()
        # just hold a moment
        time.sleep(0.5)
    except OSError:
        # no biggie, they could have deleted it
        pass

# Parse the first file to figure out what format it's in
channel_count = None
bits_per_sample = None
sample_rate = None
with open(SAMPLE_FOLDER+SAMPLES[0][0], "rb") as f:
    wav = audioio.WaveFile(f)
    print("%d channels, %d bits per sample, %d Hz sample rate " %
          (wav.channel_count, wav.bits_per_sample, wav.sample_rate))

    # Audio playback object - we'll go with either mono or stereo depending on
    # what we see in the first file
    if wav.channel_count == 1:
        audio = audioio.AudioOut(board.A1)
    elif wav.channel_count == 2:
        audio = audioio.AudioOut(board.A1, right_channel=board.A0)
    else:
        raise RuntimeError("Must be mono or stereo waves!")

# Turn on, maybe play all of the buttons
for i, v in enumerate(SAMPLES):
    filename = SAMPLE_FOLDER+v[0]
    try:
        with open(filename, "rb") as f:
            wav = audioio.WaveFile(f)
            print(filename,
                  "%d channels, %d bits per sample, %d Hz sample rate " %
                  (wav.channel_count, wav.bits_per_sample, wav.sample_rate))
            if wav.channel_count != channel_count:
                pass
            if wav.bits_per_sample != bits_per_sample:
                pass
            if wav.sample_rate != sample_rate:
                pass
            trellis.pixels[(i%8, i//8)] = v[1]
            if PLAY_SAMPLES_ON_START:
                audio.play(wav)
                while audio.playing:
                    pass
    except OSError:
        # File not found! skip to next
        pass

def stop_playing_sample(playback_details):
    print("playing: ", playback_details)
    audio.stop()
    trellis.pixels[playback_details['neopixel_location']] = playback_details['neopixel_color']
    playback_details['file'].close()
    playback_details['voice'] = None

current_press = set()
currently_playing = {'voice' : None}
last_samplenum = None
while True:
    pressed = set(trellis.pressed_keys)
    # if pressed:
    #    print("Pressed:", pressed)

    just_pressed = pressed - current_press
    just_released = current_press - pressed

    # if just_pressed:
    #    print("Just pressed", just_pressed)
    for down in just_pressed:
        sample_num = down[1]*8 + down[0]
        print(sample_num)
        try:
            filename = SAMPLE_FOLDER+SAMPLES[sample_num][0]
            f = open(filename, "rb")
            wav = audioio.WaveFile(f)

            # is something else playing? interrupt it!
            if currently_playing['voice'] != None:
                print("Interrupt")
                stop_playing_sample(currently_playing)

            trellis.pixels[down] = SELECTED_COLOR
            audio.play(wav)
            # voice, neopixel tuple, color, and sample, file handle
            currently_playing = {
                'voice': 0,
                'neopixel_location': down,
                'neopixel_color': SAMPLES[sample_num][1],
                'sample_num': sample_num,
                'file': f}
        except OSError:
            pass # File not found! skip to next

    # check if any samples are done
    if not audio.playing and currently_playing['voice'] != None:
        stop_playing_sample(currently_playing)

    time.sleep(0.01)  # a little delay here helps avoid debounce annoyances
    current_press = pressed

If you would like to use the "E is for Electronics" soundboard first with no customization, you can skip to the Use page.

The Code and Customization

The code first imports five libraries for use:

Download: file
import time
import board
import audioio
import adafruit_fancyled.adafruit_fancyled as fancy
import adafruit_trellism4

Next is a list of numeric values for the colors displayed on the board. If you think the individual colors need tweaking, you can do it here. If you want the color keys in a different order, you'll change the dictionary SAMPLES below the color values. SAMPLES contains 32 tuples (groups) which each contain a file name and a color for each button. So Button 1 will play the sound file A.wav and display on the NeoTrellis in color RED.

Changing Soundboards

Next is where you would change between from the Animal soundboard and the "E is for Electronics" soundboard. The code: 

Download: file
# Select the folder for the ABC files, only define one,
#   the other line should have a # to comment it out
#SAMPLE_FOLDER = "/animals/"
SAMPLE_FOLDER = "/electronics/"

When you load the code above, the soundboard will work as the "E is for Electronics" soundboard and get the phrases in subdirectory /electronics.

To change the NeoTrellis to the Animal ABCs soundboard, use Mu or a text editor to make the following changes to that section of the code:

Download: file
# Select the folder for the ABC files, only define one,
#   the other line should have a # to comment it out
SAMPLE_FOLDER = "/animals/"
# SAMPLE_FOLDER = "/electronics/"

This change pulls the sound files for the Animals ABC phrase set.

Each directory contains the same file names but they are different phrases. A.wav to Z.wav play the alphabet phrases. The last 6 keys play different phrases. The code will also play phrase 28 on startup.

If a key is pressed, it will play the corresponding sound file as defined in the SAMPLES dictionary. Press a key before the phrase finishes and the phrase will stop and play the new phrase so keys can interrupt other keys.

The two soundboards that are available for this project:

  • E is for Electronics - narrated in a US female voice
  • Animal ABCs - narrated in a US male voice

The code is set for "E is for Electronics" but a small change noted on the previous page will switch the board to the Animals ABC soundboard.

We suggest providing the soundboard and the book together so someone may follow the pages with the corresponding sounds. A set of crayons or pencils may be used to color the book while using the soundboard.

E is for Electronics

You can buy this coloring book from Adafruit here or download a PDF copy here. If you'd like to see a Youtube video talking in general about the book, it is available here.

This book goes through the alphabet via electronics figures and items. The pictures are in black & white so they may be colored as an activity. For a video demonstration, see below:


Animal ABCs

The second soundboard is Animal ABCs. The board is based on the book The ABC book by C.B. Falls, published in 1923. The book is out of copyright and is available from the Internet Archive via this page as a black and white PDF file.

This book goes through the alphabet noting different animals whose name matches the letter of the alphabet. This PDF is also black and white for coloring.

Activities

We suggest you have a printed copy of one of the books and provide it to one or more people along with the corresponding soundboard. 

Following the book and listening to the sounds makes for a great pairing.

The addition of coloring provides additional activities. Have fun with this project!

Customization

neotrellis_mic.jpg
Credit: Microsoft Word clip art image

If you would like a different set of phrases, this is possible with a bit of work.

You have twenty six files labelled A to Z and 6 keys after that numbered 01 to 06 for a total of 32 keys.

How to Make New Sound Files

The following guide page goes over recording speech files:

Make It Talk - Generating Voice Sound Clips

You can also make sound files for a general soundboard. The Adafruit Learning System has tutorials for several NeoTrellis M4 Express soundboards.

The sound files you record or find on the Internet must most likely be converted to a format easier for the NeoTrellis microcontroller to use. The format is WAV files, PCM 16-bit, a maximum of 22,050 Hz and mono (one channel). To convert sound files for use, we suggest following this Adafruit tutorial:

Microcontroller Compatible Audio File Conversion

If you make your own files, you should check to see which subdirectory to use. You can use the existing /animals or /electronics subdirectories. Or you can make your own subdirectory and change the value of SAMPLE_FOLDER in the code to your chosen subdirectory. Be sure there is a forward slash ("/") in front of and at the end of the filename, for example SAMPLE_FOLDER = "/myfolder/".

This guide was first published on Dec 11, 2018. It was last updated on Dec 11, 2018.