Tuesday, September 4, 2012

Back to, having fun with 8bit AVRs

Being the kind of jobless tinkerer that I am, I have again resumed fiddling with my all time favorite toy - the 8bit Atmel AVR microcontrollers. No matter how much I play with these little beasts, they never stop amazing me. I had spent a large part of my spare time in college, having fun with these, making all kinds of stuff starting from usb controlled desk lamp to full fledged webserver showing my current room temperature and ambient light levels. Not being an out-of-the-box genius, I did spent a HUGE amount of time, rummaging through the web, looking for whatever relevant information I could find!

And then after finishing college, I moved to a different country and had to leave behind all my handmade stuff :(
There was a brief period of time, almost a year, during which I focussed on other things and most of my  hobby electronics work went into nirvana. Not that I was completely detached from fiddling with electronics. My PhD experimental work, ensured that I had my regular dose. There was a continous barrage of broken electronics ranging from aom drivers to microwave generators to power supplies and what not in the lab, that I was fixing or atleast trying to fix.

And then on one fine day, came the opportunity to have some fun with my old toy. There was an electro-mechanical optical switch in the adjacent lab, that had to be remotely operated. Functionally it was just a bunch of tiny reed relays, with mirrors glued to it, that directed light from one fiber to another. The relays were hooked up to a National Instruments USB Digital I/O card. In order to make it remotely operable, someone tried hooking up the USB board to an el-cheapo Network USB hub (some generic Chinese equivalent of this), but the NI DAQmx drivers weren't so cooperative and the device refused to work.

...and I got the long awaited excuse to fiddle with the AVRs. Emulating low speed USB protocol purely in software in AVR, is trivially easy, thanks to the hard work of these guys (oops, now feminists please don't come after me, I seriously haven't come across any girls in the forums, would be very much interested to meet any :D ). Spending a couple of hours on a lazy Saturday afternoon, I came up with this

using a ATTiny2313 lying around. Shamelessly copied the code from http://www.obdev.at/products/vusb/powerswitch.html, made some modifications to suite my purpose and voila, the thing worked like a charm, even over the el-cheapo network usb hub. Spending a few minutes, looking at the client side code written using libusb, it wasn't too hard to cook up something using NI VISA to communicate with the "fake USB low speed device" without using libusb. Not that I  am a big fan of National Instruments (not that I dislike their products either :D ), but my prof demands Labview compatibility for every piece of sh*t in the lab, so I didn't have much of a choice here anyway.

Going through this whole thing, I realised I don't have much of something called "memory" in my brain. Even though I had played with AVR MCUs a lot, after just a year of break, most of the info seemed to have had dissipated away from my brain. While doing this, I was literrally re-inventing the wheel at every step. I feel a dire need to avoid googling for the same information over and over. This time I am going to document everything on my blog!