Schmiede19 MIDILAB

This post developed during the DIY MIDI controller workshop at Schmiede 2019 in Hallein (Austria). It was used as a presentation and documentation tool.

What can we do with MIDI?

  • Play notes
  • Change parameters
  • Change programs/presets

What is MIDI?

  • a serial communication protocol
  • bitrate of 31250 bps (bits per second), also called “baud rate”
  • each message consists of 2 or 3 bytes

MIDI messages

| Value (dec) | Value (Hex) | Command          | Data bytes                |
| ------------| ----------- | ---------------  | ------------------------- |
| 128-143     | 80-8F       | Note off         | 2 (note, velocity)        |
| 144-159     | 90-9F       | Note on          | 2 (note, velocity)        |
| 160-175     | A0-AF       | Key Pressure     | 2 (note, key pressure)    |
| 176-191     | B0-BF       | Control Change   | 2 (controller no., value) |
| 192-207     | C0-CF       | Program Change   | 1 (program no.)           |
| 208-223     | D0-DF       | Channel Pressure | 1 (pressure)              |
| 224-239     | E0-EF       | Pitch Bend       |                           |
| ------------| ----------- | ---------------- | --------------------------|

16 MIDI channels

Note byte 1 (channel):

  • Channel 1: 144
  • Channel 2: 145
  • Channel 16: 159

Note byte 2 (note number):

C0  = 0
C1  = 24
C#1 = 25
C4  = 60
A4  = 60
C5  = 72

MIDI note numbers list

another MIDI note numbers list

CC message:

  • Channel 1: 176
  • Channel 2: 177
  • Channel 16: 191


Send a NoteOn message for the note of D#3 on channel 1 with a velocity of 90:

144 | 36 | 90

Send a Control Change message for Controller number 81 on channel 2 with a value of 65

177 | 81 | 65

Can we choose any CC number for our controller?

midi cc list

Getting to know the hardware

official Arduino specs comparision table

Nano pinout

Pro Micro pinout

Nano specifics

The Nano is very similar to the well-known Arduino Uno, it only is smaller and has more connection possibilities.

Chinese Nano clones (CH340)

The Arduino Nano clones we use, have a CH340 chip that does the USB to serial conversion. To program it we need a USB-driver specific to our computers operating system.

For Mac OS X High Sierra and above we need this driver

For Windows 10 we need this one

Programming settings

Golden USB socket version:

  • Board: Arduino Nano
  • Processor: ATmega328b

Silver USB socket version:

  • Board: Arduino Nano
  • Processor: ATmega328b (old bootloader)

Both types:

  • Select the correct serial port
    • Mac OS X: something called /dev/cu.something (eg. /dev/cu.wchusbserial1410)
    • Windows: COMx (eg COM4, COM10, …)
      • use the Devicemanager to find out which COM port appears when you connect the Arduino to the USB port

If our programming settings or the CH340 driver are wrong this is one of the possible errors:

avrdude: stk500_getsync(): not in sync: resp=0x00

Pro Micro specifics

Sparkfun Pro Micro hookup guide

nice Pro Micro connections video-tutorial, also about multiplexing input

Chinese Pro Micro clones

Specifically this chip: ATmega32U4 5V 16MHz

Programming settings
  • Board: Arduino Leonardo
  • Select the correct serial port
    • Mac OS X: something called /dev/cu.something
    • Windows: COMx (eg COM4, COM10, …)
      • use the Devicemanager to find out which COM port appears when you connect the Arduino to the USB port

Wiring power connections and a button

To power the plus- and minus-rails of our breadboard we connect the 5V and GND pins to it. On the Pro Micro the 5V pin is called VCC.

The position of the switch and its wiring on the breadboard is wrong in this pic and can damage the Arduino! Refer to the pics in chapter Wiring the MIDI socket for the correct position and wiring of the switch.

So why is position and wiring of the switch wrong?

The short answer is: Because we assumed that these switches work similar to a lot of other switch types.

The square-button-switches we use are so called DPDT switches (Dual Pole Double Throw). This basically means that we can use them to switch on/off or toggle two things with one buttonpress. Or put differently: Two switches in one.

This is how a regular DPDT switch works. Pins 1, 3, 5 represent one toggle switch and pins 2, 4, 6 the other one. If we would plug in one of those into the breadboard as shown on the photograph above we would be perfectly fine: Even though we connected some pins together via the vertical rows of the breadboard (pin-pairs 1+2, 3+4 and 5+6 would connect), everything would be working as it should: Our goal is to connect one Arduino pin (D2) to either 5V or GND (high or low). We actually don't care that we can't use the second switch in our DPDT anymore.
The switches we use are also DPDT switches that certainly can also be used to toggle two things at a time, only that their two (vertical) pin rows don't operate in parallel - their pinout is completely different.

Let's assume the same pin numbering as on the regular DPDT diagram on the left, for our oddly wired switches on the right: In off-state 1+5 and 2+6 connect. In on-state it's 1+3 and 4+6.

So what actually happens when we plug in the power to the breadboard (connect the Arduino to a USB port) and keep the button unpressed, is: We connect + and - poles together (via pins 1 and 5) and thus short-circuit the Arduino which it can withstand for a short time only.

To correctly wire these types of switches we need to:

  • plug them into the middle of the breadboard so the two 3-pin-rows aka the 2 switches are isolated from each other.
  • use pin 5 (bottom-right / blue wire on pic below) to connect to the Arduinos input (D2).
  • in unpressed state pin 1 (bottom-left / green wire) and pin 5 are connected and thus D2 is connected to GND
  • in pressed state pin 1 (middle / purple wire) and pin 3 are connected and thus D2 is connected to 5V.

Wiring the MIDI socket

This schematic shows the socket from the backside (the soldering side)
The socket is held as on the schematic. We are looking at the soldering side. The socket's TX pin is the orange wire on the top-left.

Be aware of that the circuit-/breadboard socket is flipped upside-down compared to the wiring schematic above! The TX pin is the violet wire on the (bottom-)right.
A circuitboard/breadboard socket seen from the front. The TX pin (5) would be bottom-left now

For more detailed schematics and information on MIDI Output and MIDI input wiring refer to the official MIDI specification of the MIDI manufacturers association

Wiring a potentiometer

The output of a pot usually is the middle pin (but as we learned earlier never trust on this! ;-)). It"s connected to the Arduinos analog input pin A0. The left pin (purple) we connect to ground and the right pin (green) to 5V.

When we twist the knob to the left we decrease the resistance between ground (purple wire) and the pots output (yellow wire) until it is 0 Ohms. When twisted to the right the resistance between the two wires increases until it reaches almost the nominal value of the pot (10kOhms). The actual Ohms are not of interest when using pots with Arduinos. When we read out the current value of an analog input we always receive a number between 0 and 1023

There is a second yellow wire that is supposed to be connected to a second pot but for now we put it on ground so the Arduinos input A1 does not deliver measuring values and disturb us while coding and/or debugging.


The code we produce is available on this github repo

Direct links to “git commits”:

final code day 1 - reading in a button’s state

final code day 2 - sending out midi CC on and off

day 3 - four switches for-loop example

day 3 - two pots for-loop example

Thanks a lot to all the particpants! You really were lovely and it was a pleasure to teach you!

This article was published on Sep 16, 2019. I built/coded/did this project around September 2019. jump to top