Arduino MIDI Keyboard

by pashmores in Circuits > Arduino

3718 Views, 21 Favorites, 0 Comments

Arduino MIDI Keyboard

IMG_5636.JPG
IMG_5637.JPG
Arduino MIDI Keyboard

For our final project in Object, we were tasked with making an interactive object. Both me and my partner are very interested in music and music production so we wanted to make something related to that. We made a single MIDI Keyboard that uses an Arduino Nano 33 IoT to send MIDI information to Ableton. It includes a single octave 13-key keyboard, octave buttons, and a volume knob. This project was a huge learning experience in every aspect. The fabrication had lots of different elements including 3D modelling, lasercutting, soldering, wiring, painting, and aesthetic planning. It also involved a substantial amount of code and software to communicate between a physical circuit connected to a microcontroller and Ableton.

Supplies

IMG_5547.JPG
arduino.jpg
Bondo.jpg
breadboard.jpg
IMG_5518.JPG
1072615.jpg
rubber.jpg

Enclosure:

  • 3mm plywood
  • Bondo
  • Epoxy
  • 1/4" thick rubber mat
  • 120 grit sandpaper
  • Utility knife
  • Super glue
  • Black spray paint
  • 3D printer/filament

Circuitry:

  • Half-sized breadboard
  • Snappable PCB prototype board
  • Solid core wire
  • 10k ohm resistors
  • Push buttons
  • Soldering iron and solder

Lasercut Files

Screenshot 2021-12-15 145939.jpg
Screenshot 2021-12-15 151543.jpg
Screenshot_2021-12-07_at_5.45.15_PM.png

The first step for the enclosure was making the files for lasercutting.

To make the box, we used https://en.makercase.com/ with the following settings:

  • Units: mm
  • Width: 350mm
  • Height: 30mm
  • Depth: 175mm
  • Inside dimensions
  • Material thickness: 3mm
  • Open box
  • Finger joints
  • Finger size: 14.63

Finally, we added the hole for the USB port on the side in Adobe Illustrator.

  • the size and placement of the hole will depend on the size of your micro USB cable housing.


To make the top, we used Fusion 360 and Adobe Illustrator.

  • Key holes are 34mm/34mm
  • Octave buttons and volume knob holes are 20mm in diameter
  • The corner screw holes are 3mm in diameter
  • Spacing and location of these are subjective but our layout can be seen above

Lasercutting and Woodwork

IMG_5524.JPG
IMG_5521.JPG
IMG_5522.jpg
IMG_5543.JPG
IMG_5561.JPG
IMG_5546.JPG

Next, those files were sent to the lasercutter. Once cut, we taped used painters tape to hold the box together and check the dimensions.

Small wooden blocks measuring 3/4" on all sides were cut to place in the corners of the box, giving the top something to rest on and providing extra strength to the corners.

Strengthening the Box

IMG_5563.JPG
IMG_5578.JPG
IMG_5580.JPG
IMG_5562.JPG
IMG_5581.JPG

Next, we had to make the box solid. To do this we used Gorilla Epoxy.

  1. Firmly tape the box
  2. Mix epoxy and apply along all inside edges
  3. Apply to the bottom and outside faces of the corner blocks
  4. Wait to dry

This took a lot more time and patience than expected. Make sure pressure is applied when gluing two sides together. The packaging said it takes around 20 minutes to dry but it took much longer until it felt sturdy enough to remove all the tape.

Even then, it still felt a bit shaky so we added epoxy to the outside corners as well.

Because the fingers on our laser cut box were too short, the edges and corners didn't fit together without tape or glue. The process will be a lot easier and quicker of the fingers of the sides fit flush and snug.

Remove Tape and Prep for Bondo

IMG_5589.JPG
IMG_5590.jpg
IMG_5593.JPG

Once the epoxy was fully dried and held the box together well, the tape was removed.


If your box has flush edges, skip to Step 6.

Step 5 is for filling in open edges and corners.


To address the open edges and corners of the box, we decided to use Bondo. Bondo is a strong putty that is applied as a paste and quickly dries to concrete like material where it can be sanded.

To prep the box for the Bondo, painters tape was once again used. This time it just needs to outline the edges so that Bondo doesn't get on the flat wood.

Bondo

IMG_5594.JPG
IMG_5595.JPG
IMG_5596.jpg
IMG_5599.JPG
IMG_5600.JPG

Once taped, you are ready to apply the Bondo. It is highly recommended that you do this outside with a mask, the Bondo is extremely pungent.

  1. Put Bondo on cardboard
  2. Add activator (50:1 ratio of Bondo to activator is recommended)
  3. This determines how fast it hardens. Too much and it gloops up and is hard to spread. Too little and it takes a long time to dry/harden.
  4. Mix together with a popsicle stick
  5. Apply to the edges of the box
  6. It is easier to remove than go back and add more. Be generous
  7. Once the Bondo has hardened to about the consistency of a rubber eraser, use a utility knife to shave off some of the excess. It is much easier to do this now with a knife for large sections than trying to sand it all later.
  8. Finally, once it is fully dried and hardened, sand down it all down to the level you want. I used 120 grit but something a little rougher helps for sanding larger amounts at the beginning.
  9. Let this air out outside for a while, your house will smell like Bondo if you bring it in immediately.

