Hw to program [space] and [enter] etc on a matrix keypad

I designed and fabricated a miniature matrix keyboard pcb. It uses 5 rows and 12 columns and contains all the letters, numbers as well as [tab] [enter] [escape] [space] [up, left, down, right arrow] [backspace] and the ctrl, alt, and shift modifier keys (These are set up off the grid with their own individual pins and pullup resistors on the pcb).

I've tested out most of the lines in the matrix and it does work!

Some of the nodes in the matrix do not have keys so I also need to determine how to make them void in the keypad code set up.

But I've run into an issue: How to I program the non-numeric/alpha keys? "space bar" or "Enter" key, or "esc" key, etc...

Has anyone done this?

I am currently using the adafruit kaypad library, although I was trying to find the one by Mark Stanley, Alexander Brevig but for some reason it does not show up in the library manager. But for this, perhaps I'll have to use a different library entirely. Eventually I'll also have to program the modifier keys so I can get the extra characters and also add the F# keys.

My ultimate goal is to also program one of these to use as a keyboard for a raspberry pi zero 2w. the pcb has the same footprint and 2x20 header as the pi zero so it will make for a super cool little package. But this is an Arduino forum so I'm keeping my topic limited to just the Arduino code for now as this pcb has no internal IC's so it can be run with any controller.

A bit different than you are doing, but this should give you a hint.


//*****************************************************************************
//17 button Keypad
const byte buttonCode[18] = {
  0x46,0x44,0x40,
  0x43,0x15,0x00, //0X00 is not defined  <- - - - <<<<
  0x16,0x19,0x0D,
  0x0C,0x18,0x5E,
  0x08,0x1C,0x5A,
  0x42,0x52,0x4A
}; //END of buttonCode Array

const byte ASCIIcode[18] = {
  // ^    <   New line  
  0x5E,0x3C,0x0A,
  // >    v  nul      <- - - - <<<<
  0x3E,0x76,0x00,
  // 1    2    3 
  0x31,0x32,0x33,
  // 4    5    6 
  0x34,0x35,0x36,
  // 7    8    9 
  0x37,0x38,0x39,
  // *    0    # 
  0x2A,0x30,0x23
}; //END of ASCIIcode Array 

OR

const byte buttonCode[44] = {
  0x4,0x8,0xC,0x10,0x14,0x18,0x1C,0x50,0x54,0x58,0x5C, 
  0x5,0x9,0xD,0x11,0x15,0x19,0x1D,0x51,0x55,0x59,0x5D,
  0x6,0xA,0xE,0x12,0x16,0x1A,0x1E,0x4D,0x49,0x45,0x41,
  0x7,0xB,0xF,0x13,0x17,0x1B,0x1F,0x4C,0x48,0x44,0x40
}; //END of buttonCode Array

const byte ASCIIcode[44] = {
  // 1    2    3    4    5    6    7    8    9    0    -  
  0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x30,0x2D,
  // Q    W    E    R    T    Y    U    I    O    P    ^
  0x51,0x57,0x45,0x52,0x54,0x59,0x55,0x49,0x4F,0x50,0x5E,
  //Shift A    S    D    F    G    H    J    K    L    v
  0xFC,0x41,0x53,0x44,0x46,0x47,0x48,0x4A,0x4B,0x4C,0x76,
  // <    Z    X    C    V    B Space   N   M NewLine  >    
  0x3C,0x5A,0x58,0x43,0x56,0x42,0x20,0x4E,0x4D,0x0A,0x3E
}; //END of ASCIIcode Array 

image

image

post your code

A space is a x'20. what is the problem?

here is my code so far:

#include "Adafruit_Keypad.h"

const byte ROWS = 5; // rows
const byte COLS = 12; // columns
//define the symbols on the buttons of the keypads
char keys[ROWS][COLS] = {
  {'1','2','3','4','5','6','7','8','9','0','-','='},   
  {'q','w','e','r','t','y','u','i','o','p','[',']'},
  {'T','a','s','d','f','g','h','j','k','l',';','"'}, // the " should be a ' but the code wont accept that, T is for Tab
  {'V','z','x','c','v','b','n','m',',','.','/','U'}, // V is a void key
  {'C','V','V','V','S','L','D','R','D','N','|','B'},//the U,L,R,and D are placeholders for the arrow keys, C is for Escape, E is for Delete,N for enter,B for Backspace
};
byte rowPins[ROWS] = {9, 10, 11, 12, 13}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4, 5, 6, 7, 8, A0, A1, A2, A3, A4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Adafruit_Keypad customKeypad = Adafruit_Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  Serial.begin(9600);
  customKeypad.begin();

}

void loop() {
  // put your main code here, to run repeatedly:
  customKeypad.tick();

  while(customKeypad.available()){
    keypadEvent e = customKeypad.read();
    Serial.print((char)e.bit.KEY);
    if(e.bit.EVENT == KEY_JUST_PRESSED) Serial.println(" pressed");
    else if(e.bit.EVENT == KEY_JUST_RELEASED) Serial.println(" released");
  }

  delay(10);
}

for now, I have capital letters as placeholders for the various different keys like Enter, Space, etc...

@mooredesign13
You have 5x12 Keys in your Keyboard, and you have defined them all. Where are the places (row and column) to put your control keys (Enter, Up, Down, Right Arrow, etc.)? Do you want to add one more row or one more column to accomodate the extra keys?

Check my comments in the code adjacent the matrix. The capital letters are just placeholders for now for those special keys. I am guessing I'll have to convert all of this to hexadecimal ASCIIcode as suggested by Larry

Can you post the mapping of Capital Letter ----> Control Key? If you do so, you will be missing the Capital Letters.

That is just a placeholder for now. I have not mapped the capital letters yet. I needed to learn how to map the shift key first :wink:

Becasue, you have used all the 5x12 place holders. Now, you can use 7x12 matrix Keyboard to accomodate all the keys of Fig-1. You can use Keypad.h Libaray also.


Figure-1:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.