USB Keyboard to ASCII Converter
![]() Click to enlarge |
![]() |
USB Host Board - Keyboard Software
|
If you want to add a keyboard to your microcontroller project, you will know it's not a simple task. The easiest technical solution was to use an old-style PS/2 keyboard (if you can still find one) which has a serial interface, but you still have to decode all the keyboard scan codes into ascii on your microcontroller. This is a free software download for our USB Host Controller board Well, now you can simply and easilty add a modern USB keyboard to your project by using our USB Host controller board with the Keyboard application software loaded. We take care of the complex USB protocol and keyboard scancode decoding to give you an ascii serial output that you can read straight into your microcontroller. It converts key strokes into standard ASCII characters that are transmitted via serial TTL at selectable baud rates between 2400 and 115200. Works with Both wired and 2.4GHz wireless USB keyboards |
Click Here to Download (Version 1.07) |
All the standard keys are translated into ASCII characters including
- a-z and A-Z
- 0-9
- Backspace, Tab, Enter, Esc
- ! " £ $ % ^ & * ( ) - _ + = { } [ ] @ ' ~ # , . < > ? / \ | `
- Control-A to Control-Z
- Shift and Caps Lock work as they should generating the correct character
- Home, End, Ins, Del, Page Up, Page Down
- Arrow Keys
- Print Screen and the "Windows" key
- Function Keys F1 to F12
Function keys on the keyboard are translated into a two character combination with the first character being the ESC character (27 or 0x1B). The ASCII two character key combinations are shown in the table below.
|
Special 2-character key combinations First Character is Escape (27 [0x1B]) followed by... |
||||
| Key Pressed | ASCII Character | Key Pressed | ASCII Character | |
| F1 | 0x3B | INS | 0x52 | |
| F2 | 0x3C | DEL | 0x53 | |
| F3 | 0x3D | HOME | 0x47 | |
| F4 | 0x3E | END | 0x4F | |
| F5 | 0x3F | PAGE UP | 0x49 | |
| F6 | 0x40 | PAGE DOWN | 0x51 | |
| F7 | 0x41 | UP Arrow | 0x48 | |
| F8 | 0x42 | DOWN Arrow | 0x50 | |
| F9 | 0x43 | LEFT Arrow | 0x4B | |
| F10 | 0x44 | RIGHT Arrow | 0x4D | |
| F11 | 0x57 | WINDOWS | 0x5B | |
| F12 | 0x58 | Print Screen | 0x54 | |
Connections required for Keyboard Software
- 5V power in
- 0V
- TX out
- RX in (for setting baud rate only)
- SS pin goes high when Key pressed, low when released
Configuration
The USB Host board will generate ASCII characters at the following baud rates
- 2400
- 4800
- 9600 (default)
- 14400
- 19200
- 28800
- 57600
- 115200
The default baud rate is 9600
Configuration can be done by sending commands via the serial port. Either by microcontroller or via a terminal program and a suitable serial TTL connection. Commands take effect immediately and are stored in Flash ROM on the board.
The following Commands are available.
| BAUD <value> |
Set Serial Port Baud Rate [2400|4800|9600|14400|19200|38400|57600|115200] |
| KEYBOARD <value> |
Set Keyboard Country Code [0-USA|1-UK] |
| ESC <value> |
Set Escape Key Code 0 or 27 (default 27 - 0x1B) |
To upload the Software to the USB Host Board you will need to use the ds30Loader program. See the USB Host Board product page for more information on this.
Example use of the Keyboard Application
The following Arduino sketch prints out any characters received and decodes the function key codes into the name of the function key pressed.
/* USB HOST BOARD - Keyboard Program HOBBYTRONICS Ltd 2012 Simple Arduino sketch to show use of USB HOST board Keyboard software */ char flag_esc=0; void setup() { Serial.begin(9600); Serial.println("Type some characters and i will send them back"); } void loop() { if (Serial.available() > 0) { int inByte = Serial.read(); if(inByte == 27) { flag_esc = 1; } else { if(flag_esc==1) { // Previous char was ESC - Decode all the escaped keys switch(inByte) { case 0x49: Serial.print("[PgUp]"); break; case 0x51: Serial.print("[PgDn]"); break; case 0x47: Serial.print("[Home]"); break; case 0x4F: Serial.print("[End]"); break; case 0x52: Serial.print("[Ins]"); break; case 0x53: Serial.print("[Del]"); break; case 0x3B: Serial.print("[F1]"); break; case 0x3C: Serial.print("[F2]"); break; case 0x3D: Serial.print("[F3]"); break; case 0x3E: Serial.print("[F4]"); break; case 0x3F: Serial.print("[F5]"); break; case 0x40: Serial.print("[F6]"); break; case 0x41: Serial.print("[F7]"); break; case 0x42: Serial.print("[F8]"); break; case 0x43: Serial.print("[F9]"); break; case 0x44: Serial.print("[F10]"); break; case 0x57: Serial.print("[F11]"); break; case 0x58: Serial.print("[F12]"); break; case 0x48: Serial.print("[Up]"); break; case 0x50: Serial.print("[Down]"); break; case 0x4B: Serial.print("[Left]"); break; case 0x4D: Serial.print("[Right]"); break; case 0x54: Serial.print("[Print]"); break; case 0x5B: Serial.print("[Windows]"); break; default: Serial.print("[?]"); break; } flag_esc=0; } else { if(inByte==1) { Serial.print("Control-A"); } else if(inByte==2) { Serial.print("Control-B"); } else if(inByte==3) { Serial.print("Control-C"); } else if(inByte==4) { Serial.print("Control-D"); } else if(inByte==5) { Serial.print("Control-E"); } else if(inByte==6) { Serial.print("Control-F"); } else if(inByte==7) { Serial.print("Control-G"); } // Dont decode 8 - backspace else if(inByte==9) { Serial.print("Tab"); } // Dont decode 10 - Line Feed else if(inByte==11) { Serial.print("Control-K"); } else if(inByte==12) { Serial.print("Control-L"); } // Dont decode 13 - Carriage Return else if(inByte==14) { Serial.print("Control-N"); } else if(inByte==15) { Serial.print("Control-O"); } else if(inByte==16) { Serial.print("Control-P"); } else if(inByte==17) { Serial.print("Control-Q"); } else if(inByte==18) { Serial.print("Control-R"); } else if(inByte==19) { Serial.print("Control-S"); } else if(inByte==20) { Serial.print("Control-T"); } else if(inByte==21) { Serial.print("Control-U"); } else if(inByte==22) { Serial.print("Control-V"); } else if(inByte==23) { Serial.print("Control-W"); } else if(inByte==24) { Serial.print("Control-X"); } else if(inByte==25) { Serial.print("Control-Y"); } else if(inByte==26) { Serial.print("Control-Z"); } else { // Its a normal key Serial.write(inByte); } } } } }
Version History
1.07 28 Jan 2013 Added ability to change ESC key from 27 to 0
1.06 16 Jan 2013 Added key press indicator
SS pin goes high when key is pressed, low when released
1.05 07 Jan 2013 Added UK Country Keyboard option
Prints Pound sign and swaps " and @ keys over
1.04 24 Oct 2012 Fix for Eeprom Storage (V2 boards only)
1.03 23 Sep 2012 All Control codes (A-Z) now supported
1.02 13 Aug 2012 Increased Heap Memory as some keyboards caused failure
1.01 17 May 2012 Added Ctrl-Z
1.00 24 Jan 2012 Initial ReleaseYour Review: Note: HTML is not translated!
Rating: Bad Good
Enter the code in the box below:









Shopping Cart
DELIVERY/PAYMENT

Specials


Featured








Categories
Brands
Information




