
Doubling the Arduino Flash Memory once again
Times really flys when you're having fun - it has been more two years since I posted this journal entry about how to double the Arduino board's Flash memory by replacing the ATmega8 with an ATmega168 microcontroller. Lots has changed since then, e.g. the Arduino project now includes several board designs and layouts, most of which feature the ATmega168.
For the last couple of months now, the even better AVR 8-Bit RISC ATmega328P micro-controller was hard get. However, it's now more broadly available and four of these 8-Bit Micros have arrived today, shipped form one of my favorite Online-Electronics stores: SparkFun. The ATmega328P features 32 KBytes of Flash, 2 KBytes of RAM, and 1 KByte of EEPROM a nice improvement over Arduino's original configuration with an ATmega8: (8 KBytes of flash, 1 KByte of RAM, and 512 Bytes of EEPROM).
Time to revisit the Arduino Project, an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software, intended for anyone interested in creating interactive objects or environments.
For the last couple of months now, the even better AVR 8-Bit RISC ATmega328P micro-controller was hard get. However, it's now more broadly available and four of these 8-Bit Micros have arrived today, shipped form one of my favorite Online-Electronics stores: SparkFun. The ATmega328P features 32 KBytes of Flash, 2 KBytes of RAM, and 1 KByte of EEPROM a nice improvement over Arduino's original configuration with an ATmega8: (8 KBytes of flash, 1 KByte of RAM, and 512 Bytes of EEPROM).
Time to revisit the Arduino Project, an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software, intended for anyone interested in creating interactive objects or environments.
Burn Baby Burn .. Again
The ATmega328 comes in the same 28-lead PDIP packaging and replacing the chip was straight forward and took only a couple of seconds; burning the boot loader on the other hand - just like last time - took a little longer. The Arduino board has the AVR typical 6 header ICSP, an in-system programming port, which allows burning a boot loader without removing the microcontroller chip from the board. At least for Mac users, I recommend AVR's AVRISP mkII (ATAVRIPS2-ND), available for $34 at DigiKey.The AVRISP can program newer 8-bit RISC microcontrollers (with ICSP Interface) through the USB port. The target board still needs to be powered and its regular ports should be disconnected from other devices.

Since switching form the ATmege8 to the 16, the Arduino's Development Environment has also switched to avrdude, the software that loads programs from your machine onto the chips - manipulates the ROM and EEPROM contents of AVR microcontrollers. To use avrdude successfully with the new ATmega3258P, you may need to update its configuration file somewhere like here: /Applications/arduino-0013/hardware/tools/avr/etc, (look for the configuration file in the Resources areas below).
Preparation ...
At this point, the Arduino's microcontroller had been replaced with the 32 KByte ATmega328P and everything but the ICSP port had been disconnected. The Arduino board itself was powered by a 7.5V 500mA power supply and the AVRISP-mkII connected the board with the Mac's USB port.On the software side, avrdude 5.5 was installed, the avrdude.conf file had been updated, and the ATmega328 boot-loader was made available here /AT328.hex, (look for the configuration file in the Resources areas below).
Burning, Fuses, and Flashing the Bootloader
Burning a new boot loader is a three-step process: unlocking the boot loader segment, uploading the new boot loader, and looking boot loader segment again. For an AVR microcontroller, the closest thing to a configuration file is its set of fuses. Fuses are used to configure important system parameters and a few important but obscure options can only be set through the ICSP. For instance, the ATmega328 defaults to the use of a 1 MHz internal clock and would ignoring the 16 MHz crystal on the Arduino board, if not told otherwise, through a fuse setting.- Unlocking the boot loader segment, erase the chip, and set fuses (set boot loader size to 2K words [=2KByte]: 0x3800-0xFFFF, set clock speed to external 16 MHz)
avrdude -p m328p -b 115200 -P usb -c avrispmkII -V -e -U lock:w:0x3F:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m -U efuse:w:0x03:m - Uploading the boot loader
avrdude -p m328p -b 115200 -P usb -c avrispmkII -V -D -U flash:w:/AT328.hex:i - Re-locking the boot loader segment
avrdude -p m328p -b 115200 -P usb -c avrispmkII -V -U lock:w:0x0F:m
Burn Log
Arduino IDE
Arduino IDE - Font Rendering OS X
The Arduino IDE is a Java application that when run on Mac OS X does not turn Font Smoothing on. If you rather see the fonts a little less pixely, open Arduino's Info.plist (right-click the Arduino Icon and select 'Show Package Content') and insert the Java Property swing.aatext=true.The Fibonacci program was quickly uploaded and running - the IDE reported Binary sketch size: 2020 bytes (of a 30720 byte maximum), which makes sense, considering that we set the efuse to preserve 2K words for the boot loader.

[Arduino IDE after uploading a program]
Fibonacci Program Output for the 1st 39 fibs
Resources
- ATmega48P/88P/168P/328P Preliminary Summary (28 pages, revision G, updated 1/09)
- ATmega48P/88P/168P/328P Preliminary (451 pages, revision G, updated 1/09)
- avrdude.conf containing the ATmega328P definition
- Arduino bootloader for the ATmega328P 8-Bit RISC Micro
- boards.txt configuration, needed by the IDE to
Arduino related posts at wolfpaulus.com
- Arduino, an open-source platform, Pt.1
Small hack increases available memory by 6% - Arduino, an open-source platform, Pt.2
Replacing the ATmega8 w/ ATmega16 incl. bootloader burning. - Arduino, an open-source platform, Pt.3
ATmega 8 / 168 internal clock and fuse settings - Arduino, ATmega328
Doubling the Arduino Flash Memory once again - Arduino Fever - PHYSICAL COMPUTING
Slides

[Arduino NG board with the ATmega328P-PU 8-Bit RISC Micro Controller]