Robotic MIDI Music Maker (Lap Harp) with Arduino

A friend found this "Music Maker" lap harp in the free-box of our neighborhood and gifted it to me. I automated it with solenoids and an Arduino Uno. The light grey parts were 3D printed on a Prusa MK3s and designed in Autodesk's Fusion 360. The plywood stand was laser cut on a Boss laser cutter. On a laptop, LMMS (a free digital audio workstation app) is playing midi files which are downloaded from the internet. A program called loopMIDI creates a virtual patch on the computer so the midi signals from LMMS can be sent to Hairless MIDI, another app that creates a USB serial bridge to the connected Arduino Uno. The Uno has a simple program running, built with the MIDI Library, that waits for a midi 'note on' signal, then plays that note, if possible. It does this by digitally writing one of the Unos GPIO pins LOW, which is connected to a relay board. The relays control a separate high amp, 5V power supply for the solenoids.

Motivation

This project is similar to my automated tremoloa project from the year before. I’d wanted to make that instrument a midi input device so that I could use Ableton or LMMS to send pre-written songs. That was a difficult task since the plucking mechanism needed time to move into position to play each note. I might have been able to build in some kind of buffer to the Arduino so it was anticipating the next couple of notes, but lost interest in the project.

When my neighbor found and gifted me this Music Maker instrument, I saw a chance to re-explore my midi idea. My parents had one of these simple instruments in my home when I was growing up, so it was nostalgic getting to revisit it. The instrument has 15 strings that cover 2 octaves of the G Major scale (G, A, B, C, D, E, F#). This limits the songs that can be played on it, but there are still plenty of interesting songs that stay mostly in that key.

Process

Since the struggle with my tremoloa project was the inability to quickly play each note when the midi command was received, I decided this project would need to have a mechanism for each string to be played individually and immediately. Solenoids were the obvious solution and the only reason I don’t use them is they tend to be expensive. The best suited ones I could find for the cheapest price were from DigiKey for a little over $4 a pop. I put in an order for 16 (always good to have a spare) and a 16 unit relay module from Amazon (which would be used to turn the solenoids on and off), then focused on other aspects of the design while I waited for them to arrive.


My process went something like this:

1) Create a stand that would keep the instrument firmly in position and hide the electronics.

2) Wire up the relay board to a 10A 5V power supply unit (salvaged from an old LED art project).

3) Make a mounting system for the solenoids that was adjustable.

4) Do some prototyping of the electronics with simple Arduino code to test the wiring.

5) Figure out more complicated code for the Arduino so it could receive midi information.


Stand

For the stand I used Fusion 360 to generate some basics shapes that could be laser cut out of plywood. I measured the Music Maker and recreated the shape in Fusion 360, then used the offset tool to add an extra inch or two around the perimeter. I made two identical boards; one would be for the top and hold the instrument, and the second would be under that and mount the electronics. I designed spacers that would fit in the corners of the board and some hooks that would hold the instrument down, then 3D printed them on my Prusa MK3s. The holes in the corner supports are just a touch smaller than a M4 bolt so they would self-tap into the plastic once assembled. I used countersunk, hex socket bolts wherever possible for a cleaner finish.

Relay Module

The relay module is made by SainSmart and cost me $15 off Amazon. It has 16 relays that are controlled by 5V logic level. It requires a 12V input to operate, but has 2 pins with regulated 5V output. I originally thought I could use this 5V source to power the solenoids, but the large swings in current running so close to the Arduino and input pins caused all kinds of havoc. Instead I used a separate ACDC switching power supply unit from an old LED project. This meant the Arduino, relay board, and solenoids are all powered by separate sources, creating more cables than I cared for, but solving my performance issues.

Each of the relays has three connections: the common pin (middle) and the normally-closed (NC) and normally-open (NO). When the relay board is unpowered, or the input pin for that relay is held HIGH, the common pin is connected to NC. I connected all the NO pins of the relays in parallel to the 5V of the power supply and the common pin of each relay to its own solenoid (like in the schematic below, but 4 times as big). The output of the solenoids all returned to the GND of the power supply. I wasn’t sure if it was better to have the solenids constantly held at 5V or the wires running around the relays, but this is what I ended up doing.

