This is only a preview of the August 2022 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
|
Simple
MIDI Music
Keyboard
by Tim Blythman
This MIDI Keyboard is a follow-up to our 64-key
MIDI Matrix. It is just as flexible and offers a way to easily
make music, although it can be repurposed for many other uses.
W
hile MIDI Matrix panels
are popular for being a compact way of controlling and
interfacing to MIDI equipment, a linear
keyboard arrangement like a piano is
more ‘standard’ and, for many people,
quite intuitive.
This is a modular add-on to the MIDI
hardware we introduced in April and
May 2022. Like the MIDI Matrix, it
doesn’t have to be used strictly for MIDI
or musical purposes.
The MIDI Matrix was designed to be
used with an Arduino Leonardo board,
since the Leonardo can easily provide
a native USB MIDI interface through
the versatile Arduino MIDI libraries.
We also demonstrated some program
sketches that can run on the Leonardo to
give various features, and showed some
ways to interface with software on both
a PC and an Android smartphone.
At the same time, we presented an
Arduino shield that lets you interface the
hardware to a great range of MIDI equipment using standard DIN connectors.
This Keyboard is intended to replace
the Matrix as part of a larger construction, as presented in the earlier parts
of this series. Refer to those articles,
particularly the first part, to understand how the Matrix (and now Keyboard) can be used. At a minimum,
you need an Arduino Leonardo board
and some jumper wires to turn the Keyboard presented here into a minimal
MIDI Encoder.
The Matrix
The original Matrix is basically just an
array of pushbuttons that the Leonardo
can scan to receive user input. In our
MIDI software, each keypress is converted to a musical note.
26
Each row or column of the Matrix is
wired to a digital pin on the Leonardo.
By using the time-honoured technique
of scanning each row in turn, individual button presses can be detected.
In our version of the software, the
rows are connected to pins configured
as inputs with weak pull-ups. Initially,
all column pins are set to a high impedance input mode too.
Each column is configured as an
output in turn, and driven low. If any
button connected to that column is
pressed, its corresponding row pin
is pulled down through the switch
contacts. By scanning the columns
in turn, we can detect individual button presses.
While this system is simple, it cannot detect multiple simultaneous keypresses; for this, each switch needs to
be fitted with a diode to prevent ambiguous closures propagating through the
Matrix. Our Matrix omits these diodes
in favour of simplicity and compactness, and this linear Keyboard is the
same in that respect.
The new Keyboard
We considered a linear keyboard for
our original design but could not work
out a way of making it both compact
and functional.
We have now formulated a modular design, so a useful Keyboard can
be built that is still compact, or it can
be expanded to 64 keys, resulting in a
device that’s over a metre long! But it
still only needs 16 wires to connect it
to the Arduino.
The basic unit of the Keyboard is a
single PCB with eight keys. Each key
is wired to the same row contact as the
others and also to one of the eight column contacts. A single Keyboard module is identical to one row of the Matrix.
Fig.1 shows the circuit. CON1 is
wired to the columns, with each terminal on CON1 wired to one side of each
of the tactile switches, S1-S8. Position 1
of CON2 is connected to the other side
of switches S1-S8.
At each end of the Keyboard module PCB are connectors CON3-CON6,
which can be used to daisy-chain subsequent PCBs to expand the Keyboard.
These are eight-way surface-mount
pads, spaced 2.54mm apart.
CON3 and CON5 (on the top side of
the PCB) are wired in the same order
as, and in parallel with CON1. Thus,
the column signals can pass between
the PCBs by joining their adjacent
CON3 and CON5. These are wired as
a parallel bus.
Our prototype uses three of these PCBs, as
a keyboard made from a full set of eight PCBs would be
well over a metre wide! We’ve retained the CON1 and CON2 pads on some
of the boards to demonstrate and test the different options. In practice, only one
set is needed; note that connecting to CON3 and CON4 is equivalent.
Practical Electronics | August | 2022
Fig.1: this is the simple circuit of a single PCB with eight switches. The
offset between CON4 and CON6 is what makes it easily expandable up
to eight PCBs and 64 buttons.
Similarly, on the back of the PCB,
CON4 on one PCB connects with
CON6 on the next. CON4 is wired the
same as CON2, but the clever part is
how we have wired CON6. Pin 1 of
CON6 is wired to pin 2 on CON4, and
so forth, all offset by one position.
Say we wired up an array of eight
of these modules, numbering them
1-8 from left to right, with CON3
and CON4 wired to CON5 and CON6
respectively. Connecting to CON1
and CON2 on the first module, we
would have the equivalent of a full
8x8 Matrix only with the keys in a
single row.
Fig.2 shows how the ‘rows’ are
mapped back to CON2 on the first PCB.
CON1, CON3 and CON5 are all simply
wired in parallel and are not modified
by this system.
MIDI Keyboard Strip
Other configurations
If you look closely at the PCB, you can
see that the little tab where CON1 and
CON2 jut out is scored for removal.
This lets you remove these tabs on all
but one module.
In fact, since CON3 and CON4 are
wired identically to CON1 and CON2,
you can even remove the tab from all
boards and simply take the matrix connections from CON3 and CON4 of the
leftmost board instead.
If you don’t mind remapping the pins
in software (or changing how they are
wired back to the Leonardo board), the
CON1 and CON2 connections do not
have to be made on the first board. You
could even take these connections from
the middle of the array.
We’ve designed the PCB to use large
12mm tactile switches, as these have a
much nicer feel with a large finger surface. You might find that some smaller
switches can be made to fit by bending their leads, although we haven’t
tried that.
Since there is less space for routing
on this PCB than the Matrix, it lacks
the option to fit illuminated switches
that the Matrix had.
Hardware
Like the Matrix, the Keyboard we are
presenting has quite a basic design,
so that you can customise it to your
requirements. The switches are placed
on 20mm centres, with four M3 mounting holes provided on each PCB.
Nominally, the mounting holes will
be on 40mm centres, although this
depends on the accurate assembly of
adjacent boards. The PCBs are 20mm
Fig.2: this shows how multiple 8-button Keyboard PCBs are joined so that the Arduino can tell which key has been pressed.
Each PCB along the chain offsets where the connection is ultimately made at CON2, allowing for up to 64 keys to be sensed.
Practical Electronics | August | 2022
27
high, not counting the tab for CON1
and CON2; 28mm with the tab in place.
We strongly recommend mounting the Keyboard to a sound backing
so that the PCBs do not flex when the
keys are pressed. The connections for
CON3-CON6 will not provide much
mechanical strength as they are effectively surface-mounting pads, and are
only bonded to the PCB superficially.
Construction
Most people will want to build a
Keyboard with multiple PCBs laid
out as a continuous strip, so we will
describe what is needed to achieve
this. The Keyboard is built on a PCB
coded 23101213, which measures
158 x 28mm and is available from the
PE PCB Service. Use the PCB overlay
diagram, Fig.3, as a guide to fitting
the components.
Plan and lay out the modules
before commencing construction. To
keep things compact, the connections
between the boards are a little tight, and
it will be easier to join them before fitting other components.
If you want a different layout, just
about any method of wiring CON3 and
CON5, and CON4 and CON6 respectively will work. You might even like to
use header sockets on one and header
pins on the other to allow the units to
be unplugged, although this will not
achieve a tight spacing.
To start the PCB assembly, snap off
any CON1/CON2 header tabs that are
not needed. Do this by scoring along
the line with a sharp knife to cut the
copper traces, then carefully flex the
PCB with pliers to make a clean break.
You might like to clean up the rough
edge. As well as our usual warnings
about avoiding the inhalation of PCB
dust (eg, by working outside and wearing a mask), take care not to file away
the traces which run close to the edge
of the PCB, especially at the back.
Each PCB is 158mm long, meaning
that there is 2mm of spare space for a
joiner if the key spacing is to be kept
even. We used cut-down double-row
pin headers. The plastic spacers are
very close to 2mm deep, giving the necessary spacing.
Start by cutting down the headers to
be used for joiners. This is fiddly but
necessary, as there is no more than
What about the black keys?
You might be thinking that pianos actually have two rows of keys, white and black, and you would
be right. Also, there are seven white keys per octave, not eight. We have kept this as a linear array of
eight keys to make it simple and applicable to a wide range of applications.
We plan to produce a 12-key PCB at a later date which has the keys staggered and grouped like a
piano. In the meantime, if you’re keen to use this board like a proper piano, you could build it in two
rows, with the top row offset horizontally 6mm from the bottom row and with gaps in the keys at the
top to give the proper configuration. Both rows could be wired up in series (assuming they contain
no more than 8 PCBs total).
The software could be modified relatively easily to remap the two rows of keys into the correct
sequence so that it can act as a keyboard piano. The restriction of only one keypress being detected
at a time would remain, though. Our planned future piano keyboard PCB would remove that restriction.
8mm between adjacent switch bodies
on neighbouring PCBs, and typical pin
headers are around 11mm tall.
You can halve the number of cuts by
shifting the pins in the plastic. Place
the PCB on a hard flat surface and rest
the 2x8 pin header in the CON1/CON2
holes. Push the plastic down firmly
with a flat edge that fits between the
pins. A steel ruler is ideal for this.
This will move the pins such that
only 1.6mm (the PCB thickness) of each
pin is proud. Now reverse the 2x8 pin
header, and use the depth of the PCB
as a jig to cut 1.6mm from the other
side of the pins.
The pin stubs may fly off at speed, so
wear safety goggles and aim the header
while cutting so that they fly away from
you. See the photos opposite that show
what the header should look like after
being trimmed and then attached to
the PCBs.
Soldering these headers is a little
tricky as they are not a snug fit. Treat
them like a surface-mounted part,
applying flux paste to the pads before
soldering. We recommend securing
the parts during soldering with hightemperature tape (eg, Kapton) so they
don’t move around.
Tack the ends in place and check that
the pins do not foul the tactile switch
footprints. You might even like to testfit the switches to confirm clearances.
Solder the remaining pins – be generous with the flux, it helps the solder
form clean beads that sit where they
need to. Flip the board and complete
the headers on the back of the PCB.
Remove any excess flux using a flux
cleaner, and test the exposed CON3CON6 pads for continuity between the
ends of the strip. As you can see from
Fig.2, CON3 is wired straight through
to CON5. But CON4 will be offset relative to CON6 (unless you have the full
complement of eight PCBs), so check
that each pad on CON4 is connected to
one and only one pad on CON6.
It’s best to do this now, as it can be
quite fiddly to rework these connections with the tactile switches in place.
Fit the switches next. They should
snap neatly into place; just check that
they are sitting flush before soldering.
Finally, solder headers for CON1
and CON2. We used female headers to
match the cables we had made up for
the Matrix, but you can use whatever
works for your arrangement, even soldering wires directly to the PCB.
Hooking it up
We tested our unit with the MIDI_
ENCODER sketch. If you haven’t done
so already, we recommend reading
the earlier parts of this series of articles, as they describe the software in
more detail.
Since the Keyboard is effectively
equivalent to a Matrix fitted with
non-illuminated switches, you can
transfer many of the ideas relating to
the Matrix to the Keyboard.
As with the Matrix, wire CON1 of the
Keyboard to CON2 of the MIDI shield
(or corresponding Leonardo pins) and
CON2 of the Keyboard to CON1 on the
MIDI shield, connecting pin 1 to pin 1.
Check that all buttons work as
expected using the key notifications that
appear on the Arduino Serial Monitor. If
you find that some keys on a PCB don’t
work (but not all), check the column
connections for continuity; these are
CON3 to CON5 on the front of the PCB.
If none of the keys on a PCB work,
then it may be a problem with the CON4
to CON6 row connections on the back
of the PCB.
Fig.3: there’s not much to get wrong during assembly, although we recommend fitting the PCB joiners first, as the tactile
switches will make access difficult when soldering them. The buttons should snap into place, so soldering them is easy.
28
Practical Electronics | August | 2022
Parts List – Full 64-key Keyboard
8 Keyboard Modules
7 2x8 male pin headers, trimmed in height (CON3-CON6)
1 2x8 pin header (male or female to suit Leonardo connections, CON1 and CON2)
mounting hardware to suit usage (M3 tapped spacers, screws etc)
Keyboard Module
1 double-sided Keyboard PCB coded 23101213, 158 x 28mm (available from
the PE PCB Service)
8 12mm tactile switches [eg, Diptronics DTS-21N-V or
Jaycar SP0608/SP0609, Altronics S1135 + S1138]
www.poscope.com/epe
With the set of Keyboard PCBs
wired up to our MIDI shield,
we have a linear array of
buttons that you can play like
a piano. But keep in mind
that by default, unlike a
piano, multiple keys cannot
be played at the same time.
- USB
- Ethernet
- Web server
- Modbus
- CNC (Mach3/4)
- IO
- PWM
- Encoders
- LCD
- Analog inputs
- Compact PLC
- up to 256
- up to 32
microsteps
microsteps
- 50 V / 6 A
- 30 V / 2.5 A
- USB configuration
- Isolated
PoScope Mega1+
PoScope Mega50
Conclusion
Like the Matrix, the Keyboard is
designed to work with our MIDI hardware and software. But we think that
readers will find other uses, especially
in cases where many buttons need to be
connected to a microcontroller.
Reproduced by arrangement with
SILICON CHIP magazine 2022.
www.siliconchip.com.au
The cut-down header pins (above-left)
measure around 7mm tall so that they
will fit between the end switches on
adjacent PCBs (below-left). The plastic
part is 2mm tall, so uniform board
spacing is achieved too.
Practical Electronics | August | 2022
- up to 50MS/s
- resolution up to 12bit
- Lowest power consumption
- Smallest and lightest
- 7 in 1: Oscilloscope, FFT, X/Y,
Recorder, Logic Analyzer, Protocol
decoder, Signal generator
29
|