Question
How to make a Rpi compatible keypad, with more than 32 keys?
Short Answer
- 12 Rpi GPIO pins scanning a 8 x 4 matrix keypad (8 x 4 = 32 keys)
- MCP23x08 x 2 - 16 GPIO pins scanning two 4 x 4 keypads (4 x 4 x 2 = 32 keys)
- 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.
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.
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.
Now I have setup and found where is the key H3 L3 and other keys, as shown below.
Prototyping Board for testing python GPIO input output
/ 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
Description:
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
Keypad
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
ALSA
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