AVRisp2 on Linux and Fabduino with Atmega 328
April 21st, 2013Tags: arduino, avr, avrisp2, fablab, linux, troubleshooting
grump grump grump grump…
So lately the fab lab inventory has been shipping with atmega328-aus and not atmega328ps or atmega168s so when we say you can make arduinos in the fablab this is true, but it is kind of annoying because of some non-standard stuff. Here’s some notes:
Part 1: We make new usb rules so that linux loads the avrisp2 correctly.
First we make a new file that will contain the rules about the avrisp mkii.
$ sudo gedit /etc/udev/avrisp.rules
Into this file, we paste
SUBSYSTEM!=”usb”, ACTION!=”add”, GOTO=”avrisp_end”
# Atmel Corp. JTAG ICE mkII
ATTR{idVendor}==”03eb”, ATTR{idProduct}==”2103″, MODE=”660″, GROUP=”dialout”
# Atmel Corp. AVRISP mkII
ATTR{idVendor}==”03eb”, ATTR{idProduct}==”2104″, MODE=”660″, GROUP=”dialout”
# Atmel Corp. Dragon
ATTR{idVendor}==”03eb”, ATTR{idProduct}==”2107″, MODE=”660″, GROUP=”dialout”
LABEL=”avrisp_end”
Then we will create a link to the new rules and give them priority:
$ cd /etc/udev/rules.d
$ sudo ln ../avrisp.rules 60-avrisp.rules
Then unplug and replug the avrispmkii and it should be usable without requiring root.
Grumble some, and see also this if you’re having trouble.
Part 2: We edit the avrdude.conf to include atmega 328s
The avrdude configuration file does not include this chip by default, so we have to edit it.
$ cd /etc/
$ sudo gedit avrdude.conf
then copy the ATmega328p entry, and paste it below it, but change the id to ‘m328′ and change the last 2 characters in the signature from 0F to 14.
Part 3: grump grmp
So in this part, we’re going to make a new boards.txt that will include the right options… when I figure those out.
Right now instead of doing this the right way, I am using the aforementioned avrisp2 to program both the bootloader and the new sketches like this:
First, set the fuses:
$ avrdude -P usb -c avrisp2 -p m328 -U lfuse:w:0xe2:m -U hfuse:w:0xd9:m -U efuse:w:0×07:m
Then, flash the optiboot 328 bootloader you copy from the arduino optiboot bootloader folder (under linux this would be /usr/share/arduino/hardware/arduino/bootloaders/optiboot):
$ avrdude -p m328 -P usb -c avrisp2 -U flash:w:optiboot_atmega328.hex -vvv
Then, set the avr’s lockbits so that when you program a new sketch it doesn’t overwrite them:
$ avrdude -P usb -c avrisp2 -p m328 -U lock:w:0×0F:m
Now if you want to upload a sketch, you can do so but only with the avrisp2 and using the “upload using programmer” option in arduino (under file>).
More later about uploading through the ftdi.