Open MIDI Guitar: Build Your Own MIDI Guitar for Less Than 20€

by gadesfreak in Circuits > Arduino

1827 Views, 6 Favorites, 0 Comments

Open MIDI Guitar: Build Your Own MIDI Guitar for Less Than 20€

00_01_front_view.png.JPG
00_02_rear_view.jpg.JPG

Do you want to learn how to play guitar but can't afford one? Do you want to practice with your headphones without disturbing your family or neighbors? Are you a music composer that never got used to MIDI keyboards and can't afford a commercial MIDI guitar controller? Are you a guitarist that wants to experiment with different guitar tunings without losing time re-tuning your guitar? Or are you just an electronics freak and want to make something that rocks? If you answered "yes" to any of the previous questions, maybe this project is for you.

Disclaimer: I have focussed this project on circuit design and microcontroller code. As you can see in the photos and videos, I'm not a luthier nor a musician. The prototype I made is perfectly functional, but it lacks of ergonomy, and it could be uncomfortable and difficult to play for real guitarists. Be careful about carpal tunnel syndrome, or other injuries.

Features:

  • Guitar MIDI controller with 15 frets and 6 strings.
  • Connected through USB to your computer. You will need a serial to MIDI converter software (ttymidi and Hairless MIDI worked fine).
  • Can be used with any synthesizer or DAW.
  • Supports strings muting.
  • Configurable options:
    • Octave up/down.
    • Volume up/down.
    • Midi note maximum duration up/down.
    • Tuning changing, actually supporting 26 different tunings.
    • Virtual capo.
    • Hammer-on.
    • Sliding (as a particular case of hammer-on).

Supplies

This is what I used to build my prototype. Have a look at the "Modifications/upgrades" step for other ideas that require different materials you could already have:

  • 1x ESP32 board.
  • 8x MPR121 modules.
  • 4x push buttons.
  • 1x SSD1306 0.91 inch OLED display.
  • Perfboards, header pins and cables. I recommend perfboards over breadboards, as sometimes you can get wrong sensor readings using the later ones.
  • M3 size screws, bolts and gaskets, for the capacitive sensors endpoints.
  • Cardboard.

Tools used:

  • Pliers, scissors, soldering iron, glue gun, screwdrivers, multimeter.

How the Open MIDI Guitar Works

Open MIDI Guitar demo
Open MIDI Guitar user interface

We simulate the frets and the strings of a real guitar with capacitive sensors. If we press a sensor on the fretboard, the MIDI guitar will act as if we were pressing a string over a fret in a real guitar. If we release one of the string sensors, it will act as if we were plucking that string. The MIDI guitar will send the appropriate MIDI messages through the serial port of the microcontroller, and the serial data will be converted to MIDI data by ttymidi or Hairless MIDI. This MIDI data will be sent to your specific software. We will use only two MIDI commands to play our notes: Note On and Note Off. We can play notes and chords like in a real guitar. If we play a note, we can stop it by pressing another sensor from the same row (same virtual string). This function can be changed slightly if we activate sliding/hammer-on.

We can configure the following options through the buttons and the display:

  • Octave up/down. Thanks to this option, having less frets than a real guitar is not a big problem, as you could play almost any note pitch. However, I think we should be able to play a full octave (12 consecutive notes) for each string without changing octave. That's the reason we need as many sensors in the fretboard as we can. See the "Modifications/upgrades" section for alternative designs that would allow the building of a controller with different number of frets and strings
  • Volume up/down. With this option we change what MIDI protocol calls "velocity". It usually refers to the note volume, but you should keep in mind that, depending on your software, it could change another parameter.
  • Maximum duration up/down. If we play a note in a real guitar and don't mute it later, it will naturally vanish as the string stops vibrating. Once we play a note in the MIDI guitar, and If we don't mute the string nor play another note in that string, the note will last the time specified in this parameter. It's very useful when using synthesizers that generate continuous sounds that don't fade out.
  • Tuning changing. We can choose from 26 different tunings. If you know about more tunings that should be here, let me know.
  • Virtual capo. A capo is a clip that raises the pitch of the open strings. It's like playing a guitar with a shortened neck. In the MIDI guitar, the sensors from the capo to the head will not mute the strings when pressed.
  • Hammer-on/sliding. In a real guitar, hammer-on is a technique used to play a note without plucking a string. In the Open MIDI guitar, two parameters are used to configure it: hammer time and hammer distance. Hammer time specifies the maximum time in milliseconds you have to hammer-on a note since the last note you played on that string. Hammer distance specifies how far away from the playing fret you can hammer-on. The lower hammer time is, the faster you have to hammer-on the notes to play them. The higher hammer distance is, the further you can hammer-on from the playing note. For example, if you play a note on the fifth fret, with hammer distance 2 and hammer time 400, you have 0.4 seconds to hammer-on another note after playing that one. With the specified hammer distance, you could hammer-on a note from frets 3 to 7. Basically, the hammer-on/sliding option temporarily changes the behavior of the closer sensors to the one you have just played. The rest of the sensors will act normally, muting the string if pressed. A very high hammer time is good for testings, but it is not practical: the note would probably have been muted if maximum duration is lower than hammer time, and you could get unexpected notes when changing the position of your hand from one chord to another for example. On the other hand, a very high hammer distance could be used to play the guitar almost like a keyboard.

