HackSpace – September 2019

(Jacob Rumans) #1
LENS

MIDI input


MIDI (which stands for ‘Musical Instrument
Digital Interface’) is a technology used extensively
in studios and live gig situations to connect
synthesizers, drum machines, sequencers, and
more. For our final feature, we’re going to add a MIDI
input to the glockenspiel so that it can be played
digitally by another instrument.
MIDI outputs are relatively simple to wire up, since
you’re just sending an electrical signal down a wire,
but MIDI inputs are a little more complex. Since you
can’t really trust signals coming from external
devices, a MIDI input uses an optocoupler which
converts the incoming signal into pulses of LED light,
then immediately back into an electrical signal again.
Add the extra components to your existing circuit.
In the Arduino software, install the ‘MIDI Library’ by
Forty Seven Effects and upload the sketch. You may
actually need to disconnect the jumper wire from
pin 0 in order to do the upload, because the Arduino
gets confused between the computer’s USB signal


and the keyboard’s MIDI signal – you can replace the
jumper after the sketch has been uploaded.

GETTING THERE SLOWLY
If everything is working properly, pressing certain keys
on the keyboard (middle C, and the octave of keys
above it) will now cause the servos to move. The code
is written so that holding down a key will move the
arm into position, and releasing the key will cause the
beater to strike. While this is a little counter-intuitive, it
actually makes the instrument easier to play accurately


  • if the Arduino attempted to move to a note and hit it
    as soon as a key was pressed, there would be a
    noticeable delay before each note while the arm
    moved into position. With this method, as long as the
    player can get used to playing ‘in reverse’, the latency
    is much better, and it’s possible to play along in time to
    a piece of music.


Left
:inJe the arT has a
SiTited ranNe onS` the
TiddSe oJta]e oM the
40+0 Re`Ioard aMMeJts
the NSoJRenspieS
Below
;he rest oM the JirJuit
reTains in pSaJe
Iut I` addinN a 40+0
port we Jan JontroS
the roIot arT MroT
another instruTent

You might notice that some numerical values in these
sketches are of the type ‘unsigned long’, rather than
just ‘int’ (integer). The Arduino usually deals with time in
milliseconds, but the number of milliseconds in a day is too
large to be stored as an ‘int’ value, so instead we use ‘long’
variables which can contain much larger integers.
The ‘unsigned’ part means that the value can only be
positive, and allows for even larger numbers. If you find
any strange behaviour while writing or modifying code for
your glockenspiel, think about whether any of the variables
need to be ‘long’ or ‘unsigned long’ instead of ‘int’.

Since this project was already based around an Arduino Uno, a plug-and-play Ethernet
shield made sense, but there are loads of different ways to add internet connectivity to an
electronics project. You could swap your regular Arduino Uno for an Uno WiFi with wireless
capability, although it’s about twice the price of a regular Uno.
A Raspberry Pi would also be a good choice for this project, since many models come with
WiFi. You could either connect a RPi to the Arduino via USB, or run the whole build solely
from a Raspberry Pi. There’s a huge number of options for small controller boards at the
moment, and this project should work on most that can control servos (which is the majority).

Signing off


Switching brains


Quick Tip


If you made changes
to the note positions or
delay times in the main
sketch, remember to
copy these over to the
other sketches.
Free download pdf