Use Atmega8/168 with Arduino UNO instead of atmega328p

Hi! I'm a proud owner of an Arduino UNO with an atmega328p chip on board. Many times I've thought about making standalone applications (parking sensor etc.) with the arduino, but the 328p chip is actually pretty expensive, and most of the time I don't need the 32 kb of space.

The atmega8/168 chip is much cheaper, and most of my applications don't require more than a few kilobytes.

Is it possible to burn atmega8 or atmega168 bootloader on the Arduino UNO board , and is it possible to program it with the UNO? Will it support all the functions that the 328p have?

Greetings!

Yes, you can do all that.

  1. Look at breadboarding an Arduino.
  2. Look at using your Arduino as an ISP programmer.
  3. Look at burning a bootloader.

For simple cheap projects, look at using the internal clock.
You can also load sketches without a USB to serial board. You can use you Arduino with the chip removed or use the ISP interface.

Good luck

If I'm using Arduino as an ISP programmer, does that mean I don't need to buy a standalone ISP programmer, like AVR ISP or USBtinyISP? Is it really possible to burn a bootloader with the 8u2? And after i've burned the bootloader, is it possible to remove the atmega328p and insert the atmega8 instead?

hansibull: If I'm using Arduino as an ISP programmer, does that mean I don't need to buy a standalone ISP programmer, like AVR ISP or USBtinyISP?

No you don't need a standalone programmer. However, if you get one for under $5, under $10 if you include the 10 pin to 6 pin adapter, I would consider that money well spent. But that's just me. I am looking to pick up a couple extra if I can get them cheap enough. They too can be used as development platforms. They have a small ATMega chip, crystal, USB interface, etc. Lots of nice stuff already on a board. Limited but useful.

Here is an interesting article. He talks about a specific board but the logic carries over to most of them. http://jethomson.wordpress.com/2011/08/18/project-ouroboros-reflashing-a-betemcu-usbasp-programmer/

hansibull: Is it really possible to burn a bootloader with the 8u2?

Probably but that's not what you want to do. Look at: http://arduino.cc/en/Tutorial/ArduinoISP

hansibull: And after i've burned the bootloader, is it possible to remove the atmega328p and insert the atmega8 instead?

I've never tried it (I don't have an Uno, yet). But it should work.

One thing you will need to do is lie to the Arduino IDE. Don't tell it you have an Uno with 328P, because you don't. You need to tell it you have something with an ATMega168 or ATMega8. The IDE uses this information to set compiler switches. So it can compile for different chips.

The first lie I would try is "Duemilanove w/ ATmega168"

You might need to define you own board. To do that you would need to edit "boards.txt". This is "one" place you can add your breadboard description. You might need a little help with the fuse bytes if you want to use the internal oscillator. I would also make sure I had a copy of the full datasheet (560+ pages) not the summary.

Hi, I have recently burned a batch of ATMega8's using an Arduino UNO and the optiloader sketch. Optiloader will detect that the target chip is an ATMega 8 and burn it with the correct bootloader.

All mine use a crystal or resonator for an external clock signal, this is the easiest way to start out, if you want to use the internal clock instead of external crystal or resonator you need to change the fuse settings in optiboot and possibly more, I have not yet tried this. Make sure that the clock is connected correctly when you burn your bootloader if you plan to use optiboot.

I also had to add a new board type to the Arduino IDE to be able to program the standalone Atmega 8's here are my settings from boards.txt -

opti8.name=Arduino Optiboot8

opti8.upload.protocol=arduino opti8.upload.maximum_size=7680 opti8.upload.speed=115200

opti8.bootloader.low_fuses=0xbf opti8.bootloader.high_fuses=0xdc opti8.bootloader.path=optiboot opti8.bootloader.file=optiboot_mega8.hex opti8.bootloader.unlock_bits=0x3F opti8.bootloader.lock_bits=0x0F

opti8.build.mcu=atmega8 opti8.build.f_cpu=16000000L opti8.build.core=arduino opti8.build.variant=standard

I use a USB to Serial programmer, its so much easier than fiddling about trying to get chips in and out of the UNO without breaking them, it also allows me to leave a six pin programming header on my standalone projects for future updates.

Heres an ATMega 8 bootloaded with opti boot and loaded with Arduino Code using the settings above and the Arduino IDE, the six pin header in the top left is the programming header, the blue blob half way up the chip is a 16Mhz resonator for the clock. The only other components are a 7805 regulator, diode and supporting caps for 5v power (the other bits on the right are a L293 motor driver and supporting components) -

And in action with the motor driver here -

http://rcarduino.blogspot.com/2012/05/rc-arduino-robot.html

Duane B

rcarduino.blogspot.com

OK, so if I want to burn a bootloader on the Atmega8, I hook up this circuit:

Then I upload the ArduinoISP code to my Arduino UNO, and choose the board "Arduino NG or older w/ Atmega8" or "duemilanove w/ Atmega168", and then "burn bootloader" and choose "Arduino as ISP", Is that right.

But after I've burned the bootloader, do I still keep the circuit (picture above), or do I have to make a new one? And after the bootloader is burned in, what board do I choose in the IDE? Arduino UNO, Duemillanove w/atmega168 or NG?

I think I will stick to the external oscillator in a couple of weeks, since I don't have any experience with the compiler and the techie bootloader stuff. But is there a guide out there that can tell me how to use the internal oscillator. That would be very nice ;)

You have the right hook up. You are looking at 6 connections, in particular order. 1) 5V 2) Gnd 3) Reset 4) MOSI 5) MISO 6) SCK

hansibull: Then I upload the ArduinoISP code to my Arduino UNO, and choose the board "Arduino NG or older w/ Atmega8" or "duemilanove w/ Atmega168", and then "burn bootloader" and choose "Arduino as ISP", Is that right.

That is right. However, if you want to try running without a crystal, this is what I did.

I updated the boards.txt file by adding the following to the end.

BB1.name=Breadboard w/ ATmega328 Internal Oscillator

BB1.upload.protocol=arduino BB1.upload.maximum_size=30720 BB1.upload.speed=57600

BB1.bootloader.low_fuses=0xE2 BB1.bootloader.high_fuses=0xDA BB1.bootloader.extended_fuses=0x05

BB1.bootloader.path=atmega BB1.bootloader.file=ATmegaBOOT_168_atmega328.hex BB1.bootloader.unlock_bits=0x3F BB1.bootloader.lock_bits=0x0F

BB1.build.mcu=atmega328p BB1.build.f_cpu=8000000L BB1.build.core=arduino BB1.build.variant=standard

The important line for using the internal clock was: BB1.bootloader.low_fuses=0xE2 Of course I needed to change the clock from 16000000L to 8000000L.

hansibull: But after I've burned the bootloader, do I still keep the circuit (picture above), or do I have to make a new one?

You can keep it breadboarded like you have. If you need to load a script, you can use the same setup for that as well. File -> Upload Using Programmer

hansibull: And after the bootloader is burned in, what board do I choose in the IDE? Arduino UNO, Duemillanove w/atmega168 or NG?

If you use the same setup to load you sketch, you just need to make sure you have the chip and clock correct.

What do you want to do? What would make you development easiest?

Hi,

I would use the optiloader sketch loaded on the UNO, It will detect the ATMega8 and put the correct boot loader onto it if you use the circuit you linked.

Duane B

DuaneB: I would use the optiloader sketch loaded on the UNO, It will detect the ATMega8 and put the correct boot loader onto it if you use the circuit you linked.

I would not load anything on the UNO. I might load the "optiloader" on to the new ATMege8 or 168 but I would leave the UNO just as it is.

You could and if you did -

You would load optiloader as a sketch onto the UNO. Assuming that the UNO is wired to the ATMega8 as shown in the picture, the Optiloader sketch running on the UNO would detect the target chip, detect its type as an ATMega8 and load the correct version of the 'optiboot' boot loader on the 8.

Its all very standard and a very common procedure, you can even put a 328 as the target and the sketch will detect it and put the correct bootloader onto it, you can spend all day putting 8s, 168s and 328s in and out all of them will get the correct boot loader and nothing gets broken in the process.

Heres a link to optiloader https://github.com/WestfW/OptiLoader

For how to's etc search for it here, or on your favorite video site.

When you are finished using your UNO to upload bootloaders to your target chips, just carry straight on and use it as a normal UNO, nothing has changed.

Duane B

Duane B, I am unfamiliar with the OptiLoader sketch. I assume that this can be used instead of the ArduinoISP sketch.

When I read your message I assumed you where referring to the optiboot bootloader, which of course I would not put on the Uno. The Uno isn't broke, I would not try to fix it.

I think I would still use the ArduinoISP sketch. There is much more documentation and support for this. Someone new to all this may want to stick with the familiar. So unless there is an overriding advantage to using the OptiLoader or there is a required function that the ArduinoISP does not provide, I would at least start there.

Ok. I bought some Atmega8 chips, and I have burned the bootloader (ArduinoISP with an Arduino UNO) and uploaded some test code successfully. I also tried the optiloader thing, and it said that the bootloader was burned into the Atmega8 successfully. but when I trid to program it (removed the original 328p), I got a message that said "avrdude: stk500_recv(): programmer is not responding"

I've read that if I want to use the internal oscillator in the atmega8, I need to use optiloader or similar. Why do I get this error, and is it possible to run the Atmega8 with it's internal oscillator using the ArduinoIPS sketch?

I will try to answer your question. If is screw it up, I assume that someone will correct me. Remember, free advice is worth what you paid for it.

Q) Can you use the internal oscillator?
A) I have done it.
Equivocate) I used an ATMega328 but I assume that ATMega8 would also work.

