This Instructable covers creating a USB connected Human Interface Device Keyboard that has 10 button inputs which are mapped to key combinations in the firmware. Key combinations can be quickly accessed without using the keyboard which may be inconvenient to use. Such as with a MAME or similar machine where the keyboard may be stored or inaccessible or certain keys may be used frequently but aren't mapped to any of the arcade buttons.
Such as: Alt+F4 for Close Program, Windows+D to Show Desktop, Minimize Window, Maximize Window, Multiple Launch Program or Emulator, Alt+Ctrl+Del, Coin Buttons for players 1 and 2,
The custom hardware(circuit) is based on Microchip Solutions sample "USB Device HID Keyboard" firmware for the Low Pin Count USB Development Kit which uses a 18F14K50. The development kit is not required to recreate this as included here is a schematic, PCB layout and firmware to build one from scratch.
It does not require any external power supply, it draws from the USB host. All the keycodes are set in firmware and are for Windows based OS's, additional OSs could be used but the keycodes would have to be changed in the firmware.
If someone would like to send me key codes for a different OS, I will put together the firmware and post it to this Instructable.
Included in the ZIP below is PCB Layout, Schematic, diagrams, MPLAB project files, HEX file, readme, and the datasheet. Or you can view the HID Quickkey USB Adapter Datasheet or Visit the Website for Updates, Downloads and Details.
The Eagle files for the PCB can be found as a separate download.
DISCLAIMER: Recreate this project at your own risk. There is always risks when building your own electronics, be careful. Damage to the computers USB bus is possible, but not probable when everything is built correctly.
Step 1: Parts and Supplies
Complete Kits including the programmed PIC is available in The Store
Basic Kits including the programmed PIC, without buttons and wire are also available.
- PIC18F14K50 - DIP package, Buy One Programmed
- 2x 10k 5 bused resistors Like This
- USB Type B Socket
- 12 mhz Oscillator, series*
- 0.1uF disc Capacitor
- 220nF disc Capacitor
- 4 pin Header, such as Molex KK6410
- 4 pin Housing, such as Molex KK 6471
- 6 pin Header, such as Molex KK6410
- 6 pin Housing, such as Molex KK 6471
- Crimps, Molex KK 4809
- Wire, solid strand and stranded
- Printed Circuit Board or Perforated Proto board and solid strand wire
- 10 Normally Open Push buttons, board mount
- USB Type B to Type A cable(most devices such as printers use them) Buy One
*Normal crystal oscillator can be used, just add a 22pF capacitor from each OSC pin to ground.
- Soldering Iron
- Wire Strippers
- Diagonal Cutters
Step 2: Construct PCB
If Purchasing A PCB or Making one yourself, have it ready before beginning this step. Perforated board could also be used, then just follow the schematic.
The silkscreen PCB layout image included in the ZIP in Step 1 should be accessible for this Step, it shows the parts layout.
- Start with the 20-pin socket, the notch on the end marks the Pin 1 end. Carefully insert it, ensuring all pins line up.
- Resistor Buses are next, they each have 5 10k resistors in parallel within them with a common pin on one end, The common pin, which is marked with a dot on the SIP package should be lined up with the printed dot on the end of RN1 and RN2.
- Oscillator, ensure the solder joints are shiny and designing your own board, it should be as close to the MCU as possible.
- Capacitors C1 & C2: C1 is a 100nF disc cap for decoupling, C2 is a 220nF capacitor connected between the MCU's VBUS pin and V+.
- Resistor R1 pulls the Data+ line high, which signals to the Host what USB speed the Device runs at.
- USB Receptacle: It only goes in one way, Bend the mounting pins outward once it is in the board, solder all the contacts ensure their good joints. Make sure the solder doesn't bridge, as the contacts are quite close together.
- Headers: The polarized headers go in now, they can go in facing either way, there is a 4-pin and a 6-pin.
- PWR: Unused power header, leave it empty but solder over both pads. It is there in case more power than the bus can provide would be needed if the device was repurposed.
- Jumpers: Lastly the jumpers are installed, using these means that single sided copper circuit board can be used. Use some solid strand wire. And avoid other touching other parts, especially bare wire line on a capacitor.
- J1 is jumped to J2
- P1 is jumped to P2 which is jumped to P3. solder 2 wires into P2, then one wire each goes to P1 and P3.
- G1 and G2 are left open, explained in the next step.
- RX and TX are also left open and are not used, but are connected to the USART.
All the electronic parts except the PIC microcontroller and switches should be installed onto the circuit board. Look over everything carefully for jumps, bad solder joints, loose wires, or parts.
Step 3: Buttons
Buttons are connected as seen in the diagrams. The buttons are pulled-high by the device, bringing an input pin to ground will signal that the button has been pressed. And send the firmware assigned command from the device to the host computer.
Shown here is the layout I chose for my buttons, I am placing them under the monitor bezel. I am only using 9 buttons so I can have one centered.
Buttons are quite easy to wire up, some push button types have 4 and can be wired as normally open or normally closed, others have 2 leads. But either way normally open are required, so when the button is pressed it will connect the sw1-10 to ground, thus pressing the button.
- Mark the hole locations on the panel that the buttons will be mounted on.
- Measure the width of your push buttons and drill a hole a bit bigger than that measurement. Otherwise drill them smaller and use a small file to square the corners of the hole so the buttons will fit. Ones included in the kit should drill with a 3/8th bit or a tad smaller.
- Prep the medium used to mount the buttons, I am using perforated board to mount the buttons on, cut it to fit my hole spacing.
- Using the drilled holes as a guide mount the buttons onto the perfboard or other medium, checking the spacing.
- Once the buttons are mounted, they all will need to have one of their leads soldered in parallel with one lead from all the other buttons.(see image), this will be the ground rail,
- Connect a wire from all the buttons grounds to the a GND jumper hole on the PCB. Either one.
- Then connect the remaining lead from each of the buttons to its corresponding header on the PCB. If using crimps and housings which are supplied with the purchased kit, read This Tutorial for instructions on crimping. Or solder the wires from the buttons directly into the PCB.
- Once all the buttons are wired up they can be inserted into the panel with the holes drilled in it.
- Use some glue(hot works good) or some tape that doesn't stretch, to attach the perfboard, and hold the buttons in place.
- Finish attaching all perfboard with buttons.
- Once the buttons are in place, find a good spot for the PCB and mount it with some tape, glue or screws.
Decals: Now from the front there will be holes with the square buttons in them, looks ugly so it will need some decals. Once all the other graphics are completed of course. Included in the ZIP is some graphics I made for my button layout. I printed them onto vinyl graphic material, lamented, and contour cut them in a vinyl cutter.(Machine that cuts out shapes from sheet material)
---> Offering Reprints of my Graphics and Custom Graphics, any shape, size, image, Contact Us for Details <----
Step 4: Firmware
This device's design is based on the Low Pin Count Development Kit hardware from Microchip, Microchip Solutions has example programs for that development kit so it is quite easy to get them running on the device covered in this Instructable.
For the purposes of this project I used the USB Device - HID - Keyboard example for the Low Pin Count Development Kit. But there are various other devices that could be programmed onto this hardware/device, anything that could use 10 switch inputs.
Included in the ZIP on Step 1 is the MPLAB project files, you must install the latest version of MPLAB and the latest release of C18 compiler. Microchip Downloads Can Be Found Here
The included project files were taken and modified from Microchip's example code. They had wrote it in a way so it can run on multiple different PIC devices, so there is a lot of extra code not needed. The rest is mostly USB related code, the only function that was modified was the Keyboard() function.
ProcessIO() -> Keyboard() -> Check if IN endpoint is ready -> Check Switches ->Send Data -> ProcessIO()
The switches state are checked and compared to their previous state. if the states differ the switch is considered pressed and will fill a data buffer with/the required data then send it. Then continue checking the switches.
hid_report_in = is the modifier byte, it holds the state of the shift, alt, ctrl, gui(windows) keys
hid_report_in = 0; is reserved and always 0
hid_report_in thru  // Can be a keycode, up to 6 keys can be pressed and reported at once
See the "HID Usage Tables" pg. 52 for keycodes
Modifier key chart:
0 LEFT CTRL
1 LEFT SHIFT
2 LEFT ALT
3 LEFT GUI
4 RIGHT CTRL
5 RIGHT SHIFT
6 RIGHT ALT
7 RIGHT GUI
hid_report_in = 4; //alt
hid_report_in = 8; //L GUI
hid_report_in = 7; //ctrl+alt + shift
Some commands need a second key sent or key combo sent, by setting filling the data bytes NextModKey and NextKey then setting AnotherFlag flag in the firmware, after the primary command is sent it will send another report with those key values.
Such as Minimize Window which the Windows hotkey is Alt+Spacebar, then press n.
Step 5: Flash Microcontroller
Kits and PIC's Purchased Here, come programmed and ready to use. Just carefully plug it in, lining up the dot on the MCU with the notch in the 20-pin socket, ensuring all the pins line up, then press it in firmly.
If you have a blank PIC18F14K50 or want to be able to flash the firmware, there are 2 options.
- Program the chip in an external programmer and insert it into its socket, remove to reprogram if necessary.
- Or a ICSP header can be attached to the bottom of the PCB, using some wires to connect the proper solder pads to the PIC's ICSP headers, and use that to program and reprogram.
Check everything over well, a short could damage the Host Computers USB bus. All solder joints should be shiny.
Step 6: Usage
This device is a Human Interface Device which do not require any drivers or setting up. Its Plug and Play.
Once you are confident that the circuit is correct, its time to power it up.
For Windows OS users: (this part isn't necessary but it helps be sure it is working or not when its first ran)
- First open Device Manager
- Plug in the finished QuickKey Adapater
- In Windows the Device Manager will refresh itself after it detects the device
- Under Human Interface Devices "QuickKey v.1" will appear with a yellow exclamation mark, it will go away and refresh again after a second.
- Its name will get changed from QuickKey v.1 to USB Human Interface Device.
Assuming there is nothing now listed with a yellow exclamation mark, the device is working properly.
Button Codes:Pressing the buttons will signal the firmware to send a key or keys to the Computer. All 10 of the keys are set to send different key combinations, which the computer uses to run commands or actions. The key codes that are programmed in the supplied firmware are meant to be used with a Windows computer, and won't work on other OS's but the firmware can be modified with ones that would.
sw1 - Opens Task Manager - Alt + Ctrl + Del
sw2 - Close Open Program - Alt+F4
sw3 - Minimize All Windows(show desktop) - Windows Key + D
sw4 - Maximize Window - Alt + Spacebar -> X
sw5 - Minimize Window - Alt + Spacebar -> N
sw6 - Escape - Escape Key, exits most games
sw7 - Toggle Full Screen - Alt + Enter
sw8 - Open Program(Emulator Launcher Program) - Alt + Ctrl + Shift + L, set a windows Hotkey to a desktop shortcut
sw9 - Coin1 - Ctrl + 1
sw10 - Coin2 - Ctrl + 2
Step 7: Enjoy
Thank You for reading my Instructable, I hope it has been useful. If any of the information is wrong, please send me a PM I want fix it.
Check Out all of my other Instructables In My Profile or on my Main Website's Project Page
I have Kits for This and Many Other Projects In My Store, Take a Look and Maybe Show Some Support By Purchasing.
Participated in the