ATtiny85 - programming using an Arduino
Proud owner of three new ATtiny85 chips, I set out to program them using my Arduino. I didn’t have a dedicated programming device, so I chose to follow the promising tutorial for Arduino-based ATtiny programming published by MIT’s High-Low Tech group.
The tutorial is very helpful, but along the way I encountered three problems not mentioned there, and I thought I’d share them here for anyone having trouble.
1. Bootloader burn error - Attempting to burn a bootloader to the ATtiny, I got the following error from avrdude (for those unfamiliar, this is the software embedded within the Arduino IDE that does the actual device programming):
avr_read(): error reading address 0x0000
read operation not supported for memory "lock"
avrdude: failed to read all of lock memory, rc=-2
Apparently, there’s an incompatibility (follow the bug here) between the current Arduino IDE and avrdude that causes this issue. Following a suggestion found on the Arduino message boards, I changed the avrdude.conf file (located within the Arduino package) by adding the below text that’s in bold:
#------------------------------------------------------------
# ATtiny85
#------------------------------------------------------------
part
id = "t85";
desc = "ATtiny85";
[lots of stuff here not included in this post]
memory "lock"
size = 1;
write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x",
"x x x x x x x x 1 1 i i i i i i";
read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0",
"0 0 0 0 0 0 0 0 o o o o o o o o";
min_write_delay = 9000;
max_write_delay = 9000;
;
2. Missing reset pull-up - The tutorial was written for the Arduino Uno, while I had a Duemilanove. The instructions specify that on the Uno, a capacitor is needed between the reset and ground pins, apparently to keep the Arduino from resetting itself during programming. For me, the resetting resulted in this error:
avrdude: stk500_getsync(): not in sync: resp=0x15
Following the above advice, I added a 110 ohm resistor (well, I actually used three 330 ohm resistors in parallel since I didn’t have a 110) between +5v and RESET, which solved this issue. The doc states that the resistance must be between 110 and 124 ohms.
3. Crash during programming due to serial buffer overflow. After solving the reset issue, the Arduino would hang during programming. The “heartbeat” LED would freeze, so I knew that the ArduinoISP program on the device was crashing. Enabling verbose output in the Arduino preferences helped me see that the program data was being sent to the ATtiny but that it was halting halfway through, then timing out after the halt with the same sync error:
avrdude: stk500_getsync(): not in sync: resp=0x15
Apparently, this is a bug that’s been fixed for Arduino v 1.0.1 - I followed the instructions in the report and increased the serial buffer size in HardwareSerial.cpp from 64 to 128.
After this change, it finally worked, and my ATtiny85 was happily blinking an LED.