Hardware Reference
In-Depth Information
It cannot use USB hubs, and as such cannot talk to multiple devices or communi-
cate with keyboards that have a built-in USB hub. This includes some specialized
keyboards or keyboards with USB connectors for plugging in external devices.
USBHost Library
The Arduino 1.5 IDE comes with the USBHost library. To use it, you must i rst
import it. This can be done in the menu: Sketch
➪
Import Library
➪
USBHost.
This imports quite a few libraries, as shown here:
#include <hidboot.h>
#include <hidusagestr.h>
#include <KeyboardController.h>
#include <hid.h>
#include <confdescparser.h>
#include <parsetools.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <adk.h>
#include <address.h>
#include <MouseController.h>
To initialize the USB subsystem, you must create a
USBHost
object:
// Initialize USB Controller
USBHost usb;
The
usb
object can then be given to the different software structures. To
process USB events, you must use the
task()
function.
usb.task();
The
task()
function waits for a USB event and calls the necessary function as
those events happen. The function is blocking; while it is running, no other func-
tions can run. If no event is received, it will time out after 5 seconds. If no device
is connected, this function returns immediately, instead of waiting for a time-out.
Keyboards
Keyboards have their own controller, the
KeyboardController
class. First, you
must attach the
KeyboardController
to the USB subsystem:
// Initialize USB Controller
USBHost usb;
// Attach Keyboard controller to USB
KeyboardController keyboard(usb);
Search WWH ::
Custom Search