USB Host - Keyboard to ASCII Converter

HobbyTronics USB Host - Keyboard to ASCII Converter
Cliquer pour agrandir
Fabricant : HobbyTronics
Évaluation : 5 sur 5 Étoiles !


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 Board and USB Host IC's (SOIC, DIP, SSOP).
To order, simply select which of our boards or IC products you wish to have the software loaded onto. See the USB Host Board and IC product pages for details on pricing and installing this software.

Download Software
Click Here to Download (Version 1.40)
USB Host BoardUSB Host Mini
USB Host Boards
USB Host IC's

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.

Note: Apple Macintosh keyboards have a built-in USB Hub and will not work with our boards of firmware.

Note: This software also works with USB Barcode Readers

It converts key strokes into standard ASCII characters that are transmitted via serial TTL at selectable baud rates between 2400 and 115200.

As of version 1.15 there is now basic functionality to read the key presses via I2C as well as serial

Works with Both wired and 2.4GHz wireless USB keyboards

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
  • Alt-A to Alt-Z
  • Alt-F1 to Alt-F12
  • 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


Other Keyboard Codes

The CONTROL and ALT codes are detailed here

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


The USB Host board will generate ASCII characters at the following baud rates

  • 2400
  • 4800
  • 9600 (default)
  • 14400
  • 19200
  • 31250
  • 38400
  • 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.

Help can be displayed at any time by typing ? or HELP

The following Commands are available.

BAUD <value> Set Serial Port Baud Rate (default 9600)
I2C <value> Set I2C Address
1 to 127 (default 41)
KEYBOARD <value> Set Keyboard Country Code
ESC <value> Set Escape Key Code
0 or 27 (default 27 - 0x1B)
MODE <value> Set Modification Mode
0 - default behaviour
1 - Customer mod
2 - Customer mod
3 - Customer mod
4 - ESC key produces two ESC chars
5 - Customer mod
6 - Outputs raw HID data - useful for debugging
HELP or ? Display Help Screen


Program Updates

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 using the serial connection and decodes the function key codes into the name of the function key pressed.

  USB HOST BOARD - Keyboard Program
  Simple Arduino sketch to show use of USB HOST board Keyboard software
char flag_esc=0;

void setup() {
  Serial.println("Type some characters and i will send them back");

void loop() {

  if (Serial.available() > 0) {
    int inByte =;  
    if(inByte == 27)
       flag_esc = 1;
        // Previous char was ESC - Decode all the escaped keys
            case 0x49:
            case 0x51:
            case 0x47:
            case 0x4F:
            case 0x52:
            case 0x53:
            case 0x3B:
            case 0x3C:
            case 0x3D:
            case 0x3E:
            case 0x3F:
            case 0x40:
            case 0x41:
            case 0x42:
            case 0x43:
            case 0x44:
            case 0x57:
            case 0x58:
            case 0x48:
            case 0x50:
            case 0x4B:
            case 0x4D:
            case 0x54:
            case 0x5B:

        else if(inByte==2)
        else if(inByte==3)
        else if(inByte==4)
        else if(inByte==5)
        else if(inByte==6)
        else if(inByte==7)
        // Dont decode 8 - backspace
        else if(inByte==9)
        // Dont decode 10 - Line Feed
        else if(inByte==11)
        else if(inByte==12)
        // Dont decode 13 - Carriage Return
        else if(inByte==14)
        else if(inByte==15)
        else if(inByte==16)
        else if(inByte==17)
        else if(inByte==18)
        else if(inByte==19)
        else if(inByte==20)
        else if(inByte==21)
        else if(inByte==22)
        else if(inByte==23)
        else if(inByte==24)
        else if(inByte==25)
        else if(inByte==26)

          // Its a normal key

I2C Functionality

As of Version 1.20 we have added the ability to read keyboard characters using I2C instead of a serial connection.

The I2C functionality uses a 256 byte keyboard buffer on the USB Host board to avoid losing any characters between reads.

There are basically two read functions you can perform
1. Check how many bytes are in the buffer
2. Read the data

Check if there are key presses in the buffer

To check how many characters are waiting in the buffer, read a single byte from the register address 0x01

Read the key presses in the buffer

To read the characters that are waiting in the buffer, read one or more bytes from the register address 0x00. It is recommended that you first check how many characters are in the buffer.

Example Arduino program to Read Using I2C

** Wire Master Reader of Hobbytronics USB Host Keyboard
** Created 24 Oct 2013
** This example code is in the public domain.

#include <Wire.h>

const int  adc_address=41;   // I2C Address

char keyboard_data[80];   // Array to store keyboard values   

void setup()
  //Send settings to ADC_I2C device (optional)
  Wire.begin();              // join i2c bus (address optional for master) 
  //Start Serial port
  Serial.begin(9600);        // start serial for output

void loop()
  unsigned char i;
  char keyboard_chars;

  Wire.beginTransmission(adc_address); // transmit to device
  Wire.write(1);                       // ask how many characters are in buffer
  Wire.endTransmission();              // stop transmitting  
  Wire.requestFrom(adc_address, 1);    // request 1 bytes from slave device
     keyboard_chars =;

  Serial.println(keyboard_chars, DEC); // print number of buffer characters
  Wire.beginTransmission(adc_address); // transmit to device
  Wire.write(0);                       // get keyboard characters
  Wire.endTransmission();              // stop transmitting  
  Wire.requestFrom(adc_address, keyboard_chars);    // request characters from slave device
     keyboard_data[i++] =;
     keyboard_data[i] = '\0';

  Serial.println(keyboard_data);       // print the character  

  delay(5000);                         // Wait 5 seconds


Écrire un avis
Votre nom :

Votre avis : N.B. : Le HTML n'est pas pris en charge !

Évaluation : Mauvais            Bon

Saisir le code ci-dessous :

Il n'y a aucune image supplémentaire pour ce produit.
USB Host - Keyboard to ASCII Converter
$ 00€ New In Stock
Aucun article
Frais de Livraison

France & EU - poste aerienne de 3.47€ +VAT
Plus d'informations...

 Check out our videos
Follow us on: