I would like to build an organ pedal board and use Raspberry Pi as signal processor.

The pedal board will have 32 inputs, one for each key.

I am planning to use magnetic sensors (like A3144), which, can send true / 1 or false / 0 signals to the Raspberry Pi (correct me if I am wrong, I never used this kind of sensor before).

What I don't know is how can I have 32 inputs, since the Raspberry Pi board has less than 32 I/O pins.

I have the impression I need another component for that (like a converter... or something), but again, I don't know what I need to build the electronic part of this project.

How can I connect more inputs to the Raspberry Pi? What would be the best way to build this?

The pedals should work simultaneously as well.

  • set it up as a keypad matrix ...... 8x4 will cover the 32 keys .... 6x6 would allow you to read 36 keys ...... both of these arrangements would require 12 data pins if no external circuitry was used – jsotola Apr 8 at 15:01
  • Yes, matrix keypad is the standard configuration. In my Arduino days I DIYed 16 key key pad using single keys connected as a matrix. Then I read MagPi about MCP23008 and found MCP's app notes on how to use MCP23008's two 4bit ports to make a 16 key key pad. That app notes is very good, and I followed the notes and made a keypad, using polling and interrupt. Of course a simple setup is to use 8 Rpi GPIO keys as a 4 x 4 matrix to handle 16 keys. Perhaps I can give an answer here recommending both methods. – tlfong01 Apr 12 at 7:51
  • @tlfong01 Can you please post an answer with more details? That would be great. Haven't started this project yet. – Ionică Bizău Apr 12 at 9:32
  • @Ionică Bizău - Yes, I can post a short answer, perhaps over the weekend. BTW, I have a midi keyboard, but I have not idea if the keys are capacitive or else. You might like to read the following about my keyboard and my answer which partly relates to your project - raspberrypi.stackexchange.com/questions/96083/… You might also read the following about mcp23008 based 4 x 4 keyboard design. This design can easily be scaled up using mcp23x17, to 16 x 16 = 256 keys. ww1.microchip.com/downloads/en/AppNotes/01081a.pdf – tlfong01 Apr 12 at 12:39

The best way depends on factors only you can determine.

I give a couple of ways.

  • use two MCP23017, each of which supply 16 digital IO. They use the I2C bus (pins 3/5, GPIO 2/3) and up to 8 can be used on the bus.
  • use 4 8-bit input shift registers. They provide 8 digital inputs each. They can use the SPI bus and you can daisy chain as many as you want. If needed you could instead bit bang reading the devices from any GPIO.

The shift registers are probably better for your application. They are likely to be more responsive as you can drive the SPI bus much faster than the I2C bus.

  • Thanks! I will look into that. I forgot to mention that the pedals should work simultaneously as well. Will that do it? – Ionică Bizău Apr 8 at 7:34
  • Also, could you recommend me some tutorials where to start? – Ionică Bizău Apr 8 at 7:35
  • Yes, that would be fine for either suggestion. – joan Apr 8 at 7:35
  • So, will 32 A3144 sensors connected to two MCP23017 chips connected to RPi do the job? Will that work? :) – Ionică Bizău Apr 8 at 8:04
  • I believe that will work. I'm just worried about the responsiveness. I would prototype both suggestions unless money is really tight. – joan Apr 8 at 8:11


How to make a Rpi compatible keypad, with more than 32 keys?

Short Answer

  1. 12 Rpi GPIO pins scanning a 8 x 4 matrix keypad (8 x 4 = 32 keys)
  2. MCP23x08 x 2 - 16 GPIO pins scanning two 4 x 4 keypads (4 x 4 x 2 = 32 keys)
  3. MCP23x17 x 2 - scanning 8 x 4 keypad (8 x 4 = 32 keys)

Step 1 - Start with a cheapy (US$1) 4 x 4 push button keypad, program 8 Rpi GPIO pins to scan keypad, using edge and level interrupts.

4 x 4 keypad