To make things easier to work on in parts, I didn’t directly connect the wires from the relays to the solenoids. Instead I ran them to a small circuit board with some header connections that I could later plug the solenoids into. It was more work, but this allowed me to work on the upper and lower half without worrying about pulling wires from the screw terminals of the relays.

Solenoids

The solenoids I purchased from DigiKey were tiny things, but this made it possible to position one over every string on the Music Maker in a single line. The spacing between the strings on the instrument varied, so I tried to engineer in ways to adjust the position of the solenoids. First, I designed and 3D printed a bunch of clips that would hold the solenoids by their round bodies, leaving enough room to still solder wires to their small terminals. These clips slipped over a piece of stock angle aluminum bar from Home Depot and they each had a hole that allowed a set screw to hold them in a final position. This took care of lateral adjustability. For vertical adjustability I 3D printed a stand to hold the aluminum bar that included a vertical slot for fine tuning the height.

Programming

I used most of the analog and digital GPIO pins on an Arduino Uno to connect to the input pins on the relay module (see code below), leaving digital pins 0 and 1 free since they get used in serial communication and I didn’t want any random relays trigged when uploading new code. I also connected GND from the Arduino to GND on the relay module. I did some test runs using simple digitalWrite() commands and found to my pleasure that I hadn’t flubbed a single connection or soldering job.

To tackle the final challenge of adding midi control, I looked for help online. I found this article about an Arduino Glockenspiel by Mike Cook particularly helpful, even if the article was 12 years old and the project was even older than that!

I’d previously used the MIDIUSB library (that can be downloaded through the Arduino IDE) to make midi output devices (instruments that created midi signals that were then played by a midi synthesizer application on my computer), but for this project I used “MIDI Library,” which can’t be found through the IDE, but can be downloaded from GitHub. The MIDIUSB library works with boards that have native USB capabilities like the Micro and MKRZero, but the MIDI Library can work with an Uno. The MIDI Library also works well with the Hairless MIDI application (see more in Software below).

My code is pretty simple, after all is said and done. The loop() is mostly just a function that reads what is coming over the USB cable. If it reads a ‘note on’ signal it uses some callback functions to determine what note to play, then plays it! I ignore velocity and all other command bytes. Notes received that aren’t on the Music Maker are ignored. I did have some issues where the relays wouldn’t return to their original state after playing a note, so I added that to the loop() as well, which I feared would slow things down, but didn’t have a noticeable impact on the performance in the end.

Software

There are a number of pieces of software I had to install to make everything communicate nicely. First, I needed some software that would generate midi signals. I’ve used Ableton in the past, but wanted something more universal (i.e. free). I downloaded LMMS, which is a free digital audio workstation that works on many platforms. It doesn’t include any soundfonts, so you won’t hear much unless you add some. Free packs exist, but I just used the Microsoft GS Wavetable Synth that is included with Windows for troubleshooting. In LMMS and similar programs you can route the output of the music, either through soundfonts on the local system, or to connected midi devices. On Macs it is simpler to route a midi signal to a connected device, but on a PC you’ll need to install some extra programs to accomplish this.

In order for software programs on a Windows computer to pass midi signals to each other, you need to download something like loopMIDI (by Tobias Erichsen), which creates virtual midi ports on the computer. It is my understanding that Macs have this feature built into the operating system. After installing loopMIDI and creating a virtual port, it should show up in the list of output options in LMMS.

Lastly, what loopMIDI is passing the LMMS signal to is a program called Hairless MIDI, which creates a serial bridge to the Arduino Uno. Their website has some really helpful information, so check it out. The “MIDI in” for Hairless MIDI should be the virtual port you created in loopMIDI. When you play something in LMMS you should see that register in Hairless MIDI, even without a connected device. In the “Serial port” menu of Hairless MIDI, select the connected Arduino. If you unplug the Arduino or try to upload code from the IDE this may cause trouble with Hairless MIDI and you should close and reopen the MIDI bridge with the check box.

Most of the songs that you see playing in the video at the top of this page were freely downloaded .mid files from sites like BitMidi. These can be imported into LMMS and often contain multiple tracks. I ignore things like percussion tracks and individually route the melody and rhythm tracks to loopMIDI.

Code

Previous
Previous

LED DomeHead Costume with Raspberry Pi

Next
Next

Interactive Projected Light with Kinect V2 Sensor