In the previous post we saw how to program the Arduino bootloader on a standalone Atmega328, while in another post we saw how to upload the sketch to the microcontroller with Arduino bootloader on board.
In this post I want to highlight what I believe is the ultimate goal of the projects prototyped with Arduino: program the ATmega328 without a bootloader, so that our programs can completely override the flash of the microcontroller.
But why do we do it? The main advantages are the immediate execution of our program when the Atmega power on, and more space for our programs in the memory of the microcontroller. The disadvantage is the fact that it is no longer possible to program via simple serial (less than reload the bootloader), but we must use a dedicated programmer (or a ArduinoISP) and the time to upload the sketch is a lot longer. I advise you to use this mode only on finished project, while using the Arduino bootloader when we are debugging our programs (with continuous uploads).
But we come to practice. The programming is implemented in the same way as the previous post, with a slight modification. We need to edit the usual file “boards.txt”, and add the line xxxxxxx.upload.using = arduino: arduinoisp in the configuration of the board that we are interested in programming, where xxxxxxx is the name of the board. We make a practical example, lets take the configuration to be included in boards.txt we saw the last time for the Atmega at 8MHz: with this new addition would thus become:
############################################################## atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock) atmega328bb.upload.protocol=stk500 atmega328bb.upload.maximum_size=32768 atmega328bb.upload.speed=57600 atmega328bb.upload.using=arduino:arduinoisp atmega328bb.bootloader.low_fuses=0xE2 atmega328bb.bootloader.high_fuses=0xDA atmega328bb.bootloader.extended_fuses=0x05 atmega328bb.bootloader.path=arduino:atmega atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex atmega328bb.bootloader.unlock_bits=0x3F atmega328bb.bootloader.lock_bits=0x0F atmega328bb.build.mcu=atmega328p atmega328bb.build.f_cpu=8000000L atmega328bb.build.core=arduino:arduino ##############################################################
With this addition, we specify that the upload of the sketch does not have to end up on our Arduino UNO, but on the Atmega we want to program.
Also note the change (optional) atmega328bb.upload.maximum_size whose value becomes 32768. Basically it is the maximum space in bytes available to load our sketch. There is no longer the bootloader so the freed space is available to us.
1 – We upload by the IDE (version 0022) the example sketch ArduinoISP on our Arduino UNO
2 – We turn off everything and then connect a 22uF capacitor between RESET and GND of the Arduino UNO
3 – We Connect pin 10 of Arduino UNO to the RESET pin of the Atmega and pins 11,12,13 to pins 17,18,19 of the microcontroller (or pins 11,12,13 of another Arduino board) as shown in Figure :
4 – We do upload the sketch using the traditional command File -> Upload to I / O board
And that’s it … We programmed the microcontroller to work standalone without Arduino bootloader and without (or almost) external components.
As you can see it is very simple and allows us not only to program the ATmega328 standalone, but also a full Arduino board.
For example I use this system with the Arduino Mini Pro. These are budget boards, which have nearly all the features of the Arduino UNO, but they are very small. Usually, instead of using a standalone Atmega328 within a well-defined project, I use these small boards, and once everything is ready to be canned, I upload the sketch bypassing the bootloader, in particular to make faster ignition.
The Arduino Pro Mini is produced by Sparkfun and is available in 3.3V or 5V and with ATmega168 or ATmega328. I would recommend if the sketch does not exceed 16kB to use the ATmega168 and the 8Mhz version at 3.3V especially if your project is running on battery because it consumes a lot less.
Obviously during programming we have to select the corresponding tab from the list of boards, for example Arduino Pro or Pro Mini (5V, 16 MHz) w / ATmega168.
But the fun does not stop there …
With this system we can also program the ATtiny, the younger brothers of the Atmega. There are several versions but the most interesting are the 8-pin ATtiny85 and the 20-pin ATtiny2313. They have the advantage that consume very little power, are smaller and cheaper.
The ATtiny85 has only 5 I/O, but for many projects is just fine, considering the cost of about € 2.50 in Italy.
Moreover working with internal clock to 1Mhz consumption is really very low, and the size is like that of a NE555.
Can u think how many projects we can simplify using the ATtiny. Even only for example a PWM control of a LED strip, which would usually require operational, capacitors, NE555, and so on, with a simple ATtiny85, a potentiometer, a transistor, a few other components and 2 lines of code, the game is done…
In the next post then!