MIDI Keyboard

by calisb in Circuits > Raspberry Pi

219 Views, 3 Favorites, 0 Comments

MIDI Keyboard

IMG_0298.jpeg

My background in music production inspired me to create my own MIDI keyboard. MIDI keyboards are essential in the music creation process and can be found in every music studio. Almost every modern song we listen to consists of MIDI signals. The advantage here is that you can access the biggest and best sample libraries and virtual instruments by only using your laptop and a MIDI controller.

Supplies

Planning

The first step was to decide the shape of the MIDI Keyboard. The "console box" template on Festi's Boxes.py had the perfect shape for a small on desk MIDI device. However, I changed the length of the size from 100mm to 200mm to give it enough space for the actual keyboard and the microcontroller and cables.

With Adobe Illustrator I changed the stroke size to 0.01mm and the color to RGB Red, so the Laser cutter could recognise the shape.

For the keyboard I used my own design which was also done with Adobe Illustrator. A basic 12 note keyboard layout was the foundation for my design. Note that the stroke color and size was not changed because the laser cutter engraved the keyboard on the wood.

Cutting

A Trotec laser cutter was used to cut out the design. The material was 1/4" baltic birch. Several test cuts were made on cardboard first.

Assembly

IMG_0302.jpeg

The different parts were glued together with wood glue, except for the top part which represents the lid. Through that lid the electronic was places inside, providing enough space for the alligator clips. For the keyboard part, first the copper tape was placed on each key and then the screw through the copper tape. The screws serve the purpose of making it easier for the alligator clips to attach. Additionally, another layer of copper tape was placed on top of the screw for more stability. Inside the box is the Rasperry Pi Pico on a breadboard attached to the MPR121Touchpad with alligator clips.

Testing

Screenshot 2023-03-28 at 13.44.22.png

Download the following code.py and load it up to MuEditor. It should create a new MIDI channel which will be recognised by your audio software (also known as "DAW"). For this example I selected Logic Pro but any other digital audio workstation (DAW) should work as well as MIDI is a universal language. Create a software instrument in your DAW and start jamming!

Code

Screenshot 2023-03-28 at 13.52.32.png

# Note: This program has set the keyboard to the C4 octave, you can change that using the MIDI note map

import board, time


# Pico MPR121 Debouncing Touchpads

import adafruit_mpr121

from adafruit_debouncer import Button

i2c = board.STEMMA_I2C()

touch_pad = adafruit_mpr121.MPR121(i2c) #12 touchpads


# For loop to create pads list with (debounced) Buttons

pads = []

for t_pad in touch_pad:

  pads.append(Button(t_pad, value_when_pressed = True))


#MIDI

import usb_midi

import adafruit_midi


from adafruit_midi.note_on import NoteOn

from adafruit_midi.note_off import NoteOff

from adafruit_midi.pitch_bend import PitchBend

from adafruit_midi.control_change import ControlChange


midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)


print("Midi test")

print("Default output MIDI channel:", midi.out_channel + 1)


while True:

  for i in range(len(pads)):

    pads[i].update() # gets current state of each debounced pad

    if pads[i].pressed:

      print(f"You touched pad number {i}!")

      # 72 = C4, 60 = C3 (always +/- 12 to change the octave)

      midi.send([NoteOn(72+i, 80), PitchBend(8192)]) # No PitchBend at 8192 (represents the middle vlaue from 0 to 16383)

    if pads[i].released:

      print(f"You let go of pad number {i}!")

      midi.send([NoteOff(72+i, 80), PitchBend(8192)])