Stephen Coyle

Making a better WiFi piano

About a year ago, I made my trusty electric piano wireless using a Raspberry Pi Zero and some nifty software. It worked pretty well, but wasn't quite perfect. I initially assumed input lag (something I'm pretty unforgiving about) would be the biggest issue, but for the most part this wasn't a problem. There were some annoying quirks, though: - occasional missed notes, or stuck notes - random disconnections, which seemed to get worse the longer it was powered on - a few times things just stopped working entirely, and I had to reinstall everything from scratch

That third issue happened again recently, so I figured I'd take it as an excuse to try out a different approach. Having picked up one of these recently, I thought something more Arduino-oriented might be a neater solution to the problem. Getting rid of the overhead of a full Linux OS, and usb device, would surely mean there's a lot less to go wrong?

So, the to-do list looks like this: 1. Make the Arduino act as a network MIDI device. 2. Set the Arduino up to receive information from a hardware MIDI port. 3. Parse the signals from step 2, and send the corresponding info over the network.

Luckily, step one is pretty well served by the AppleMIDI library, and the networking libraries for esp8266-based devices. Having a look at some examples, it was pretty easy getting that part of the sketch done. I tested it out by having it send some random MIDI notes, and it worked (I'll post the complete Arduino code below).

Step two was a little harder, but nothing that wasn't already well-tread and documented. Consulting a few resources, I was able to mock up and test a MIDI-in port, which uses the SoftwareSerial Arduino library to receive the data. Once I'd checked it was working, I soldered the parts together to make a slightly neater package.

With those parts done, I needed to write a layer to take the signals from the MIDI port on my piano, and send out the correct information over the network. This was the fiddliest part, and took a bit of reading up on the MIDI spec to get working properly, but in the end it does the trick. Trick is the operative word here; my only requirements was that this worked for sending note on/off and pedal on/off data, and that's all my code will do. Any more intricate or esoteric MIDI signals, or even anything beyond the basics I just described, would require some reworking.

All in all, I was really happy with how this worked out. The Arduino makes for a snappy, latency-free MIDI relay, and seems to be a lot more stable than the Raspberry Pi-based setup of before. Another benefit is that it's ready to connect within about 5 seconds of powering on (less time than it takes me to plug in the power supply, then switch on the piano) - much faster than the boot time of the Pi. Finally, I'm hoping it should be less prone to corruption/breaking down over time, since I'm not now randomly pulling the plug on a Linux system I should really be shutting down properly.

If you're interested in making something like this yourself, here is the Arduino sketch, and the hardware is based on a NodeMCU V2 device, with the MIDI-in port based on the schematic at the site I linked above.

Finally, with the hardware and software working, I put everything in a box and attached it to the back of my keyboard like so, and so far so good.