An Overview of the Building Process

02_01_diagram.png
02_02_blocks.png.JPG
02_03_sensors_microcontroller_strings.png.JPG

In the images you can see a diagram of the Open MIDI guitar and some photos of my prototype. The MPR121 modules are controlled through I2C, and each one provides 12 capacitive sensors. We need as many frets as we can, but we can only connect up to four modules per I2C channel. The ESP32 has two I2C channels, so this microcontroller can control the impressive amount of 96 input capacitive sensors: 90 for the fretboard and 6 for the strings. MPR121 modules and ESP32 controller work at 3.3v.
Physically, we can divide the design into four parts:

  • Fretboard and strings.
  • Microcontroller block.
  • Sensors block.
  • User interface block.

I have used female pin headers to connect the MPR121 modules and the ESP32 to their respective perfboards. I recommend a glue gun to fix these pin headers to the perfboard before soldering them. The blocks are interconnected using dupont cables, so that they could be interchanged for other blocks. From the microcontroller block, six dupont cables are connected to the sensors block: VCC, GND and the four lines needed for the two I2C channels. Another four cables are connected to the user interface block, for controlling the buttons. Finally, another four cables are connected between the sensors block and the user interface: VCC, GND, and the two cables of I2C channel one.

Fretboard and Strings

03_01_fixing_cables_to_fretboard.png.JPG
03_02_fretboard_sensors_endpoints_front.jpg.JPG
03_03_opened_fretboard.jpg.JPG
03_04_opened_fretboard_details.jpg.JPG
03_05_strings_sensors_endpoints_front.jpg.JPG

The sensors endpoints I chose were some screws, with nuts and gaskets on the back side. Among the images, you can see the initial prototype with breadboards. I recommend you using a longer fretboard, leaving more space without sensors so you can fix it to the body of the guitar with enough screws/glue. In the final prototype, I covered the cardboard with plastic book cover. For the strings, I used some peeled cables, and raised them using two more nuts per screw.

Microcontroller Block

04_01_protoboard_sensors_block.jpg.JPG
04_02_microcontroller_block_front.jpg.JPG
04_03_microcontroller_block_back.jpg.JPG

I have used a small perfboard and female pin headers to insert the ESP32 module in. I soldered some male pin headers too, for dupont cables connections. I used pins 4, 0, 2 and 15 for the buttons; and pins 25, 26, 27 and 14 for the I2C channels. Among the photos, you can see the initial complete prototype with this block already soldered.

Sensors Block

05_01_soldering.png
05_02_soldering_sensors_block.jpg.JPG
05_03_sensors_block_front.jpg.JPG
05_05_sensors_block_side.jpg.JPG
05_04_sensors_block_back.jpg.JPG

According to its datasheet, a MPR121 module can have one of these I2C addresses: 0X5A, 0X5B, 0X5C or 0x5D. Its address will depend on what you connect to the ADD pin. By default, GND is connected to this pin, so if you want to use another address different from 0X5A you will have to break the connection in between the two pads on the back side of the module, as explained here. I used a small precision screwdriver, a cutter could be used too. A multimeter is very useful here, to ensure you have broken the contact.

I draw a diagram in Fritzing to guide myself in the soldering process. Once the pin headers were soldered, I soldered the 96 cables that were connected to the fretboard and strings. Once again, a multimeter is useful here to test the sensors endpoints.

User Interface Block

06_01_user_interface_block.jpg.JPG

As you saw in previous photos, I initially used a small breadboard with the four buttons and the display for this block, and it worked fine. I decided to use a perfboard here too, but divided it in two parts: one for dupont lines interconnections, and the other for the buttons. I did this because I didn't want anything higher than the buttons in the board, so i could put these into a perforated cardboard box or something similar. At the end, I used insulated tape, so the result isn't pretty at all :-). At least these small perfboard pieces are ready for something better.

Code

