Arduino is excellent for education: once you have achieved your goals you can dismantle your project and advance to the next stage.
But what if that project proved so useful that you want to keep it forever or at least for a long time or even distribute a lot of copies? Well, you can easily buy another Arduino and continue your class.
But in most cases there will be a much cheaper solution. Just check the amount of resources your project really needs. For example, take a look at the absolute minimum sketch:
So, if you successfully finished your project and are keen to keep it, just check if the resources it requires match the smaller chip. When you compile examples you find online you will find most of them will fit into an ATmega8. The good news is the pin assignement is exactly the same.
Unfortunately, there is another point to check: after compiling, it only will tell you the amount global variables. And of course, it is always recommended to keep variables as local as possible, so variables inside functions are not accounted for. If you are in doubt, make local variables to global ones and double-check for SRAM usage. Another restriction might be the number of PWM pins you need; the ATmega8 offers only pins 9, 10, and 11 as PWM-pins.
Direct access to Timer registers will be slightly different.
If all works well you can transform your project this way and keep your real Arduino for further studies.
Instructions: how to burn a sketch into a naked ATmega8 chip?Hardware first:The ATmega8 chip cannot be connected to the USB port of your computer, so another method has to be used. The good news is, any real Arduino is able to perform this task. You just need six short cables to connect both of them. And additionally, the little chip will need a clock source, so you have to add a quartz, 16MHz recommended. All is shown in this figure:
As you can see, the legs of that chip have numbers form 1 to 28, anticlockwise. Those number do not match the pin numbers when you use the digitalRead and digitalWrite function. You will find "cheat sheets" on the web.
Any kind of breadboard can be used, even the smallest ones. When you try to insert the chip most probably you have to bend the pins in order to fit into the holes. And check for the orientation: the chip name (sometimes printed black on black) must be readable, and there is a notch on the left side.
Next, insert the quartz in pins 9 and 10. Again, you have to bend the legs.
Now, make the six cable connections from the Arduino to the breadboard as shown above, and connect the Arduino to a USB port of your computer.
SoftwareBefore you start, check if you had selected →Tools→Arduino AVR Boards→Arduino UNO and check the USB port that is activated: →Tools→Port.
Now open →File→Examples→11.ArduinoISP and load this sketch. Do not modify it!
Compile and upload this sketch to your Arduino using this button
This Arduino has to act as a programmer for the ATmega8. In order to do this, you have to select →Tools→Programmer→Arduino as ISP. In case you repeat the whole procedure at a later stage you can omit this step unless you select another programmer in the meantime. Now is the time to select the target device:
→Tools→Board→Arduino AVR Boards→Arduino NG or older
But the NG or older came in two flavours: the ATmega8 and the ATmega168. Unfortunately, the default setting is ATmega168 and you have to modify it. The menu will show a new option:
→Tools→Processor
Select ATmega8.
Confirm that all your settings will be displayed in the bottom line of the IDE.
Now, all preparations are done. You can open and load the sketch you want to upload to the ATmega8. But to upload it you have to make use of the real Arduino to which it is connected.
If you have more ATmega8 chips to program you can just continue doing it without performing this long procedure.
When you are finished and want to use your Arduino as before, you have to select Arduino UNO as target device:
→Tools→Board→Arduino AVR Boards→Arduino UNO
In case you are not happy with the sketch you have transferred and need to modify it and you have redone all the steps shown above you have to start from the beginning. The manufacturer ATMEL (now taken over by Microchip) guarantees this procedure can be done at least 10000 times.
How to use the ATmega8?First of all, you have to find a power source. It can be anything that gives a stable 5-Volt supply, even 4 Volts might do. It could be a power bank, batteries, or a power adapter driven by the mains.
Be aware that there is no Serial monitor anymore. In case you still need one, you can feed the Serial output from pin-1 to a standard Arduino where you have SoftSerial running on some pin.
Some background information:As you know, the normal way to upload sketches to an Arduino is via USB and an additional small chip which is connected to the Serial pins d0 and d1. This requires a small program that resides in the Arduino. This program is called "bootloader" and it takes 512 bytes off the Arduinos FLASH memory. There exists also a bootloader for the ATmega8, but it has two disadvantages: firstly it takes 2048 bytes off the FLASH memory leaving only 6 Kbytes for your program, and secondly at power-on this bootloader will wait for 8 seconds before it starts to execute your program. In the unlikely case your ATmega8 was shipped with a bootloader, when you uploaded a sketch in the way shown above via ArduinoISP that bootloader will be overwritten, so there will be no more 8 seconds delay after power-on.
Comments
Please log in or sign up to comment.