This takes a decent amount of practice and a lot of patience. We did not get a very clean finish with ours but with more practice and better tools this could look really good if needed.

Spray Paint

IMG_5607.JPG
IMG_5615.JPG

The outside of the box and the top plate were given two coats of black spray paint each. Make sure to apply evenly and avoid having the paint be runny/drippy.

These were left outside over night to dry and air out. The Bondo scent was still noticeable and the paint wasn't helping.

Circuitry

IMG_5621.JPG
IMG_5585.JPG
FinalSchematic_schem.jpg
IMG_5586.jpg
IMG_5554.JPG
IMG_5552.JPG
IMG_5553.JPG
IMG_5583.JPG
IMG_5584.JPG

First, set up the power and ground of the microcontroller on a breadboard and place it in the corner. It can be attached with the adhesive on the bottom.

For the circuitry, we made each section of the keyboard with a separate PCB prototype board to minimize the space they took up inside and make them easier to work with individually.

All of the buttons just used a basic button-to-digital-pin circuit and the the volume knob used a potentiometer circuit.

These are fairly simple to do but can be time consuming. Make sure to measure the amount of wire each button will need based off of its distance from the breadboard.

Assembly

IMG_5625.JPG
IMG_5540.JPG
IMG_5591.JPG
IMG_5592.JPG
IMG_9465.png
IMG_9508.png
IMG_5629.JPG
IMG_9512.png

Finally, we got to the assembly.

First, we cut up the rubber mat into 33/33mm squares and superglued them to the buttons. This gives them a softer but still tactile feel.

We also 3D printed button caps for the octave buttons and a knob for the potentiometer. Those were glued on as well.

To attach all the circuitry to the box, we glued small pieces of wood down and then glued the PCB boards on top of those. These made sure that the buttons were at the correct height and gave us channels to route the wires through to the Nano.

The last step, if you want to secure the top plate, is to put wood screws through the holes of the top plate into the wooden corner blocks.

Code: Hairless MIDI and Arduino

To connect the MIDI keyboard to Ableton, we used Hairless MIDI to create the connection, and loopMIDI to create a virtual MIDI port. First, we set up the virtual MIDI port by opening loopMIDI and creating a new MIDI port. Once that port was opened, we opened Hairless MIDI and selected the microcontroller we were using (Nano 33 IoT) and selected the newly created MIDI port as the input and output. To test if the MIDI was working, we used example code from amandaghassei on Instructables.


byte noteON = 144;//note on command

void setup() {
  Serial.begin(9600);
}

void loop() {
  for (byte note=50;note<80;note++) {//from note 50 (D3) to note 79 (G5)
    MIDImessage(noteON, note, 100);//turn note on
    delay(300);//hold note for 300ms
    MIDImessage(noteON, note, 0);//turn note off (note on with velocity 0)
    delay(200);//wait 200ms until triggering next note
  }
}

//send MIDI message
void MIDImessage(byte command, byte data1, byte data2) {
  Serial.write(command);
  Serial.write(data1);
  Serial.write(data2);
}


The rest of the code came from ma 8az on Instructables, but we replaced the MIDI library calls with the Serial MIDI messages instead. We ran into some trouble with the code for controlling the volume knob, as it sent so much data to the Hairless MIDI that it ended up crashing. In the future, we might change the knob to control the velocity of the notes instead of the volume, so it doesn't overload and crash Hairless MIDI.

When you open Hairless MIDI, there should be green lights flashing to indicate a signal being sent. If there aren't any green lights, you should check in the Baud rate of the code and the MIDI are the same. You can check the Baud rate of Hairless MIDI in the Preferences, and change it from there. While testing out the Hairless MIDI, make sure to not open the Serial monitor in Arduino! Since Hairless MIDI is reading from the Serial monitor, this will mess with the connection and you won't be able to see if the signals are actually being sent. Also make sure that the Baud rate matches in both the code and in Hairless MIDI. To change the Baud rate in Hairless MIDI, you can open Preferences and change the Baud rate from there.

Once you have signals being sent, keep Hairless MIDI and loopMIDI open, and open any Digital Audio Workstation of your choosing. We used Ableton. There should be the MIDI port that was created using loopMIDI, and there should be signals being sent from it, so just connect to that and start making music!

Some troubleshooting for issues that you might run into. We had to unplug and replug in our MIDI, since there were sometimes issues when uploading the code to the microcontroller. Also, the CPU in Ableton might get overloaded a lot, so it's best to have your computer or whatever device you are using plugged in.


The code is attached below.