The code is available here, and it's licensed under GPL v.3. I recommend Sloeber IDE, as it provides some basic features Arduino IDE doesn't have (auto-completion, etc.). It's based on Eclipse, and it allows even navigating through the Arduino built-in functions declarations and definitions, so you can learn a lot about the Arduino API framework using Sloeber.

About the code, there isn't a class for the guitar itself, and I used global variables everywhere. The code is an evolution of my first tests. Maybe not the best design, but having a single .ino is good for people not used to Arduino and only interested in building their own guitar. Furthermore, with so many sensors, I need the program to be fast, so that latency is low, and calling many functions using many parameters doesn't help (thinking here about a possible version with an Arduino Nano and several I2C channels through a multiplexer). I will probably change this in the future: for example, in the case of a double-neck guitar, having multiple guitar objects could be useful.

The code is full of comments, so you can follow its behavior if interested. Basically, in each loop:

  • I read the sensors data.
  • Depending on differences from previously read data:
    • I control note muting (by the user) and hammering.
    • I control note playing.
  • I control note muting (by maximum duration).
  • I control the user interface block, and make the changes the user activates.

For future modifications (see next step), I'm thinking about multithreading, using the 2nd core of the ESP32 for the Wifi user interface.

Modifications and Upgrades

These are possible modifications/upgrades to my prototype. I will likely try at least the first four ones. If you have other suggestions, let me know:

  • "Lite version", with an Arduino UNO (or Nano) instead of ESP32 and four MPR121 modules instead of eight. In this case it should have four virtual strings and eleven frets, transforming the MIDI guitar into a small MIDI bass or a MIDI ukulele.

  • ESP8266, Arduino Uno or Arduino Nano version, using I2C multiplexer TCA9548A (at least two I2C channels should be used) and eight MPR121 modules.

  • Configuration via Wifi and/or Bluetooth. No extra hardware needed, as ESP32 includes both.

  • Using different MIDI channels (for example, a different instrument for each virtual string).

  • Building a MIDI guitar with as many frets as a real guitar, or an eight strings guitar, or even a multi-neck guitar. This could be done using more than two I2C channels from the the multiplexer mentioned above (TCA9548A), and more than eight MPR121 sensors.

  • Supporting pitch bend through a potentiometer or some other extra hardware (there is a MIDI command for bending).

  • Using MPR121 IRQ pins.

  • Using some of the 10 touch sensors provided with the ESP32 chip. You could use them instead of the buttons, or use them instead of the string sensors, getting one more fret this way. Or maybe they could be used to add some sensors so that you can mute the strings with the right hand.

  • Consider other conductive alternatives to screws and nuts I've used, like:

    • Pushpins or some kind of plane head screws.
    • Copper tape squares.
    • Alluminium foil squares.
    • Nails
  • Consider cleaner alternatives to the ninety 30-50 cm. soldered cables, like those old IDE ribbon cables and connectors.

  • Building a more ergonomic controller. The neck I built is quite bulky and heavy. Wooden parts or a 3D Printer could be used.

  • Make the controller feel like a real guitar. We have two main problems here: passing the sensor cables through the neck without affecting comfort when playing; and fixing/soldering the cables to the fretboard conductive sensors enpoints. Considering real electric guitar strings and real frets are made of metal and should be conductive, we have at least these options:

    • Using squares made of copper tape or alluminium foil over the fretboard, together with real guitar strings over the neck. Another six different pieces of string could be used for the right hand. Capacitive sensors would be activated when pressing strings over the conductive squares.
    • Using real guitar neck, dividing real frets into 6 different parts, and using real guitar strings. Each string should contact its corresponding sixth of each fret. Another six different pieces of strings could be used for the right hand.

Final Thoughts, References and Links

A set of MPR121 modules is a great option for projects with a lot of inputs, like this one. They are really affordable, and If interested you should have a look at its datasheet, as they offer a lot of options.

I hope you liked this project, I enjoyed making it. Although not a pretty prototype, it provides a lot of the functionality much more expensive commercial products offer. I encourage you to make your own MIDI guitar, and of course let me know about it. I'm really looking forward to seeing a good wooden or 3d printed design. Feel free to tell me your thoughts about anything involved: circuit design, code, materials, software (DAWs, synthesizers, etc.), links, or even typos / grammatical errors in this document.

Regarding software used, I recommend the following for Linux (I only know the basics of some of them):

  • aconnectgui, Jack (QjackCtl), Carla: for interconnections.
  • LMMS, Zynaddsubfx, Fluidsynth (Qsynth), Guitarix, Rosegarden, Rakarrack, Hydrogen: for composing and synthesizing.

Finally, some interesting links: