Tuesday 13 September 2016

usb - Creating a keyboard with a microcontroller, do I need an input pin for each key?


I am planning to implement V-USB with an ATMega8 microcontroller. I am interested in implementing an HID device; more specifically, I want to try and make my own simple 26 key keyboard (each corresponding to a letter of the English alphabet).


This may be a stupid question, but do I need an input pin for each key I implement? In other words, will I need to use a microcontroller that has at least 26 I/O pins? Or is there another way to do this?



Answer



The idea to use a matrix is certainly the way to go. Your matrix could be organized in another way with eight input rows and four output lines for support of up to 32 switches. Since you only need to excite one input row at a time you could use a simple common 3-8 decoder to drive the input rows like shown below. This reduces the total microcontroller pin count to 7 lines!!


Note that with use of a 74HC138 type of 3-8 decoder it is necessary to flip the logic so that the output columns have pullup resistors, the diode direction is inverted and the software will see lows (0's) on the output lines where detected switches are seen.


Many thanks to tcrosley for borrowing some of his key matrix graphics and to Philips Semiconductors for the logic symbol image of their 74HC138 part.


enter image description here


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...