Arduino as HID

jon's icon

Hi all.

I've hooked up a Qprox capacitance-to-digital sensor to an Arduino board, and am using the setup as a kind of theremin. The sensor spits out a stream of 16-bit data relating to the proximity of objects (like my hand) to its electrode/antenna.

The 16bit data gets sent as ACSII strings into the computer (PC, WinXP) via the Arduino USB serial port. Then, in Max, I can re-assemble the ASCII stream into meaningful numbers and do stuff with them - ie, generate a tone, whatever.

So, here's the problem: It all goes too slow, and half the time everything jams up - Max just doesn't seem to be able to cope with the amount of data coming in, even when i program Arduino to send only 2 numbers per second. Not at all useful considering I need to cut down the latency to below 10ms for the setup to be even vaguely useful as a musical instrument...

What about somehow convincing windows that Arduino is actually a keyboard or a joystick or something, then using the data in a HI object in Max?? Is anyone able to explain to a relative newcomer how Human Interface systems work (ie, how to make something that windows will recognise as one), or suggest other ways to get a fast 16bit data stream into Max somehow?

Thanks, Jon.

Andrew Benson's icon

This would not be an easy task, to say the very least.
HID devices require a great deal of extra work in creating HID
descriptor tables. The way the Arduino communicates via USB relies upon
a UART-->USB conversion chip, which essentially mimics a serial port as
far as the computer is concerned. I doubt that it would be possible to
even implement HID on Arduino given that HID is a subset of the USB
protocol, not meant for serial port devices.

What I think you are looking for here is the Incremental update for
[serial] posted here for Windows users:
https://cycling74.com/twiki/bin/view/IncrementalDownloads

That said, if you are interested in a lower level solution that might
require some C programming and a little more DIY, there are several
microcontroller-based projects that use the HID protocol. Google for
AVR-HID or the CREATE USB Interface designed by Dan Overholt.

The one caveat to working with HID is that it all HID devices are
limited to a 10ms~ polling rate. I don't believe there is any such
limitation on serial devices besides that imposed by the software (or
the speed of the microcontroller).

Good luck!

Andrew B.

Olaf Matthes's icon

andrew benson wrote:
> The one caveat to working with HID is that it all HID devices are
> limited to a 10ms~ polling rate.

That's not true. - recently I did some tests with Dan's CUI and a custom
firmware that Dan provided with the bInterval field in the HID
descriptor table changed from 10ms to 5ms. At least on Windows (haven't
checked in OS X yet) the data rate really increases by a factor of 2!
I used a loopback configuration by connecting the output pins to the
inputs and monitoring for missing data. With 5ms set in the firmware I
could send every 6 or 7 milliseconds and got all the data back without
losses. In theory it should be possible to reduce this value even more,
but we haven't tried that yet.

Olaf