DIY

64-key matrix keyboard for working with Arduino

64-key matrix keyboard for work with Arduino A DIY master is working on a project that will have a built-in keyboard and there is a problem here : how to include keyboard in development board prototype? You cannot use a USB keyboard or an existing Arduino based keyboard in a project, because the keyboard in a real project is connected directly to a microcontroller that handles all other functions. To solve the problem, the master developed a 64-key keyboard matrix for PCB prototyping.
This PCB does not contain any ICs. The rows and columns of the keyboard matrix connect directly to the pin headers, so the keyboard can be connected to an Arduino or any other microcontroller.
Wizard has included detailed code with comments. The keyboard has 64 keys, including modifiers for shift, caps, ctrl, alt, fn, and “special”. There are also six extra keys that you can use for just about anything. The functions of each individual key can be defined individually.
Tools and materials: -Tactile instant button 6x6x5 mm – 64 pcs; -Diode 1N4148 – 64 pcs; -Pin connector; -Circuit 74HC595; -Jumpers; -Breadboard; -Arduino Uno;
Step one: the principle of the matrix keyboard
This keyboard has 64 keys. If we were to connect each of these buttons directly to the development board, we would need 64 I/O pins. That's a lot of pins and more than what is available on most boards. To reduce the number of connectors to a reasonable number, a keyboard matrix can be used, which requires only the number of pins equal to the square root (rounded up) of the keys.
The keyboard matrix is ​​configured such that every key switch in a row is connected and every key switch in a column is connected. When we want to see which keys are pressed, we “activate” the first row and then check each column. If a specific column is active, we know that a key was pressed on that column and row 1. Then we deactivate row 1 and activate row 2, then check all the columns again. After all the lines have been activated, we simply start over from the first row.
Since the device is working with a microcontroller, “activate” means setting this line to LOW or HIGH. In this case, we set the row to LOW because we are using the built-in pull-up resistors of the microcontroller on the input pins of the columns. Without the pull-up resistor, the pin will respond unpredictably and false button presses will be recorded.
All rows are also typically set to HIGH, which prevents the column pins from being connected to the row pins whether the button is pressed or not.
The diodes in the circuit are designed to prevent unintentional key presses while holding down certain button combinations. The diodes only pass current in one direction, which prevents double-clicking. If diodes were not used, then pressing certain keys could trigger another unpressed key, since current would be conducted through adjacent switches.
The keyboard matrix requires the number of contacts equal to the square root of the number of keys, but in this keyboard design there are only 11 contacts (and there should be 16). There are 11 pins because the design uses a 74HC595 shift register. This register allows only three Arduino I/O pins to be used to control up to 8 output pins. These three pins allow a byte (eight bits) to be sent to the shift register, which sets its eight output pins to HIGH or LOW. By using the shift register for the output line pins, we save 5 full I/O pins.
You can use the shift register for the input pins, but here you need a different type of register. The master did not have such a detail. In addition, using a shift register for input also makes the columns harder to read and can cause key bouncing issues.
schematic.pdf
64-key matrix keyboard for work with Arduino  64-key matrix keyboard for working with Arduino Step two: PCB design
Now that you have an understanding of how the keyboard works, the wizard designs the PCB in KiCAD. He just put in a button symbol and a diode symbol, then copied and pasted them until he got a grid of 64 keys. Then I added two 1×8 slot symbols, one for rows and one for columns. One side of the buttons was connected in columns and the other side of the buttons was connected in rows.
The next step was to assign PCB footprints to each of these schematic symbols. The library of schematic symbols/footprints included with KiCAD has the necessary built-in symbols.
Pay special attention to the pin numbers. KiCAD has a problem where the pin numbers of the diode symbol do not match the pin numbers of the footprint. This causes the diodes to be in reverse order, which is a serious problem considering their polarity. To solve this problem, the master had to create a special landing site for a diode with mirrored contact points.
After creating the schematic and assigning symbols, the wizard moved on to the PCB layout. The board outline was created in Autodesk Fusion 360, exported as DXF and then imported into KiCAD on the Edge Cuts layer. Much of the work after that was simply arranging the buttons so that their layout would look like a regular keyboard.
Once the board was created, the wizard simply drew all the layers and added them to the zip folder. You can download the file for making the board here.
64-key matrix keyboard for work with Arduino  64-key matrix keyboard for working with Arduino 64-key matrix keyboard for work with Arduino Step Three: Building
After making the boards, the master proceeds to the installation. You just need to solder all the components into place. All components are through hole and soldering is uncomplicated. Pay particular attention to the orientation of the diodes. The mark on the diodes must match the mark on the printed circuit board.
64-key matrix keyboard for working with Arduino Step four : connecting the keyboard to the Arduino
The connection looks complicated, but it's actually quite simple.
Eight jumpers go from the column pin directly to the following Arduino pins:
Column 1 & gt; A0
Column 2 & gt; A1
Column 3 & gt; A2
Column 4 & gt; A3
Column 5 & gt; A4
Column 6 & gt; A5
Column 7 & gt; 5
Column 8 & gt; 6
Then we install the 74HC595 shift register on the breadboard. The dot indicates pin 1. The shift register has two pins connected to 5V and two pins connected to ground.
Only three wires are needed to connect the shift register to the Arduino:
Shift (Clock) 11 & gt; 4
Shift (Latch) 12 & gt; 3
Shift (Data) 14 & gt; 2
For some silly reason, the shift register output pins are illogical. Pay special attention to the shift register pinouts when connecting them to the pins.
Row 1 & gt; Shift (Q0) 15
Row 2 & gt; Shift (Q1) 1
Row 3 & gt; Shift (Q2) 2
Row 4 & gt; Shift (Q3) 3
Row 5 & gt; Shift (Q4) 4
Row 6 & gt; Shift (Q5) 5
Shift 7 & gt; Shift (Q6) 6
Shift 8 & gt; Shift (Q7) 7
Nothing is connected to Arduino pins 0 and 1. These pins are used for the serial port and cause conflicts.
64-key matrix keyboard for working with Arduino 64-key matrix keyboard for working with Arduino 64-key matrix keyboard for working with Arduino Step five: firmware
The article contains two codes. The first is old, the second is modified taking into account the shortcomings. The prologue works for both codes.
Everything in the code has detailed comments. Basically, contacts are configured as inputs and outputs. The main loop just contains a timer function. Every 5ms it calls the keyboard scan function. This function calls a separate function to set the shift register before checking each column. The pressed keys display their value in Serial.
If you want to change what is printed when a key is pressed, just change Serial.print (“_”); in the if statement that matches the condition. For example, you can set what will be printed when you hold FN and press N. The same is true for any other key with each modifier.
Many keys do nothing at all in this code, because it just prints to Serial … This means that the Backspace key has no effect because you cannot delete from the serial monitor – this data has already been received. However, you can change this if you like.
This keyboard is designed for prototyping more complex projects. This is why it is easy to change its functionality. If, for example, you want to print typed text on an OLED screen, you can simply replace each Serial.print (with display.print (or whatever is required for your particular display). The Replace All tool in the Arduino IDE is great for replacing all these values ​​in one quick step.
The new code has been completely rewritten and works better than the original code. This was mainly done to solve a problem with an algorithm that did not allow characters to be entered each time a key was pressed. The source code checked that a particular key was not pressed last. This caused a problem if 2 or more keys were held down, resulting in something like “fgfgfgfgfgfgfgfgfgfg” being entered. It also prevented you from typing the same key over and over again very quickly, for example, when you type two letters m in the word “bummer.”.
The new code solves both of these problems. Instead of keeping track of the last key pressed, the device checks the state of the entire keyboard and compares it to the entire state of the keyboard in the last cycle. This means that the loop can run much faster, and you can enter the same key over and over again very quickly. Performance has been greatly improved. All symbols are also in the arrays at the top, so you can easily find and change them. There are independent arrays for each modifier. The code is also much shorter.
The only downside to this new code is that it uses more heap, although it uses significantly less program space. The Arduino Uno now uses 3532 bytes (10%) of program storage and 605 bytes (29%) of heap.
As an added bonus, this code also works well on fast microcontrollers like the ARM Cortex-M4. The interval timer for keyboard testing is in microseconds, so it will work the same on any board. You can also easily adjust the frequency of the keyboard check. By default, it starts one cycle every 500 microseconds. It takes 8 cycles to test the keyboard for a total of 4000 microseconds (4 milliseconds or 250 times per second).
ProtoKeyboardV1.1-Shifted.ino (old code) ProtoKeyboardV1-Bits.ino (new code)
64-key matrix keyboard for work with Arduino

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button