hardware for a MIDI instrument
AGPL-3.0 License
Contents
A MIDI controller in the shape of a video game controller (e.g. xbox), but using mechanical-keyboard buttons.
Like some MIDI keyboards, it doesn't make actual sound, it only sends digital notes over USB to a computer or synthesizer.
Hold it like an Xbox controller. Play it like a kalimba, with your thumbs.
The diagonal keys are notes; the 3 keys in the middle are extra function keys. The joystick is for pitch bends.
Unlike a kalimba, the notes are arranged piano style. There's one octave starting at B on the left and ascending to Bb on the right. Like a piano, white keys are on the bottom row and black keys are on the top row (except for B).
Because we use Shepard Tones (more below), you can play a melody so that it wraps off one side of the keyboard and back onto the other side, without noticing a jump in octaves.
The middle keys S, T, and U are for special purposes. Currently:
...but check the source code for the latest changes to the special keys.
The middle keys could possibly do other things like:
The joystick is not programmed yet (TODO), but it will do pitch bends. Left/right will bend by a half step, and up/down will bend by a whole step.
It could also act as a mod wheel on one axis and a pitch bend on the other axis.
There's only room for 12 notes, but wouldn't it be nice if you could wrap around the edge when playing a melody without jumping an octave?
We use an auditory illusion called Shepard Tones to make this possible. Each key actually plays several octaves of that note at the same time, but with louder notes in the middle octaves, to maintain the loudest note in the same octave despite the illusion of constantly ascending tones.
As you go up, the higher octaves fade away and the lower octaves fade in to take their place, until you wrap around seamlessly.
For example:
My advice is to stick with an Adafruit Feather board since they're mostly the same size and pinout, and all work with the Arduino IDE.
Make sure any microcontroller you use has 15 digital inputs and 2 analog inputs. You'll have to adjust the plywood case to fit, as well.
Some microcontrollers support Bluetooth Low Energy (BTLE), which you can use to pair with iOS devices for wireless MIDI playback. Here's Adafruit's guide. I tried this and found it worked within about 15 feet, after that latency and jitter became a problem. I also preferred to plug things together instead of messing with bluetooth menus. Note also that a wireless Thumble will need a battery, and the Feather boards have integrated lithium battery pack connectors and circuitry.
The Elite-C uses the same chip as the Feather, but the physical hardware is better. It's smaller, and it has a strong USB-C port, while the Feather's USB-Micro port tends to rip off if the cord is pulled.
However the Elite-C can't be flashed from the Arduino IDE (because it uses the DFU bootloader instead of the Caterina bootloader that's normal for Arduino boards.) You have to use the command line to flash it, and I'm not sure how to compile the code for it or make sure it supports MIDI-over-USB.
If you know how to solve that problem, you can use the Elite-C instead. Note though that the case is designed for the Feather, which is larger.
There's a new microcontroller made by Raspberry Pi called the Raspberry Pi Pico, using their new RP2040 chip. It's cheap and there are many variants already such as the Adafruit feather RP2040 which has a USB-C port. This microcontroller works with Circuit Python instead of Arduino, but Arduino code support is in the works. It's much faster than needed for this project.
Many mechanical keyboards use some kind of Teensy board, but there are many with different microcontrollers. I'm guessing you'd want a Teensy 2 since it matches the Atmega 32u4 microcontroller we're using here? Getting USB MIDI working is a bit different and it may require special setup to work in the Arduino IDE
The case is laser cut from 7 layers of 1/8 inch material (3mm). I used plywood and glued the layers, or you could use acrylic and figure out some screw holes. The SVG files are in the case
folder.
3mm plywood is too thick for the keyswitches to grab onto with their little latches. You'll have to glue them into place (TODO: with what glue?).
The joystick and microcontroller are also a bit loose in the case; you'll have to improvise a way to keep them stable. Maybe a spare piece of wood to pack the space below them.
The top layer SVG is flipped so that the laser smoke marks end up inside the case instead of outside. Case level 4 is hollow, make three of those to stack up enough interior space for wiring.
Refer also to the build photos below.
This code will turn the microcontroller into a USB MIDI input device, like a piano keyboard, that can be used with any other hardware (ipad, laptop, etc).
This is not based on any existing mechanical keyboard firmware because it's fairly simple. There's just one GPIO pin to read each switch individually, and two analog inputs used for the joystick.
https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
Open the arduino code in thumble_001_arduino
. Hit the checkmark button to see if it compiles with no problems.
To send the code to the board, press the button in the IDE's top left corner with the right arrow. You do not need to press the reset button on the board when flashing it.
iOS devices will complain that the Thumble is requesting 500mA of power, which is too much. It doesn't really need that much power, it's just part of the power negotiation process of plugging USB devices together where they claim how much they need.
Unfortunately, fixing this requires hacking a file in the Arduino IDE. This file is likely to be un-hacked every time the Arduino IDE is updated, so watch out.
These instructions are adapted from https://github.com/arduino-libraries/MIDIUSB/issues/22
hardware/arduino/avr/cores/arduino/USBCore.h
. On my mac is was under /Applications/Arduino.app/Contents/Java/
. So the total path is /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/USBCore.h
#define USB_CONFIG_POWER (500)
#define USB_CONFIG_POWER (98)
Re-flash the board. Now it will work when plugged into a iOS device via something like the weirdly named Lightning to USB Camera Adaptor, which is not just for cameras but for any USB device.
There's also a version of that adaptor that has an extra lightning power input for wall power -- using that and plugging in wall power at the same time will probably bypass the USB power warning but creates a mess of cables.
So my cable setup is: Thumble --> usb-C to usb A cable --> Apple camera adaptor to lightning plug --> iPod Touch
(I haven't tried this on any USB-C equipped iOS devices, only through the USB-A to lightning dongle. Maybe things just work on USB-C iOS devices.)
If you don't have an iOS device and you need a portable hardware synth to turn your MIDI into sounds, the iPod Touch is not a bad option. It's $200, can run most iOS music apps and synths, battery powered, small, has (tiny) speakers and headphone output. One could be mounted to a Thumble somehow. This is what I use when I'm not at my computer.
See the Appendix below for app recommendations.
P.S. I'd love to hear any other options for portable battery-powered MIDI synths with audio out, I don't want to support Apple specifically.
We can wire each key directly between GND and an input pin, since we don't have many keys. (Otherwise in a bigger keyboard we'd build a key matrix using diodes.)
For simplicity, a few GND wires can run along tracks in the case and connect to every key. Then attach a signal wire from each key to a unique pin on the microcontroller.
We use 15 digital input pins for keys.
The joystick uses up two analog inputs and needs a ground and 3v wire too.
Wiring diagram (click to enlarge):
The thick black wiggly wire is a ground wire that connects to each keyswitch. It fits into the wiggly channel in the plywood. You can use one long wire for this, or several smaller wires, whatever is easier.
ERRATA The joystick board is horizontally flipped in this diagram, but it might not actually matter because the board might be symmetrical. Double-check.
You can adjust the key-to-pin assignments in the code if you soldered things a bit differently. Look for the #define KEY00_PIN
lines around line 90.
Laser cutting the case layers from 1/8 inch plywood
Gluing the case layers
Test fitting the switches for layer alignment
Gluing
We used TiteBondIII Ultimate Wood Glue
Clamping & gluing
The layer stack showing the USB area
Counterset Torx screws to hold the back over
Sanding round edges
Fitting the electronics. We had to cut off a corner of the case to make room for the USB cord.
Improvised way to hold the Feather board steady
Final case assembly
Soldering and gluing in the PCBs. We used 2-part epoxy to hold the keyswitches to the wood. The PCBs are held in with hot glue and blocks of wood that press them against the back cover for stability.
Keycap layout
(Not pictured: flashing the firmware.)
Finished!
Layer cut plywood layers make a great case, although a bit heavy.
This instrument was designed as a follow-up to the Waffletone, but it differes in several ways:
So...
Desktop
Open source, multi platform
Android
iOS
Hardware (advanced)