USB Mouse with ATmega32U4 Pro Micro Clone and LUFA

I have spent a fair amount of time with 8-bit AVR microcontrollers and one of the cooler things has been the V-USB library which implements low-speed USB with clever (and very time-critical) bit-banging. The popularity of my USB tutorials is a testament to its usefulness, and I’ve gotten lots of mileage out of that.

There are, however, some limitations to software USB with such a low spec microcontroller. USB communication hogs up the MCU completely during USB communication, which means you lose dozens of microseconds in random (or in many cases 8 ms) intervals. This rules out things like software UART at reasonable speeds (which I discovered when trying to implement MIDI on Adafruit Trinket). And more powerful ATmega328-based dev boards like Pro Trinket start to get quite large.

ProMicro on a breadboard

Not so with this tiny beauty shown in the image. It’s a ATmega32U4 based board, where the U4 means it has hardware USB support. The form factor is extremely compact 12 pin header length, which leaves 5 rows free on the smallest prototyping breadboards. That means you can have a DIP8 component with a few resistors on the same breadboard (such as a 6N137 optocoupler which is nice for MIDI… ;).

And the best part is, that because the chip is flashed with same firmware used in Arduino Leonardo (and a largely matching pinout), you can use Arduino for programming, and avrdude supports it out of the box.

Actually, scratch the above statement. The best part is the price. The board is based on Sparkfun Pro Micro 16 MHz, but it’s actually a Chinese clone, which you can get for $4 via DealExtreme and from quite many places in AliExpress: Just search for ATmega32U4 and they will come up. This means you can just order five and solder them into whatever project you’ll make permanently. And unlike Arduino Micro (for which clones exist as well), this has the micro-USB port already in place.

Using Pro Micro without Arduino IDE

Now you can just follow SparkFun’s instructions on how to use that thing on Arduino (short version: select Leonardo as board type, and look up the schematic if you are unsure which pins are connected to LEDs, etc.). But if you’re like me and want to get to raw metal, avr-gcc and avrdude is the way to go. Here’s a simple blinky demo:
Continue reading USB Mouse with ATmega32U4 Pro Micro Clone and LUFA

Using WinAVR and Command Line for AVR Development

cmd

Since my V-USB tutorials became popular, a recurring theme in the comments section have been people who are obviously motivated to try out the tutorial, but due to limited exposure to C language and command-line are either having trouble following my short instructions to compile the example .hex files, or being scared of the command-line, have tried to use AVR Studio instead, and fail.

I have to admit that first I was a bit annoyed by these people – why are they trying to follow a challenging project, when they seemingly have no understanding of how command line, makefiles, C compiler and linking process works? Then, comment by comment, I finally realized that not everyone started coding in the nineties where you launched Windows 3.11 mostly to play Solitaire, and biggest thing in coding productivity was 80×50 text mode which allowed you to have 16-color hacking bliss in your Borland Turbo C++ 3.0 IDE (or RHIDE, after DJGPP came around).

So, instead of either ignoring these people, or spending any more hours answering the same questions, I decided to start a new series of tutorials to cover really basics of getting into AVR development the way I like to do it: Old skool.

Navigating the command line

The bar for command-line wizardry in AVR development is low. There are four levels in it:

  1. Firing up command prompt
  2. Navigating to a directory and viewings its contents
  3. Running commands

The first one is really easy. In Windows 7 you can just click the start button, type “cmd”, and you’re there. Or type “command”, as the Command Prompt is usually the first search hit displayed. More hardcore persons use Win+R (that key with flag symbol finally does something useful!) and type “cmd” into the Run dialog as shown in title image of this post.

Windows Explorer

Once you’ve bitten the blue pill, commanding #2 is also quite easy. First, you need to understand that command prompt is very much like Windows explorer (shown in the above screenshot) – you are always in some directory, and the commands you enter usually work within that directory. In the example above, we are in directory E:\Koodi\AVR\usb_tutorial – let’s try if we can replicate that in command line:
Continue reading Using WinAVR and Command Line for AVR Development

Tips and Tricks: Flashing already soldered MCUs

I have been wanting to try this one out ever since I soldered together my USB password generator six months ago, just to realize that I would’ve actually liked to make a few changes to the firmware. The problem with my design was, that I had managed to pack everything so tightly, that there was no hope of reaching the ATtiny85 pins via normal methods to reprogram it.

I initially tried to use a 8-pin DIP socket and press it against the MCU, but it soon became apparent, that I could not keep it stable for all the pins to keep contact long enough. Lacking proper microhooks, I had to postpone the idea shown in the above photo until I just recently put my hand on this set of IC hooks from SparkFun.

The five IC hooks came one hook short of the six needed by the ISP header, but fortunately/unfortunately one of the pins was impossible to access even with these tiny hooks, so I manually held a yellow jumper wire against the MISO pin while running avrdude. Did it work? Look for yourself:

Definitely not rocket science, but for $4.95, I’d say it’s a pretty good deal!

AVRweb 0.1 alpha released

After several months of sporadic coding, I finally got this large project to a point where I can consider making the first alpha release. So without further ado, I present AVRweb, a web-based UI for programming AVR chips.

Basically, it is a self-contained web server that allows you to interface with avrdude to read fuse settings, change them, and in the future, much more. The first alpha release is centered around fuse settings, and should already make the changing of AVR fuse bits a much quicker task – current settings are automatically read from the connected device, so you don’t need to toggle switches anymore to find the current setup. Also, new settings can be changed with a press of a button. See the video demonstration below (note that I’m running AVRweb on a PC, and just using the web interface with iPad, it’s not an iPad application!):


Continue reading AVRweb 0.1 alpha released