Getting Started with 8-bit Atmel AVR Microcontrollers

Microcontrollers are absolutely wonderful little pieces of technology.  They can be programmed to perform a myriad of functions, such as digitizing analog signals for processing, controlling lighting or motors, reading sensors, making music, or just about any imaginable task given enough computing power.  As a programmer of desktop and server systems, writing code that is emancipated from the confines of a mostly stationary general-purpose computer is very exciting and appealing to me.  These little processors basically live in their own little microcosm.  And some of them can be genuinely tiny.

For as many functions as microcontrollers can perform, there are as many different options for processor selection.  There are 8, 16, or 32 bit processors.  There are different architectures, such as 8051 / C51 / C52, PIC, AVR, ARM, dedicated DSP processors, etc.  Selecting the right line of processors can be a confusing, if not daunting task.

As a beginner getting into programming processors, some criteria are probably obvious…which processors have inexpensive programming tools, are well-documented, have a wealth of source code available online?  The answers for many beginners are often some common 8-bit processors, such as Atmel’s AVR or Microchip’s PIC processors. [Arduino is also an option...more on that later.]  I’ve worked with many MCU architectures, and I find that 8-bit Atmel AVR processors are very easy to program, have inexpensive device programming tools, have a free IDE* in which to program, and have a very active online community of programmers of all levels of expertise to help guide you when you’re stuck.  It's also great that there are programming tools available to code in C, C++, assembly, even Basic.

* The free Atmel AVR Studio IDE is Windows-only.  Many other toolchains are available for AVR development

You’ll need a programmer to get started.  This is a physical device that attaches between a computer [usually via USB] and the microcontoller.  A programmer may offer different functionality such as the ability to debug your code in-circuit, or use special high-voltage programming modes [very helpful to resurrect an incorrectly programmed chip].  But a programmer’s primary duty is to write your compiled code into the processor’s flash memory for permanent storage.  Atmel’s MCUs allow a minimum of 10,000 writes, so you can basically re-program the chip endlessly.  Atmel offer two very inexpensive options, the AVRISP MKII and the AVR Dragon.  The AVRISP MKII is a ~$30 programmer that allows you to program a chip, even if it’s in the target circuit [ISP means In-System Programmer].  The AVR dragon offers a lot more functionality, including debugging, which is a feature absent in the AVRISP MKII.  The AVR Dragon supports a wider list of devices, including Atmel’s 32-bit line of AVR processors.  The AVR Dragon also provides HVSP and HVPP [high-voltage serial or parallel programming] modes.  One idiosyncrasy of the AVR Dragon is that it doesn’t support Atmel’s TPI protocol [Tiny Programming Interface] to program some of the smallest AVR ATTiny processors…you’ll need an AVRISP MKII for that.

You’ll also need some processors to work with.  I’d suggest starting with the ATTiny24 or ATTiny44.  These are 14-pin breadboard-friendly DIP processors and are supported by both the AVRISP MKII and the AVR Dragon.  They feature 2k/4k flash programming memory, 128/256 bytes of RAM, one 8-bit and one 16-bit timer, clock speeds up to 20MHz, 8 ADC [analog-to-digital converter] channels, operate from 1.8-5.5VDC, support external interrupts, serial communications [includes SPI], several PWM modes.  They’re just all-around good processors for many projects.  They’re also inexpensive, costing just ~$2 each in single quantities.  If the ATTiny isn’t powerful enough for your specific application, the ATMega processors will probably work well for you.  Most Arduinos use ATMegas for their brain.

Speaking of Arduino - what about getting started with Arduino, instead?  I’ve not personally used an Arduino.  I know they have a very vibrant and active community of enthusiasts.  I know there are vast libraries of code available to get you blinking LEDs in no time flat.  But once you get your first LED blinking, where are you left?  You’re somewhat stuck with the Arduino platform.  It’s a great gateway to learning microcontroller programming and physical computing in general.  But I personally feel that it obfuscates the underlying MCU architecture from the programmer in such a way as to leave the programmer without an understanding of how the code actually works.  It’s also my understanding that Arduino compiled code is relatively slow and bloated compared with writing bare-metal C code…but I have no personal experience with Arduino, so I can’t back that up.  I feel that if you can program an Arduino, you can program an AVR without the Arduino framework.  It probably just takes a little more reading and understanding of the processor’s datasheet, which isn’t a bad thing.

So, here’s a quick list of items available from one of my favorite electronic component distributors, Mouser :

AVR Dragon

There are other components you’ll likely need if you don’t already have them, such as a 5VDC power supply, various resistors, capacitors, potentiometers, 20MHz crystal if you want to run the chip at full speed [you can run up to 8MHz without one], LEDs, jumper wires, etc.  Many of these items can be purchased at your friendly neighborhood Radio Shack.

Here are some additional links :

Atmel’s website
Atmel AVR Studio 5 [requires registration…grrr]
AVR Freaks website [awesome resource for learning; great message boards]

And of course, if there’s anything I can do to help-out, I’m more than happy to. 


FYI : The watch at the top is powered by an ATMega88 AVR microcontroller.