Microprocessors are so cheap these days. If only there were a way to program them up just as cheaplyâŚ
*wavy dream-sequence lines*
In this instructable, find out how to build up a complete AVR microprocessor toolchain: compiler, programmer software, programmer hardware, and some simple demos to get your feet wet.
From there, itâs just a hop, skip, and a jump to world domination.
The endpoint is not quite as swanky as Atmelâs suite, but itâs gonna run you about $150 less and take only a little more work to get it set up.
This instructable is based on the Atmel ATtiny 2313 chip, mostly because itâs one of the smaller chips (in size) while still being beefy enough to do most anything. And at $3 a pop (non-bulk), they donât break the bank.
That said, most of the steps are applicable across the AVR family, so youâll be able to re-use most everything when your programming needs outgrow the ATtiny and you reach for the $8-$12 ATmegas.
Update Aug 24, 2007: Iâve gone USB! Itâs neither ghetto nor particularly deluxe, but a nice middle ground. If youâve got a computer without a parallel port, check this http://www.instructibles.com/id/EDRQZ56F5LD8KDX/ out.
If youâve got a parallel port, or are just feeling cheap, read on!
Go Order Parts!
Necessary Parts List (stuff to buy or scrounge):
Atmel ATtiny2313 chip: $2.50 - $3Socket for chip: $1Parallel port connector (DB25):$3 at Radio Shack or $0.95 at SparkfunHeader Pins:$1-$2 (at least one strip each male & female, maybe 2 female) Some LEDs and resistors: $1
= Around $10, even if you go deluxe. Half that if you can find an old parallel port cable.
Add-ons
A pushbutton switch or two: $1.
A piezo speaker: $1-$5
Light sensitive photocells: $2-$6
Breadboard for making complex circuits: $8-$10(?)
Other Stuff You Oughta Have
Computer: The older the better because it needs a parallel port.
Hookup wire, solder, soldering iron
Super-duper glue
Source of ~5v DC: Batteries will work, and old computer power supplies are perfect.
I get a lot of stuff from Sparkfun because theyâre
fast, reliable, and fairly priced. They carry AVR chips (but seem to be out
of ATtiny13âs at the moment). Theyâve got everything on the âNecessaryâ
list in one place, nice website.
If youâre gonna be ordering a lot of chips, you can get a deal from Digi-key or similar. For instance: ATtiny 2313 for $2.36 each. Theyâve only got 27,853 more in stock, so order quick. (Make sure you get the DIP form-factor.)
Go order stuff now, and we can set up the software side while you wait.
The waiting is the hardest part.
Get and Install Software: Linux Version
If you run Windows, skip this page. Or install Linux, then come back. đ
The Linux AVR software toolchain used is:
1) an editor of your choice (emacs, gedit, kate, etc)
2) AVR-GCC compiler and libraries
3) AVRdude programmer
4) A nice Makefile to tie it all together
May 2008 Edit: Ubuntu has packages for the whole toolchain. Your installation is now as easy as: âsudo apt-get install avrdude avr-libc binutils-avr gcc-avrâ. Bam! The versions that come with 8.04 are good all around. Woot Ubuntu!
If you want to do it âby handâ, the script below automates most of the work for you. Note that as of May 2008, itâs a year old, and doesnât support the newer ATTinyx5 series chips. You can mess around with updated versions of all the software is youâd like. (Itâs saved with a .txt extension b/c Instructables wants it. Doesnât matter.)
Youâre going to have to edit the first command in the install script depending on whether youâre using an apt-based package system or a yum-based one. Just uncomment the relevant line. It needs to make sure youâve got some packages which are required for the compilation stage.
Have a read through the script to make sure itâs not doing anything stupid, then get root and run it and you should be golden.
It will create a directory /usr/local/AVR and install all the AVR tools there.
The last thing the script does is to add avr-gcc to your path so that you can run avr-gcc directly by adding a line to the tail of your /etc/profile.
The other file, setupParport.txt, is just a (very) simple script to set up your parallel port for user use. If youâre savvy, you can add the same commands to a boot script so that it enables the parallel port every time you boot up. Otherwise, just run it by hand.
Websites with similar, but different and possibly outdated, procedures include: Psychogenic.com, AVRWiki, and this (old) Linux Focus article.
Alternatively, I hear cdk4AVR has a complete set of compiler tools in RPM format. I havenât tried it, but it could save you the 30 min of compiling time on a slow, old laptop.
Get and Install Software: Windows Version
The MS Windows software toolchain is based on the same compiler as Linux one, but with some optional extra GUI friendliness.
WinAVR is the compiler and programmer software. It also includes a nice programming editor, Programmerâs Notepad.
Download and install it. Itâs that easy. Almost.
As the last step in setup, youâll need to make the parallel port user-accessible. WinAVR includes a program for you to do this. If you accepted the default installation options, run C:\winAVR\bin\install_giveio.bat by double-clicking on it. A window will flash up and down, and then youâre done.
Make Programmer Cable
Parallel Port AVR Function Color2 MOSI Orange/Grey11 MISO Orange1 SCK Green16 RESET Brown18 GND Brown/Grey
Only tricky bit here: Note that pin 1 (SCK) is on the upper-right hand side when you are looking at the solder pins from the back. Itâs upper-left when youâre looking at it here, and in the circuit diagram.
Also, the guyâs website above has ground connected to 20 and 21 while mine (and others) use 18. Many of the pins connect to ground, and it doesnât matter which of them you pick, as long as you get ground.
If you look around the web, youâll find that most people put resistors in either the cable or the cradle (next step) to protect their computerâs parallel port from excessive voltages on the AVR chip for use when programming it in-circuit. We will be using strictly 5v here, so thereâs no such worry, and I leave them out for simplicity.
However, if your chip ever comes near >5v, DO NOT USE THIS CABLE WITHOUT RESISTORS! A computer with a burnt-out parallel port is no fun. That said, Iâve been using it without incident for 6 months now.
Make the programming cradle
Now use the 20-pin socket and female headers to make a cradle which connects the pins from the cable to the right pins on the chip.
The first thing to do is superglue all the headers and the socket to the circuit board. That way, itâs easier to solder to. You can even make an extension for the header like I did if you need more room on your circuit board.
For more Detail: Ghetto Programming: Getting started with AVR microprocessors on the cheap.