# Setting up a development environment for the ATTiny85 using Raspberry Pi 3 and avrdude

I’ve started looking at programming USB devices recently and wanted to set up a small development environment for some ATTiny85 chips I have. This first project was just to get a LED blinking. I programmed it using a Raspberry Pi 3b and some spare components. All the code for this project is available on my Github.

## Hardware

When wiring this up I set it up with two spaces on a breadboard, one where the chip is programmed and one where it blinks a LED.

## Configure the Raspberry Pi

I’m not very well versed in wire protocols but to program the chip I needed to enabled SPI and install a burner program, AVRDude. But first I installed some development libraries:

yum install git avr-libc
yum group install "Development Tools"


Enable SPI in the kernel:

cat >> /boot/config.txt <<EOF
dtparam=spi=on
EOF
reboot


I found a guide to install avrdude with SPI support by the guy who added the support:

git clone https://github.com/kcuzner/avrdude
cd avrdude/avrdude
./bootstrap && ./configure && make install


I made sure the linuxspi programmer in the avrdude config-file (/usr/local/etc/avrdude.conf) used the right gpio port for reset. Default is 25, I used 22:

programmer
id = "linuxspi";
desc = "Use Linux SPI device in /dev/spidev*";
type = "linuxspi";
reset = 22;
baudrate=400000;
;


Before programming the chip I had to burn some fuses. I followed the AVR fuses for beginners and ran:

avrdude -p t85 -P /dev/spidev0.0 -b 10000 -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m -c linuxspi


After this I could try it out with avrdude -p t85 -P /dev/spidev0.0 -c linuxspi :

I had some trouble when upgrading the kernel during the project and the /sys/class/gpio directory disappeared. I had to downgrade the kernel until I’ll be able to install an upgraded AVRDude with support for the new kernel API.

## Write the code & flash to chip

The following code will cycle the output power on portc once every half second, which makes the LED blink:

#ifndef F_CPU
#define F_CPU 1000000
#endif

#include <avr/io.h>
#include <util/delay.h>

int main(void) {

PORTB = 0xFF;
DDRB |= (1 << PB3);
while(1) {
PORTB = ~PORTB;
_delay_ms(250);
}

return 0;
}


I compiled this with the following Makefile:

CC=avr-gcc

.PHONY: install clean

all: build strip

clean:


Running make install in the source directory should now succeed: