Showing results for 
Search instead for 
Did you mean: 

Need Example Code to Interface with a USB HID compliant Device

Well, not surprised that the alone doesn't work. Most devices tend to require some kind of command to initiate a transfer.


But I wonder if you are not barking up the completely wrong tree here. The ATTiny is most likely by default not implementing a USB_HID device but maybe a USB_CDC device or even some proprietary protocol. You do need to install a specific driver for the Digispark for instance to communicate with it.


While the USB bus for both is the same as far as hardware is concerned, the protocol is what makes the whole story. Default the Micronucleus firmware on the ATTiny is using a proprietary protocol. It can be changed to CDC (virtual comm) or HID but that requires a recompile of the firmware and potentially other changes to implement a specific device (the teensy variant for instance does use the HID implementation).


Rolf Kalbermatter
Averna BV
LabVIEW ArchitectLabVIEW ChampionLabVIEW Instructor
0 Kudos
Message 31 of 34

Dear Rolf,


The Digispark Attiny85 has several USB protocols integrated by software. Keyboard, mouse and joystick work nicely.

There is a CDC protocol, which I would like to use, because then it would be like serial communication, but unfortunately this does not work on my machine. The reason seems to be that "CDC isn't technically supported on USB low speed" as found on several notes (e.g.!topic/london-hack-space/vCXBVYzPJqw). I get the error message "Das USB-Gerät hat einen ungültigen USB-Konfigurationsdeskriptor zurückgegeben." and a yellow "!".

When taking the DigiUSB library Windows lists two devices with the Same PID, VID combination: "USB Eingabegerät" and "HID-konformes vom Hesteller definiertes Gerät".

The HID_Descriptor can be found in the software:

PROGMEM const char usbHidReportDescriptor[22] = {    /* USB report descriptor */
    0x06, 0x00, 0xff,              // USAGE_PAGE (Generic Desktop)
    0x09, 0x01,                    // USAGE (Vendor Usage 1)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x09, 0x00,                    //   USAGE (Undefined)
    0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)
    0xc0                           // END_COLLECTION

I remember that I had to select a configuration (even if there is only one) and select Carrier and DTE for a USB interface that I needed for a real-time system some years ago, but I am not sure if this is standard.

Writing descriptors is not much more complicated than reading, but will take some time....

So, I would be happy if someone has done this before or there is a "universal" solution for HID-devices?


I have not worked with the teensy, but I think it implements a CDC USB Device, so that you just have to communicate with a serial device. If not, the solutions for teensy and Attiny85 could be similar?


The disadvantages of the joystick implementation are:

a) only one way transfer

b) no synchronization and buffering

So I would like to have a better way.

Best regards








0 Kudos
Message 32 of 34

Well from a project I looked at to use a Digispark as Keyboard emulation ala Rubber Ducky, I remember that one had to write specifically a C program that included "DigiKeyboard.h" and at the start of the main() routine one had to call one or two functions from that library to initialize the USB port as HID. Out of the box the Digispark which is an AtTiny85 board, would only support a proprietary USB device protocol that is used through the Arduino IDE or other programming environment through a special USB driver that one has to install on the computer. But I have to admit that I didn't quite work through everything as the project eventually was canceled.

Rolf Kalbermatter
Averna BV
LabVIEW ArchitectLabVIEW ChampionLabVIEW Instructor
0 Kudos
Message 33 of 34

Oh oh, what a bunch of comments.
I hat written the Durchflussmesser example pointed above but unluckily I cannot view into my .LLB anymore because our company had downgraded the LabVIEW version.


In case of using V-USB on ATtiny85, making a USB HID device ist by far the best solution as no user-supplied driver is needed from Windows 98 upto Windows 10.

The example given surely contains code to get data from the USB device, and you can easily put data into the opposite direction. However, don't forget to initialize the HID Report ID. Zero if no Report ID is used.

Correct, all my .LLB subroutines should be marked as runnable in "any thread". It's a bug.


As USB HID is not natively supported by LabVIEW (and Matlab), a Serial Interface (aka COM port) is more common. Today I would recommend migrating to PIC145x and its crystal-less USB full-speed interface, allowing for USB CDC interface with almost no hassle except one INF file. For this chip I made a 512 word USB CDC boot loader that additionally allows for simple I/O with no firmware programming. See

0 Kudos
Message 34 of 34