AS for your error message, I’m not sure where or how you are getting that. I also don’t know which bootloader you burned. For the ATmega8 I would assume you used “ATmegaBOOT.hex”. This is the bootloader you would get if you told the IDE you had a “Arduino NG or older w/ ATmega8”.
The board is a 16 mHz and uploads at 19.2k baud

If you want to use the ATMega8, use the interal oscillator, and upload sketches via the serial port … you still have some work to do.

About the Optiboot thing.

Linke I wrote, I burned in an optoboot bootloader into my atmega8. (using Optiloader on my arduino Uno w/328p) I updated the boards.txt, and added this text:

opti8.name=Arduino Optiboot8
opti8.upload.protocol=stk500
opti8.upload.maximum_size=7680
opti8.upload.speed=115200
opti8.bootloader.low_fuses=0xff
opti8.bootloader.high_fuses=0xc8
opti8.bootloader.path=optiboot
opti8.bootloader.file=optiboot_atmega8.hex
opti8.bootloader.unlock_bits=0x3F
opti8.bootloader.lock_bits=0x0F
opti8.build.mcu=atmega8
opti8.build.f_cpu=16000000L
opti8.build.core=arduino
opti8.build.variant=standard

When I tried to upload the Blink led example (Ive extracted the original 328p in my UNO, and inserted the 8'), I get the error:

avrdude: Yikes! Invalid device signature. Double check connections and try again, or use -F to override this check.

I have chosen the Arduino Optiboot8 from the boards menu.

What is wrong? is it the boards.txt file?

Thanks for any help! :)

Here is my ATMega8 entry from boards.txt if it helps -

opti8.name=Arduino Optiboot8

opti8.upload.protocol=arduino opti8.upload.maximum_size=7680 opti8.upload.speed=115200

opti8.bootloader.low_fuses=0xbf opti8.bootloader.high_fuses=0xdc opti8.bootloader.path=optiboot opti8.bootloader.file=optiboot_mega8.hex opti8.bootloader.unlock_bits=0x3F opti8.bootloader.lock_bits=0x0F

opti8.build.mcu=atmega8 opti8.build.f_cpu=16000000L opti8.build.core=arduino opti8.build.variant=standard

I use it to program lots of ATMega8's on breadboard and strip board using external crystals or oscillators. Also check the full name of your ATMega8 chips, I recently bought some that were limited to 8mhz by mistake - I guess they would also have a different device signature.

Totally off topic, but its a ATMega8 inside this -

http://rcarduino.blogspot.com/2012/07/rcarduino-yaw-control-part-2.html

Duane B

rcarduino.blogspot.com

WOOOOW!!

THANKS ALOT!

with the part of your boards.txt, it finally working! :D :D

Thank you SO much!

Just picked up a atmega8535 (Hobson's choice at my local hardware shop)

Will comments here about using atmega8 apply to this chip as well?

Thanks.

You need to find a bootloader for your atmega chip. If you can find that, I think you'll be OK ;)

In comment #4 Duane says:

I also had to add a new board type to the Arduino IDE to be able to program the standalone Atmega 8's here are my settings from boards.txt -

opti8.name=Arduino Optiboot8

opti8.upload.protocol=arduino opti8.upload.maximum_size=7680 opti8.upload.speed=115200

opti8.bootloader.low_fuses=0xbf opti8.bootloader.high_fuses=0xdc opti8.bootloader.path=optiboot opti8.bootloader.file=optiboot_mega8.hex opti8.bootloader.unlock_bits=0x3F opti8.bootloader.lock_bits=0x0F

opti8.build.mcu=atmega8 opti8.build.f_cpu=16000000L opti8.build.core=arduino opti8.build.variant=standard

I use a USB to Serial programmer,

So if I'm following him correctly his prototype board with just the Atmega 8 can be programmed directly using the IDE. The config above ensures the right information for the chip is used in creating the optiboot image.

The usb-serial programmer is presumably a non intelligent hardware interface that converts usb input to ISP serial on MISO MOSI pins. In that case why the need for boot loader?

I'm probably misunderstanding something about what he's doing.

Can anyone put me straight?

thx

The config above ensures the right information for the chip is used in creating the optiboot image.

No, you'll still need to build the optiboot image yourself (or use the existing .hex file.) The info in the boards.txt file is used for compiling the user sketches, uploading the sketches via the bootloader OR via a device programmer, and for the "burn bootloader" command.

The usb-serial programmer is presumably a non intelligent hardware interface that converts usb input to ISP serial on MISO MOSI pins. In that case why the need for boot loader?

Most programmers are somewhat intelligent. They do things like check the device type, and convert "high level commands" (like "what device type are you", or "program these 64 bytes of flash at the specified address") to the appropriate AVR ISP commands on the SPI signals. All sort of necessary since there's no obvious exact translation between usb (or any other typical desktop PC interface) and SPI. (at any rate, there wasn't, in the timeframe when Atmel was specifying ISP protocols.) The bootloader substitutes for the intelligence in the programmer, permitting the AVR to modify its own flash over a dumb data connection.