key matrix


Now that I have the schematic, I can start coding. But I only know python, and I heard that python is poor in keypad interrupt mode event driven programming, which node.js and javascript are best at.

I know very roughly the keypad scanning algorithm:

1. Connect GPIO 0, 1, 2, 3 to Row 0, 1, 2, 3
2  Connect GPIO 4, 5, 6, 7 to Col 4, 5, 6, 7
3. Set GPIO 0, 1, 2, 3 as Out 0, 1, 2, 3
4. Set GPIO 4, 5, 6, 7 as In  0, 1, 2, 3
5. Loop IN 0, 1, 2, 3 until any IN is low
6. ...

I am a bit tired. I guess I should let Johnny B take over, perhaps show us a node.js program, then a javascript, and I will follow him with python :)

Have a nice weekend.

Update 2019apr13hkt2130

Now I am thinking of how to test just one key switch SW R4 C4. The algorithm is roughly summarized below.

test switch SW R4C4

1. Set GPIO pin connected to Row 4, PinR4 as output
2. Set GPIO pin connected to Col 4, PinC4 as input
3. Write PinR4 Low. The line connected to PinR4, including point X, 
   will be pulled low
4. Polling (repeatedly reading) PinC4 will return High, until switch 
   SW R4C4 is pressed, Y is shorted to X, therefore the line connected 
   to PinC4 will now also be pulled Low, and PinC4 will read Low, indicating 
   that SW R4C4 is pressed.

Now I am studying the keypad. This is what I played in pre Rpi days, some 6 years ago.

4 x 4 keypad

Now I have setup and found where is the key H3 L3 and other keys, as shown below.

find key h3 l3 (R3, C3) and other keys

Prototyping Board for testing python GPIO input output

protopying board

/ to continue, ...

Long Answer

/ to add later, ...

Appendix A - Research Notes

/ to add later, ...

Appendix B - References

MCP23x08/mcp23x17 References

AN1081 Title: Interfacing a 4x4 Matrix Keypad with an 8-Bit GPIO Expander -04/12/2007 Mike Curran


This application note discusses interfacing a 4x4 matrix keypad 
with MCP23X08 8-Bit GPIO Expander. 

GPIO Expanders provide easy I/O expansion using standard serial 
interfaces such as I2C and SPI. They are especially useful in 
applications where pin count is limited on the microcontroller 
unit (MCU) or if remote inputs / outputs (I/O's) are needed.

MCP23008/MCP23S08 Data Sheet 03/28/2019 625KB

Errata MCP23008 Rev. A Silicon Errata 11/07/2005 146KB

AN1043 - Unique Features of the MCP23X08/17 GPIO Expanders 06/27/2006 297KB

AN972 Title: I/O Expansion Using the MCP23X08 and PIC10F202 01/31/2005 Pat Richards

MCP23008/MCP23S08 Evaluation Board User’s Guide


AliExpress 8pin 4x4 Matrix 16 Keys Button Keypad - US$0.58/pièce

How to ask a question

How to create a Minimal, Complete, and Verifiable example - StackOverflow

How to debug small programs - Eric Lippert's blog 2014mar05

How to ask technical questions to get quality answers - opensource.com

How to Ask a Question on Stack Overflow - WikiHow

Electronics Tutorials

Pull up and pull down resistors - Electronics Tutorials


Ted's Linux MIDI Guide

ALSA and MIDI Chapter 18. Sound in Linux

vkeybd — Virtual MIDI Keyboard

If you do not have an external MIDI keyboard connected to your sound card, use the virtual keyboard vkeybd.

kmid — The KDE MIDI Player

If the kdemultimedia is installed, find ‘Midi/Karaoke Player’ in the KDE start menu under ‘Multimedia’. Some demo files for kmid are available in .kar format in the directory /opt/kde2/share/apps/kmid. These files also contain the lyrics, which are scrolled and highlighted in sync with the playback.

ALSA USB MIDI keyboards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.