1
\$\begingroup\$

Introduction

I'm asking for help to validate following schema. I'm a nob in electronics, this project is not a professional project, just for fun. Please, be kind to me. Thanks.

My Goal

I would like to connect a piano toy keyboard to Arduino to get MIDI notes through USB connector.

Details

The keyboard has a matrix layout like this:

enter image description here

Example 1: When power flow is set to P23, if pushbutton 1 is pressed, the power flow arrives to P30. If, also pushbutton 9 is pressed, power flow, also, arrives to P31. Please check "On/off switches board pinout labels" for piano keyboard details.

Notice that I only can to send +5v from one pin (from P10 to P23) at a time. On Example 1, If flow is sent from all the pins at a time, we can't know witch pushbutton from 1 to 8 was pressed.

What I have thought

Because the keyboard has a lot of pins I guess I need to use a multiplexer. One multiplexer for 5V output (only output one pin at a time).

This is the schema I have in my mind:

enter image description here

For me, looks like a solution, to connect P30, P31, ... P40 to Arduino digital inputs and multiplexing with +5v one pin at a time from P10 to P23 using the multiplexer module.

Materials

This is what a have:

Question

I would like to know if my solution is right, or they are a more clever/elegant solution.

Disclaimer

I'm not an electronic hacker guy, I'm looking for a project I can do with my daughter and have a bit of fun. Please, be kind. This is not a module for a nuclear power plant, just a summer side project. Any help is welcome. Also, sorry about my poor English, if some part is confused, please, let me know to try to write a proper explanation.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ You should have enough pins without a multiplexor (you can use the "analog" ones digitally, too). However beware that your keyboard matrix is not correctly designed for detecting arbitrary key combinations as it lacks diodes. \$\endgroup\$ – Chris Stratton Aug 12 '20 at 14:25
  • \$\begingroup\$ I think your multiplexing scheme is fatally flawed. Any two keys on the same column that are active will cause a logic-high-to-logic-low shortcircuit. @ChrisStratton suggests that diodes might fix this flaw. I agree. It is possible to avoid diodes by employing tri-state row drivers. Microcontroller pins could drive rows directly, scanning one row at a time with a logic-high...the 7 other rows would be tri-stated to high-impedance so keys on those rows have no influence on the one active row. \$\endgroup\$ – glen_geek Aug 12 '20 at 14:58
  • \$\begingroup\$ The short circuit problem is easily solved, eg using pulling resistors. But certain combinations of keys will cause others to be falsely detected as well \$\endgroup\$ – Chris Stratton Aug 12 '20 at 15:50
1
\$\begingroup\$

The Arduino you show in the picture has more than enough pins to scan a 5x8 matrix of buttons without a separate multiplexer.

The Arduino also can enable internal pull-up resistors on input pins, so you don't need external resistors either.

So simply set rows (or columns, depending on which way you want to do it) as inputs with internal pull-up, and the columns (or rows) as outputs, and the one output that is scanned is set to 0V, and all the other outputs are set to 5V.

Edit: Actually, the one active output should be set to 0V, and the other outputs should idle at high-impedance mode to simulate open-collector output, so that pushing multiple buttons does not short the outputs. This could be avoided by putting diodes to outputs if necessary.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks about your answer. I know for you is simple, but I don't understand at all, sorry. How can I "enable interall pull-up resistors on inputs pins"? Why you say "the output that is scanned"? I should to scanner the inputs and not the outputs, it isn't? Also, Why one to 0V and all others to 5V? Isn't it the other way around (one to 5V and others to 0V? Sorry about all this questions to your answer.I know I'm a nob. \$\endgroup\$ – danihp Aug 12 '20 at 14:59
  • \$\begingroup\$ The Arduino includes a button matrix scanning library, so you actually don't need to know anything about how it is actually done and why. If you do want to know, it is your code that needs to set the outputs one at a time to non-idle state and read the inputs. It is up to you if you want to do it the "one output high" or "one output low" way, I just said the most elegant way where you don't need any external components, because the Arduino contains internal pull-up resistors but not pull-down resistors so the scanning needs to be "one output low and others 5V" way. \$\endgroup\$ – Justme Aug 12 '20 at 15:22
0
\$\begingroup\$

You could also use shift registers instead of multiplexers. A shift register can take many inputs like a multiplexer but it outputs a serial stream of data. Shift registers can also be daisy-chained together to get as many inputs as you need. The advantage to using a shift register instead of a multiplexer is that you only need one input pin to your micro-controller for data and it allows you to have many inputs active at the same time. However, note that a shift register stores input data and sends output data when triggered by clock signals which is different than a multiplexer. Input to the shift register is stored when it receives a "write" clock pulse and it outputs the stored data on a "read" clock pulse. It also requires you to de-serialize the data stream in the micro-controller.

\$\endgroup\$
0
\$\begingroup\$

schematic

simulate this circuit – Schematic created using CircuitLab


If a one-of-8 logic MUX is used to scan the keyboard, where only one line of eight is set to logic high (while all other seven output lines are low), then diodes are needed on scanning outputs. Keyboard switches at matrix junctions are not shown on the schematic above.

With enough general-purpose-input-output (GPIO) microcontroller pins, the 5x8 matrix can be scanned, needing neither MUX nor diodes. You would need 13 GPIO pins for a simple scanner.

\$\endgroup\$
0

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.