HIDSerial Problems

- %post_shorttitle_linked%
- %post_shorttitle_linked%
- %post_shorttitle%
The idea is to take the USB Volume Knob project a step further and not only have one-way communication from the Adafruit Trinket to the PC, but also have the PC report any changes in volume and mute state to the device.
I eventually want to add an Adafruit NeoPixel ring around the base of the rotary encoder in the enclosure to show the current volume and mute state. With the RGB LEDs I could even display some special effects to notify the user of certain events happening on the PC.
But, first things first. The Trinket doesn’t offer hardware serial communication but there are at least two two workarounds:
- using a tool called com0com but that meant manually installing drivers and additional software and I didn’t want this because it’s not very user friendly
- an alternative method using a library called HIDSerial from RaysHobby.net, but forked and adapted to work with Adafruit’s Trinket. It uses V-USB to bitbang USB as a software-only implementation to make low-speed serial communication possible for AVR controllers of the Atmel family, i.e. ATmega’s like the one used in an Arduino Uno and ATtiny‘s like on the Trinket.
The great thing about HIDSerial is that no driver installation is required. However, you can’t use it with Arduino IDE’s Serial Monitor or any other generic serial terminal software, but since I want to integrate it into my own host software anyway, I don’t mind that disadvantage, so that’s the library I want to use.
First download the Trinket HIDSerial library and copy the HIDSerial folder contained within that zip file to your %USERPROFILE%\Documents\Arduino\libraries\ folder.
Then restart the Arduino IDE and load the example sketch: menu File » Examples » HIDSerial » hello_world
Finally, from the Tools menu:
- menu Tools » Board » Adafruit Trinket 16MHz
- menu Tools » Programmer » USBtinyISP
That’s it! You can now upload the sketch to the Trinket (menu Sketch » Upload) right after pressing the reset button.
In the host software folder of the downloaded zip file, you’ll find the HIDSerialMonitor application to connect to the Trinket. If you didn’t select Adafruit Trinket 16MHz but the 8Mhz one as your board instead, you’d see the “Hello World!” message appear not every second but twice as fast. In that case, just change your board selection and upload again. There is no need to add the clock_prescale_set call to the setup as mentioned in my Adafruit Trinket programming introduction because HIDSerial already does that for you.
Problems
I initially couldn’t get the supplied HIDSerialMontor to connect to the device and got none of the HIDSerial examples to work because my Windows 10 Device Manager showed the device as an “Unknown USB Device (Device Descriptor Request Failed)” instead of “USB Input Device“. Sometimes it even showed up as an “USB Input Device” but with an error icon next to it. I noticed I often got the error message avrdude: error: usbtiny_receive: (expected 4, got -5). Maybe just bad luck with the timing of pressing the reset button on the Trinket, I don’t know. I tried upgrading my Arduino IDE from version 1.6.5 to 1.6.7, but that didn’t help. Until all of a sudden, after uploading the sketch, it worked: Windows showed “USB Input Device” without an error icon and I could even connect to it with the HIDSerialMontor, but after disconnecting and reconnecting in the tool, I got the message “Could not find device!!” again—even though the device still looked alright in the Device Manager. But when unplugging the Trinket and inserting the USB cable again, the “Unknown USB Device” message was back.
Later, I might give this another try with something else that supports serial communication to begin with—unlike the Trinket—but after spending multiple days trying to modify USB HID report descriptors, experimenting with HIDSerial and trying to adapt the TrinketHidCombo code, I’m giving up on this for now.
Did you try this tutorial? https://learn.adafruit.com/trinket-usb-volume-knob/code The com0com one I don’t like much myself. If you get a Trinket Pro (which is like a tiny Uno) try https://learn.adafruit.com/pro-trinket-rotary-encoder/overview (which I did).