Tactile Button Keyboard PCB

I’ve used tactile buttons as musical keyboards in a number of my projects now and either build them on solderless breadboard, which is quite unreliable, or on stripboard, which is a little messy.

This PCB design is for a one-octave tactile button keyboard PCB that has various modes of operation and is extendable to two octaves.

Here is the build guide: Tactile Button Keyboard PCB – Part 2.

ButtonKeyboard-3d

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key tutorials for the main concepts used in this project:

If you are new to microcontrollers, see the Getting Started pages.

The Circuit

ButtonKeyboard-sch

Each switch is a basic “connect to ground” switch, so will require the linked input pins to be in INPUT_PULLUP mode.  There are diodes for each switch to reduce ghosting, but this will not eliminate it completely – there are still some combinations where it might occur.  All “ROWS” and “COLS” are broken out to headers for ease of use.

The Arduino Keypad library treats all COLS as the OUTPUTs and all ROWS as the INPUTS.  ROWS will be in INPUT_PULLUP mode and COLS will be individually changed from INPUT to OUTPUT and set LOW in turn to “scan them”.

Note that whilst eight “rows” and four “cols” are provided, to cover a single octave actually only requires 2 “cols” and 6 “rows”.  There is the option of using a 7th to support a 13th note for the “top octave” in any configuration.

Two boards can be linked together, and the second two unused “cols” can be extended to the second octave on the additional board.

It is also possible for the output stages to be driven from a 74HC138 3 to 8 decoder.  This means that just 3 GPIO pins (plus 5V and GND) could be used to drive the eight “rows” of the matrix.  Full decoding of the matrix thus requires just 3 GPIO for the outputs and 2 GPIO (per octave) for the inputs. But there are some significant caveats (see below).

There is also the option for the PCB to include an Arduino Nano directly to drive all the GPIO pins itself.  In this configuration there is the option of breaking out the RX/TX pins via the same header that would have been used for the HC138 to allow some kind of external connectivity – for a MIDI interface for example.

It is also worth noting that if the HC138 or the Nano are not used, and the switches are simply decoded directly, then there is nothing inherent in this board that requires 5V operation, so it can be used just as easily with a Raspberry Pi Pico as an Arduino.

74HC138 Support

Unfortunately there are two pretty significant problems that stop this PCB easily being used with the 74HC138.  Oh and one minor annoyance!

The direction of the diodes has to correspond to what I’ve labelled the ROWS being the OUTPUTs and the COLS being the INPUT if the HC138 is to be used.  Unfortunately I had my usual confusion over ROWS, COLS, INPUTS, and OUTPUTS (despite checking several times) and my PCB has the diodes the WRONG WAY ROUND for use with the HC138.

Also, the logic for the three EN pins of the HC138 is reversed.  I’ve connected E1 and E2 HIGH and E3 LOW, and it should have been the other way round!

If that wasn’t enough, even if patched then the HC138 outputs (Q0 to Q7) are reversed compared to the ROW numbering (1 to 8).

So in summary:

  • If being used directly then the ROWS and COLS are appropriately labelled for use with the Arduino Keypad library and the diodes are correct for the COLS being the OUTPUTs and the ROWs being the INPUTs.
  • If the board is to be used with a 74HC138 then the COLS/ROWS are opposite to what is assumed by the Arduino Keypad library and the diodes are the WRONG WAY ROUND.  Also, the numbering of the HC138 outputs is reversed too.
  • With the current version of the PCB, the 74HC138 won’t work at all without some fairly non-trivial patching for E1, E2, E3.  But it is possible.

Sigh.

PCB Design

ButtonKeyboard-pcb2

The previously described options should be reflected in the PCB design as shown above (with the GND planes removed for clarity).  There are two sets of pin headers on the sides of the board for the ROWS and COLS and another 5-way header at the top for the optional HC138 or UART link if using an Arduino Nano.

The PCB includes a removable 13th note for the top of a full octave if used standalone, but also allowing it to be “cut off” to connect one octave to a second.  When connecting two boards, the pin headers should align to allow for relatively easy connections between boards.

Note that only one configuration of the board should be used at any one time:

  • Direct ROWS/COLS links; OR
  • HC74138 3-to-8 decoder (DOESN’T WORK at present without patching); OR
  • Arduino Nano.

The UART link can only be used if used with an Arduino Nano.

ButtonKeyboard-ger

Closing Thoughts

There are a number of ways this board could have been put together.  I actually experimented with a two-octave version directly, but the dimensions meant it would have been quite expensive to produce, hence going for this “extendable” version.

I was also unsure quite how to allow for the 13th note. In the end I opted to just go with six OUTPUT lines and two INPUT lines per octave, allowing for the use of an optional 7th OUTPUT for the extra note.  This saved breaking into another INPUT, but I might regret this decision when it comes to coding it all up!

But fingers crossed this will all prove workable in software.

As with any attempt at keyboard matrix scanning, I’m still annoyed that I find it very easy to get confused about “ROWS” vs “COLS” and which should be INPUTS and OUTPUTS (and when) and throwing diodes into the mix and the option for a HC138 has added to the complications – as evidenced by the mistakes!  And I’ve no idea how I managed to hook up the EN pins the wrong way round… and must just have been really late when I was joining up Q0 to Q7…

This is definitely a candidate for a V2 board at some point though, but I’ll have to rethink if I really want to swap the ROWS/COLS to accommodate a 74HC138 or not.

These boards have been manufactured using the Seeed Fusion PCB service, which I am happy to continue to recommend. They have been supported with discount vouchers that I’ve been sent by Seeed for my previous projects.

Kevin

Leave a comment