Dec 23, 2013

LeoStick Volume Control


I first became interested in building a micro-controller hardware volume control for computers through the tutorial from Adafruit on the Trinket Volume Knob. The Trinket is an interesting ATTINY85-based platform designed by Adafruit. It can, with a little set up effort, be used with the Arduino IDE. 

The basic idea of this kind of volume control is this: turn a rotary encoder, which acts like a volume knob on audio equipment, and the micro-controller sends a keyboard code to your computer, altering the volume level. To do this, the micro-controller has to appear as an HID USB device to the computer.

But, after much effort and for one reason or another, I couldn't get the Trinket Volume Knob to be recognized on Ubuntu 12.04, Mac OS/X 10.7.5 or a Windows 7 64 bit.

My next attempt was with the code offered by Bluebie  on the Digistump/digispark forum. The digispark is also an ATTINY85-powered dev platform, programmable through a special version of the Arduino IDE offered by Digistump. It differs from the Trinket in several ways, notably the choice of the micronucleus bootloader. I got a little farther with this design, I could get the volume mute function working in Mac 10.7.5, but no volume up/down. No functionality in Ubuntu 12.04 LTS. Bluebie said that the volume control worked for her on OS/X 10.9, which may have functional differences from my installed 10.7.5.

I did some googling on arduino volume controls and stumbled upon the work of Stefan Jones with the Arduino Leonardo. I didn't have an actual Arduino Leonardo, but I did have a Freetroncs LeoStick, which is a nice clone of the Leonardo with some added features, in a smaller form factor.

I installed the LeoStick with the instructions offered in the LeoStick Getting Started Guide  on my Ubuntu 12.04 LTS system, using Arduino 1.0.5 as the base. Once I was satisfied the LeoStick was working in this setup, I  made the changes to the USBAPI.h and HID.cpp as Stefan Jones indicates in his post. I tried the test sketch that alternately mutes/unmutes volume from Stefan's post and that worked fine.

Finally, I used Bluebie's digispark volume knob code as a base for a LeoStick version. The code changes were trivial: 
  • Remove any references to DigisparkKeyboard
  • Add statements for Remote.mute(); Remote.increase(); and Remote.decrease(); as appropriate
  • Add Remote.clear(); at end of main loop to keep from repeating latest function.
That's it!

See the code at GitHub.

This worked for mute/up/down on my Mac and Ubuntu systems. It worked for volume up/down on my Nexus 7 4.4.2 (KitKat) as well, using a USB OTG cable to connect the LeoStick. Unfortunately, I could not get any functionality on Windows 7 with this set up.

UPDATE: Tested to work in Windows XP and Windows 7 64bit Home Premium. I had to remove the LeoStick after installing LeoStick Windows Drivers, available from the Freetronics site. On re-insert to a USB port, the Volume Control had full functionality.


1 comment:

  1. Thanks thisoldgeek your code worked for me using Arduino Leonardo and a Keyes KY-040 Rotary Encoder!
    BTW, your profile remarks remind me of me LOL!!!

    ReplyDelete