HID Control of a Web Page

Pages
Contributors: Nate
Favorited Favorite 13

Teensy Setup

Teensy in a breadboard

Let's start by having the Teensy report HID packets. At this point we only need to attach a USB cable to the Teensy.

To get use RawHID you'll need to install Teensyduino. For help installing Teensyduino see the PJRC site.

RawHID Menu in Arduino

Once Teensyduino is installed, you'll have access to the Raw HID USB type as well as a basic example sketch. Before we continue there are some settings that can be modified. Find the usb_private.h file located in the \Arduino\hardware\teensy\cores\usb_rawhid folder, and open it in a text editor. The usb_private file contains the VID/PID, device string, and frame settings when using the RawHID library.

Vendor ID / Product ID

If you're just learning how to control HID there is no need to change the VID/PID settings. If you are rolling your own hardware you'll need to tweak the vendor ID and product ID. Don't have your own Vendor ID? That's kind of a problem, but, if you're just playing around, don't worry about it too much. If you're planning on selling 10,000 of your device then you'll need to spend the $5,000 to get your own VID.

Device String

This is the human readable string that is commonly shown when the USB is plugged in. It may sound fun to attach the 'NSA Webcam Controller' to your friend's computer, but let's leave the STR_PRODUCT alone for now.

Frame Size

The frame size (RAWHID_TX_SIZE and RAWHID_RX_SIZE) is what you should focus on within usb_private.h. How much data do you need to pass back and forth? For this tutorial, we are going to show how to read up to eight, 16-bit sensors, so we define RAWHID_TX_SIZE to be 16 bytes. To make things symetrical, let's set the size of the RAWHID_RX_SIZE to 16 bytes as well. These buffers can be any size (256 byte max), but try to be economical with your settings. Don't define a 256 byte array if you're just reading a temperature sensor. Edit usb_private.h, and set the TX/RX buffers to 16.

After you've edited the buffer sizes, save the file. If you're using Windows, you may need to save a local copy to your desktop, then copy/paste back into the \Arduino\hardware\teensy\cores\usb_rawhid directory.