DIY Programmable Keypads

2016-07-09 16.49.25-1.jpg

In my last post I mentioned off the shelf options for creating custom button options but there is a fairly easy way to do it yourself using an Arduino. To make this work you need and Arduino Leonardo/ Pro Micro because they are able to emulate a HID keyboard device. Luckily they can be found pretty easily and cheaply. Knock off Pro Micro's/ Leonardos can be found all over eBay and Amazon. On my own version I began using cheap arcade buttons which adds gaming fun element when using you keypad. The one downside I've found in this project is that you need to have the Arduino IDE installed on computer you wish to use your keypad with.

My first attempt was a two button module that I could use as a "Go" and "Back button for ETC's Nomad software. After using it for a while I began to think of using it for other things such as a screen switcher for Windows 10 that I can attach below my monitor to control the new desktop features. Luckily its fairly straightforward to add more buttons as needed for a given project on both the hardware side.

 

Hardware

Here is a diagram of the hardware side that can be expanded to as many buttons as needed:

 

Each digital pin as set high and pulled to ground when activated.

My suggested hardware list is:

Arduino Pro Micro

Arcade Buttons

Software

The coding end is also fairly straight forward. Here is my example for the "Go" button:

#include "Keyboard.h"


const int buttonA = 2;
const int buttonB = 3;


void setup() 
{
  pinMode(buttonA, INPUT);
  pinMode(buttonB, INPUT);
  digitalWrite(buttonA, HIGH);
  digitalWrite(buttonB, HIGH);
  Keyboard.begin();
}

void loop() 
{
  int b_A = digitalRead(buttonA);
  int b_B = digitalRead(buttonB);

  if(b_A == LOW)// Green Go Button (Control G)
  {
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press('g');
    delay(100);
    Keyboard.releaseAll();
  }

  if(b_B == LOW) //Red Stop/ Back Button (Control F3)
  {
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press(KEY_F3);
    delay(100);
    Keyboard.releaseAll();
  }
}

To add more buttons replicate the code for the first two.

Keys are added with the Keyboard.press('x') command the desired key going inside the brackets with single quotation marks, here is the full explanation.

If you want to use any special keys (Control, Alt) here is a link to the Arduino reference on keyboard modifiers.

Inserting a delay helps to ensure that everything has to to execute properly and can be tweaked as needed.

Finally remember to use the Keyboard.releaseAll() command otherwise repeating key problems with occur.