One of the ways we’ve tried to differentiate some of our recent and upcoming products, like the Krampus and RBG RGB badge, is by using some of the tiniest ATTiny microcontrollers we can get our hands on. For these boards we picked the ATtiny4, which has just 6 pins, 256B (not KB!) of EEPROM and SRAM, and 512B (not MB!) of flash, providing a hearty challenge to hackers who may be accustomed to more spacious resources. But before we dive into hacking with that most minimalist MCU, let’s take a general look at the basics of programming AVR chips without all of the abstraction provided by tools like Arduino – or as it is sometimes called: bare-metal programming.
BARE-METAL AVR DEVELOPMENT WITH USBASP
If you’ve ever taken a close look at an Arduino board before, you may have noticed that it is fairly-well populated beyond the ATmega chip. Most of the components you’ll find on the Uno PCB for example are for supporting a range of power supplies, as well as onboard USB-to-serial, so that all that is required for programming is a standard USB cable. Given the visual complexity of the Arduino, it may surprise you to discover that the ATmega168 chip itself comes with everything you need for basic operation right inside the package! One of the components you’ll see on the board is an external crystal, which allows the 168 to operate at 16mHz, but the 168 is actually capable of running at 8mHz with its own onboard clock. So other than the above-mentioned programmer to flash it, and a 5V power source, none of that other fancy stuff is actually required for basic operation!
With our compiler and Downloader/UploaDEr installed (get it? DUDE??), let’s load some blinky code! This blog post is already rather long, and I can tell you’re anxious to see that LED blink, so let’s just grab some pre-compiled code and not worry too much about how it was built from a .c file or what it’s doing – there are more blog posts coming in future where we will get into compiling and makefiles and ports and pins and bit masking and all of that! We used a nicely commented piece of example code "blinkLED.c" from the repo for Make: AVR Programming (474 pages of raw AVR goodness centered around projects which demonstrate key microcontroller concepts – pick up a copy from the Maker Shed!). We forked their repo and added the compiled hex file to ours here: