Trybotics Logo

How to Make a Arduino HID Keyboard

DESCRIPTION

Controller by picklesandicecream

In this tutorial I shall explain how you can turn your Arduino chip into a HID keyboard device.

This is done by updating the Firmware on your chip with FLIP.

The cool thing about this trick is that you can make your own game controller or macro keyboard with the power of the Arduino coding method, so possibility are endless for great prototypes.

I have put all files into a Google Drive map for you to download.

link: https://drive.google.com/open?id=1jfOJmFf9C6QCb8I_...

I also have made a youtube Video for the coding part.

Supplies:

Arduino UNO or Mega

4 push buttons

4 resitors 1k ohm

Jumper cables

Description:

The basic setup of the Arduino for this example. (This can also be done with the Arduino Mega if more pin inputs are required) Note that we use the 3.3v of the Arduino as the input current of the push buttons onto the Digital-pins. The resistors used for this example are 1k ohm resistors.

Description:

Video link: https://www.youtube.com/watch?v=j05vj8zRP1o

Description:

First we initialize a keyboard buffer, this is required for the Arduino to send a bit register as a HID Keyboard.

Description:

Define the pins of the Arduino, you can also use (const int PIN_W = 4;) but I prefer the #define method.

Description:

Write the setup function, as with every Arduino code project the setup is pretty much the same except that setting the Baud rate and serial communication with the (Serial.begin(9600)) function is required for the Arduino to communicate with your computer.

Description:

Write an end buffer method to send a bit when button is released, this step is required to end the data stream of the HID keyboard. For this example we send the key code through buf[2] so we need to reset them to 0 when the button on the Arduino is released. Note: Without this step you’re HID keyboard can start sending button inputs but it will never stop sending bits until the HID keyboard (Arduino) USB is unplugged.

Description:

This step is done in the Loop() function to be updated every cycle the Arduino get through checking if a button is pressed.

Description:

uint8_t buf[8] = { 0 }; //Keyboard report buffer

#define PIN_W 4 // Pin for w

#define PIN_A 5 // Pin for a

#define PIN_S 6 // Pin for s

#define PIN_D 7 // Pin for d

void setup() {

Serial.begin(9600); // Setup Serial communication

//Set pinmode of Input pins

pinMode(PIN_W, INPUT);

pinMode(PIN_A, INPUT);

pinMode(PIN_S, INPUT);

pinMode(PIN_D, INPUT);

}

void loop() {

//When button representing W is pressed

if (digitalRead(PIN_W) == HIGH) {

buf[2] = 26; // W keycode

Serial.write(buf, 8); // Send keypress

releaseKey();

}

//When button representing A is pressed

if (digitalRead(PIN_A) == HIGH) { buf[2] = 4; // A keycode

Serial.write(buf, 8); // Send keypress

releaseKey();

}

//When button representing S is pressed

if (digitalRead(PIN_S) == HIGH) { buf[2] = 22; // S keycode

Serial.write(buf, 8); // Send keypress

releaseKey();

}

//When button representing D is pressed

if (digitalRead(PIN_D) == HIGH) { buf[2] = 7; // D keycode

Serial.write(buf, 8); // Send keypress

releaseKey();

}

}

// Function for Key Release

void releaseKey() {

buf[0] = 0;

buf[2] = 0;

Serial.write(buf, 8); // Send Release key

}

Description:

To install FLIP please install JRE - Flip Installer - 3.4.7.112.exe provided in the Google Drive link

Note: When starting up you get the error "AtLibUsbDfu.dll not found" you have to install a driver.

Here is a solution made by MDGrein link: https://www.youtube.com/watch?v=KQ9BjKjGnIc

Description:

Press the Highlighted chip button, then Select ATmega16u2 and then the button OK. As this is the chipset for the Arduino Uno R3 and the Arduino Mega R3.

And now you are done with setting up flip and we can go to the Next step of Flashing the Arduino.

Description:

You will get a message at the bottom from the Arduino IDE saying done Uploading

Note: if uploading fails
Check 1 COM port under Tools>port if none is available unplug and replug USB or check device manager. Check 2 if you have the correct board selected in Tools>board.

Description:

short the 2 ICSP2 pins as shown in the image

To put the Arduino in the DFU (Device Firmware Update) mode, so that FLIP can access the Firmware

on the Arduino Chip. More info on this reference link: https://www.arduino.cc/en/Hacking/DFUProgramming8...

Description:

Description:

Load the arduino-keyboard.hex into FLIP

You will see at the bottom USB ON, this is that the Arduino is connected through DFU Mode.

Description:

Description:

You will see this all in green if not close FLIP and return to step 12 Arduino into DFU mode.

Description:

From now on the Arduino is a HID Keyboard Congratulations!

The only thing now is that the Arduino IDE does not support your Arduino anymore. So to check if your HID keyboard works we open Notepad, or any other text editor.

Description:

You can do that by repeating the steps after Step 12 Arduino into DFU mode,

only then chose Arduino-usbserial-uno.hex instead of arduino-keyboard.hex


YOU MIGHT ALSO LIKE