USB Type A Female Breakout Hookup Guide

Pages
Contributors: Shawn Hymel
Favorited Favorite 1

Example Code

We will use the mbed online editor and compiler for this example. First, navigate to mbed.org, and login or create a profile.

mbed login

Once logged in, go to the Handbook Homepage, which contains all of the official mbed libraries.

mbed Handbook

Scroll down to find the USB Host Keyboard library under "Communication Interfaces."

mbed USB Host Keyboard library

Click the "Import Program" button to load the library and example program into the online compiler.

mbed import program

Make sure you have "Program" selected from "Import As:", as we want to use the example program (select "Library" if you plan to write your own program using the library).

importing example mbed program

In the "Program Workspace," select the "USBHostKeyboard_HelloWorld" folder and click "Compile" at the top. This will automatically compile the program and download a binary (.bin file) to your computer.

mbed compile USB keyboard example

Plug in the mbed microcontroller to your computer using a USB cable. The mbed should enumerate as a USB mass storage device. If you are using Windows, it will appear as if you plugged in a thumb drive.

Find where you downloaded the compiled .bin file and copy it to the root directory of your mbed device.

mbed copying compiled program

Press the reset button on the mbed system. This will reboot the mbed and load the .bin file to be immediately executed.

In addition to enumerating as a mass storage device, the mbed also has a built-in COM port. If you are on Windows, open up the Device Manager and locate the mbed Serial Port's COM number.

mbed COM port

Start the serial program of your choice (I will use PuTTY for this example) and select the COM port correseponding to the mbed device. Use 9600 baud, and click "Open."

Configure PuTTY for the mbed

Once you establish a Serial connection to the mbed, you will be presented with a blank console.

blank Serial console

Plug in a USB keyboard to the USB Type A Female Breakout Board.

mbed LPC 1768 and USB keyboard

The Serial console should show the keyboard being enumerated. You can type, and keystrokes will appear in the console. If you unplug the keyboard, you should see a "disconnected" message.

IMPORTANT: Only letters and numbers are supported in this example program. Additionally, the program cannot discern multiple keystrokes (for example, if you hold '1', press '2', let go of '2', and let go of '1', you'll see "111" printed).

Testing the mbed USB keyboard program