0
\$\begingroup\$

I think that this is a design question because I need to know what type of chip to use first, and then I'll go shopping on my own for which one to use.

I need to understand how to add at least 90 digital I/O pins to a microcontroller (or to find a microcontroller with that many pins) for a keyboard I'm designing and making, however, I don't know how to find microcontrollers, or even if they have what I need. I would also like the microcontroller to be able to be used with the Arduino IDE (if that's possible).

I need so many pins because I decided I didn't want to do a matrix because of the need for diodes. The microcontroller would be hand-soldered to a PCB if that helps in finding the right package type. I'm still pretty new to electronics, and PCB design, so dumbing things down would be appreciated. If you want me to, I can provide the schematic, and the pcb-layout, but they currently only have all of the switches.

Added:

I meant a keyboard for typing on a computer, not a musical keyboard. Sorry I didn't specify. I don't know how fast I want the key state to update, so whatever is typical for the average keyboard is fine.

\$\endgroup\$
10
  • 1
    \$\begingroup\$ You're going to put a LQFP144 or BGA STM32 when a LQFP48 would suffice? Also, this is not the place for buying recommendations. \$\endgroup\$
    – Jeroen3
    Commented Sep 2, 2021 at 19:33
  • 2
    \$\begingroup\$ The IC makers usually have selection charts showing the capabilities of their products. Anything with 90 I/O pins will be in a hand-soldering-unfriendly package. \$\endgroup\$ Commented Sep 2, 2021 at 19:44
  • 2
    \$\begingroup\$ You don't need 90 IO pins to an MCU. Even if you did use a matrix, you don't have to use diodes, but it helps. There are also other ways reading 90 buttons than a matrix or 90 IO pins, but in the end, the matrix with diodes may just be the cheapest solution. \$\endgroup\$
    – Justme
    Commented Sep 2, 2021 at 19:47
  • 1
    \$\begingroup\$ Welcome to the site. Are you building a key to play P2P? :-) You will need 90 GPIO (input), since you do not want to "SCAN" the key matrix. But, it is not necessary to have that 90 counts right on the CPU. Look for various "GPIO Expander" and find microprocessor with right "Interface" to use multiple of that device. \$\endgroup\$
    – jay
    Commented Sep 2, 2021 at 20:02
  • 5
    \$\begingroup\$ Another bad close, voting to reopen. Karl, you got caught in the 'product recommendation is off-topic' trap when what you're really asking is a system design question. The closer-voters... think outside the box a bit. k? New user and all that. \$\endgroup\$ Commented Sep 2, 2021 at 20:18

2 Answers 2

1
\$\begingroup\$

I will assume you're making a music keyboard which typically has 88 keys, yes?

How often do you need to update the key state? What latency are you willing to tolerate? You could use I2C expanders for example, if you can tolerate a bit of latency. Six 16-bit ones would do the job and you'd have independent GPIOs for each key, so no rollover issues. These devices provide an interrupt on change-of-state to improve response latency, so you could get the key state in less than a millisecond from key press or release.

So your host needs one I2C port and 6 GPIO's to monitor the change-of-state interrupts. That's doable with an Arduino (ATMega328) or similar. 16-bit I2C I/O expanders are available from a number of vendors, including TI, Microchip, On Semi, NXP and others.

\$\endgroup\$
9
  • \$\begingroup\$ I don't think that any of manufactured keyboard uses an I2C expander. \$\endgroup\$ Commented Sep 2, 2021 at 20:04
  • \$\begingroup\$ They wouldn't owing to the additional cost. The issue here is that, assuming a musical keyboard, a scanning approach doesn't work so well due to rollover and response latency. Musicians are surprisingly sensitive to this kind of stuff. Also, OP wants Arduino, so that constrains the problem as far as I/O is concerned. \$\endgroup\$ Commented Sep 2, 2021 at 20:08
  • \$\begingroup\$ @hacktastical Assuming a musical keyboard, I have only encountered ones with a scanned matrix. Instead, if some generic 74HC164 or similar chips are used, it might be simpler and faster even if used with same clock rate than for I2C. Many of those I2C chips also have buggy interrupt reporting. Comparing the options, I don't think I2C would be the first choice, but it is possible though. \$\endgroup\$
    – Justme
    Commented Sep 2, 2021 at 20:28
  • \$\begingroup\$ With a PISO shift reg you don't get a change-of-state indication, so the response to the keypress has more time variation. At least with the interrupt the response is short, and somewhat consistent (the latter being most important for music.) That said, there's SPI I/O expanders with interrupt too. \$\endgroup\$ Commented Sep 2, 2021 at 20:32
  • 1
    \$\begingroup\$ @hacktastical At 400 kHz you can scan 88 keys in 220us with a PISO, or 4500 times per second. You can't even send one MIDI byte in that time, and transmitting one USB MIDI packet would likely have more variable timing too. And it would not be a problem to organize the pins so that it is possible to read 11 8-bit PISO registers at a time so even a 400 kHz clock can read each button every 22us. \$\endgroup\$
    – Justme
    Commented Sep 2, 2021 at 21:16
0
\$\begingroup\$

You have multiple options:

  • Big microcontroller with lots of I/O pins
  • Matrix with diodes
  • Matrix without diodes - suffers from ghosting
  • I/O expanders - chips that have a bunch of I/O pins on them, and then your microcontroller talks to these chips using some kind of serial protocol with less pins, and ask them which inputs are active.
    (anything that allows a microcontroller to use more pins may be called an I/O expander)
  • Parallel-in/serial-out shift register chips (e.g. 74HC165) - dumber distant relative of an I/O expander, may be cheaper and/or easier to get, and simpler. And they can be chained together to make an infinite number of inputs.
  • DIY I/O expanders - you can have more than one microcontroller! And connect them together and make it so each "slave" microcontroller watches some of the keys, and sends a signal to a "master" microcontroller when a key is pressed.

You get to choose one - they're all valid! My preference would probably be the shift register approach, but that's just my preference. I did not research the cost; it may end up being cheaper to get a big microcontroller, but if you are only making one as a DIY project then it does not matter too much. It is worth noting that 74xxxxx chips come in DIP packages, and big microcontrollers do not.

Most approaches involve some kind of scanning. If the microcontroller can't access all the pins at once then it has to check one pin, then the next, then the next, then the next, then the next.... e.g. with an I/O expander, you would have to send the first chip a command to say "which pins are turned on?" and then it will tell you, and then you send the same command to the second chip and it will tell you, and then to the third chip and it will tell you, etc. As long as you scan often enough it is not noticeable to humans. For a computer keyboard, even if the scan cycle takes a few milliseconds, that should be no big deal, unless you're an expert at fast-paced shooter games. Of course you want it to be as low as possible but it doesn't have to be zero.

\$\endgroup\$
5
  • \$\begingroup\$ This is only a one time DIY project and I think I'm wanting to just do one big microcontroller. I don't really want to do an expander or matrix just because I'm wanting to keep things simple. However, I don't really know where to look for microcontrollers in general. Are there any websites or specific chips you recommend? I'm also hoping that it can be soldered by hand but if it isn't possible, I'll work something out. Sorry I'm responding late, got caught up with other stuff. \$\endgroup\$
    – Karl
    Commented Oct 14, 2021 at 2:40
  • \$\begingroup\$ @Karl No specific recommendations. You can look at a shopping site like digikey and sort by number of I/O pins, only DIP packages (the ones that are good for DIY prototypes), etc. However, DIP packages with 90 pins don't exist. It will be a QFP or BGA package. You have no chance at all of soldering a BGA (you can reflow it), but QFP is possible with a custom circuit board and "drag soldering". \$\endgroup\$ Commented Oct 14, 2021 at 12:40
  • \$\begingroup\$ @Karl here is a digikey search which may help but be aware that you do need to investigate each option and find if it's suitable for you. The search tool isn't the end-all be-all of choosing a chip. For example, many/most/all(!) of them probably need specific programming tools and software, not just a USB cable and the Arduino IDE. \$\endgroup\$ Commented Oct 14, 2021 at 12:41
  • \$\begingroup\$ digikey.de/products/en/integrated-circuits-ics/… \$\endgroup\$ Commented Oct 14, 2021 at 12:41
  • \$\begingroup\$ @Karl the Arduino IDE is only designed for the specific products which are designed for it and I don't think any of them have 100 pins. I really recommend using the shift register idea or the matrix idea. You can get 74HC165s in the easily solderable/breadboardable DIP packages. And the matrix idea requires no extra chips. Programming these ideas is not as scary as you seem to think. \$\endgroup\$ Commented Oct 14, 2021 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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