Skip navigation.

exploreopera

| Help

Sign up | Help

First contact with ATmega8 microcontroller - part 1

, , ,

Last week I bought an ATmega8 microcontroller. I plan to use it to build an arcade USB Joystick, but first I need to understand how it works and how to use it.

This and the following posts are an attempt to document my first contact with this microcontroller and to describe all needed hardware and software so you can start using a microcontroller too.

What is a microcontroller?

A microcontroller is a simplified CPU, plus some amount of RAM, plus some amount of (re)programmable ROM, plus some I/O ports (including some analog I/O ports), and all of this in a single small chip.

Microcontrollers are used at many electronic devices, including microwave ovens and washing machines. They are simple and useful enough to be used in many DIY (do it yourself) projects. They usually can run at a clock rate of a few MHz.

What is ATmega8?

ATmega8 is a microcontroller from Atmel AVR family. Like (all?) other microcontrollers from that family, it has an 8-bit RISC CPU core. Both ATmega8 and ATmega16 are very popular and inexpensive microcontrollers.

The very popular Arduino project uses ATmega16, but has an ATmega8 version. The Make Magazine often features some projects using AVR microcontrollers (1) (2) (3) (4).

Atmel company provides some software tools to work with AVR microcontrollers, but there are also enough free software tools for that.

Why ATmega8 and not ATtiny or some other model?

There are many AVR models. ATtiny, in special, tend to be smaller and to have smaller memory and fewer I/O pins. I really don't know too much about them (or any other AVR microcontroller), but there is one big reason why I've choosen ATmega8: Cerne-Tec (the place where I bought the microcontroller)
only has two AVR models: ATmega8 and ATmega16.

Why ATmega8 and not ATmega16?

There are two main reasons why I've choosen ATmega8 over ATmega16: it's cheaper and it's the microcontroller used in the project I want to make sometime soon.

Before you continue...

I don't have much experience with electronics (yet), so please don't think everything here is 100% correct (actually, if something is wrong, please tell me!). If you are not careful enough, you may damage the microcontroller or even the USB port or the parallel port from your computer.

I use Gentoo/Linux system on x86 arch. I don't have access to Windows, Mac or BSD computers, so I don't know exactly what you must do on those systems.

This post is intended to be a very quick introduction to ATmega8 microcontroller. This post (and probably future posts about the same subject) can be viewed as crash course about ATmega8.

In this post I'm going to assume you have some very basic electronics background: you know what are DC, Vcc and GND; you can recognize a resistor, a capacitor, a LED and other components; you know how to solder (video and PDF) and how to use a multimeter (video and PDF). I'm also going to assume you can use your computer, whatever the system is, but I'm going to focus on Linux. Finally, I'm going to assume you can understand C programming, Makefile and assembly.

Objectives

The main objectives in this post are:

  • to make the microcontroller work
  • to make it work using my Linux (without the need of Windows or any proprietary software)
  • the total cost of components must be low (the project must be as cheap as possible)
  • it must be simple
Fortunately, all objectives were met.

What you need

Hardware

  • 1x ATmega8
  • 1x 28-pin socket (optional)
  • 1x USB-B connector (optional)
  • 1x DB-25 male connector (plus case)
  • 1x 220 ohms resistor
  • 3x 330 ohms resistors
  • about 1 meter of cable (with 5-wires or more)
  • a pair of male/female connectors with 5 pins or more
  • 1x breadboard (AKA protoboard)
  • many short wires
  • some LEDs and resistors
  • basic electronic tools (1) (2): soldering iron, solder, wire cutter, wire stripper (with practice, a pair of scissors can be used to strip wires), pliers, helping hands (1) (2)...

For the final version of any project, consider either making a PCB or using a stripboard. The project from this post, however, is just for learning the basics and, thus, won't generate anything useful at the end (except the knowledge acquired).

Software

  • A compiler: avr-gcc or tavrasm
  • A programmer: avrdude (old homepage) or uisp (or maybe PonyProg, but I haven't tried it)
  • ppdev Linux kernel module (Device Drivers -> Character devices -> Support for user-space parallel port device drivers)
  • giveio (direct download) (only for Windows, I don't know how this works nor how to install it)

Installing them on Gentoo:
emerge -av crossdev tavrasm avrdude uisp
crossdev -t avr
modprobe ppdev
Then, add your user (your ordinary user, not the root) to the lp group, or instead change the permissions of /dev/parport0.

Total cost

I already had the breadboard, some resistors, some leds and some wires. The other components I bought at Cerne-Tec (I went to their physical office in Rio de Janeiro). The prices here are in Brazillian Reais (R$). Today, US$ 1.00 = R$ 1.78.

  • R$ 9.90 - 1x ATmega8
  • R$ 1.00 - 1x 28-pin socket
  • R$ 4.00 - 1x USB-B connector
  • R$ 4.50 - 1x DB-25 male connector (plus case)
  • R$ 0.20 - 1x 220 ohms resistor
  • R$ 0.60 - 3x 330 ohms resistors
  • R$ 2.00 - about 1 meter of cable (with 5-wires or more)
  • R$ 1.50 - a pair of male/female connectors with 5 pins or more
  • R$ 23.70 - Subtotal (US$ 13.30)
  • R$ 4.60 - 2x subway tickets for transportation
  • R$ 28.30 - Total (US$ 15.90)

The ATmega16 was priced at R$ 24.90, which is a bit more than the total cost of all these components. There was also a large stripboard available for sale at around R$ 20.00 ~ R$ 25.00, which is almost the price of all these componentes together. Since I don't want to double this project cost, I'm using the breadboard I already have for now.

Note: There is no guarantee the prices will be the same at the time you go buy your components. I'm not affiliated with Cerne-Tec. The prices listed here are just for illustration.

Update at 2007-10-26: I found a small stripboard (about the exact size I need, maybe just a bit larger) for sale at R$ 2.50 at an electronic store near my house. I haven't bought it yet, but I'm probably going to.

Update at 2007-12-29: The USB-B connector turned out to not be needed for these experiments and was substituted by a simple USB cable (priced at R$ 2.79, or US$ 1.57). However, I know I'm going to use it sometime in future, in other project.

Overall plan of this project

Since I wanted to learn how to use the ATmega8, I wanted to make a simple "Hello, world" program and put it on the microcontroller. Well, my microcontroller does not have a terminal, a screen or an LCD to print something, so the "Hello, world" is going to be just some blinking LEDs. Also I need something to write the program into the microcontroller, so I need to build such tool.

So, these are the steps to be followed in this project:

  1. Build a simple, cheap and working AVR Programmer (part 2)
  2. Write a simple "Hello, world" for the microcontroller (part 3)
  3. Compile the "Hello, world" (part 3)
  4. Mount the microcontroller on the breadboard (part 4)
  5. Use the AVR Programmer to write the "Hello, world" to the microcontroller (part 4)
  6. Be happy and watch the blinking LEDs! (part 4)

See you at the next part!

Update at 2008-02-02: I've uploaded a video of this project at YouTube. Everybody loves videos, so check it out!

What if nVidia had an open source driver?First contact with ATmega8 microcontroller - part 2

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

Please type this security code : 12c5ae

Smilies

May 2008
SMTWTFS
April 2008June 2008
123
45678910
11121314151617
18192021222324
25262728293031