And finally i have some time to develop on microcontroller! The choice was pretty hard, since i wanted to avoid all problems with toolchains and operating systems. My choice went on Atmel Attiny line, i could have chosen the PIC family but i was able to find more data on Atmel Attiny. And having a Raspberry Pi building a simple programmer is really easy.
This tutorial cover both ATiny85 and ATtiny88. In the future will cover ATtinyX61 series.
My idea was base on an Instructables tutorial Programming the ATtiny85 from Raspberry Pi from prb3333
This page is licensed under Attribution Non-commercial Share Alike (by-nc-sa) license.
No responsability is taken by the author for any kind of damage caused directly or indirectly by the content in this website including, but not limited to, people, things, environment.
You will need: * Raspiberry Pi * ATtiny85 or ATiny88 chip * 5 x 1K resistors (or similar) * LED of your choice * Prototyping breadboard * Connection cables for Raspberry Pi GPIO (6 wires)
This will be used to communicate to the ATtiny and to build the compilation toolchain. It may take a while to be completed, so go prepare a coffe in the meantime :)
sudo apt-get install bison automake autoconf flex git gcc
sudo apt-get install gcc-avr binutils-avr avr-libc
git clone https://github.com/kcuzner/avrdude
cd avrdude/avrdude
./bootstrap && ./configure && sudo make install
This will be needed to use easily the GPIO from the Pi.
cd ~
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
The pinout of Pi GPIO is valid for both Rev.A and Rev.B Raspberry. Note that the last pin is connected only to the ATtiny. This is used with the led to verify that everything works as expected.
The schematics is valid for both the microcontrollers. Only mind the pinout.
''Attiny85 Pins'':
Pi GPIO ATtiny85 Description and wire colour
15 1 GPIO22 to Reset (through 1K, Blue wire)
17 8 3.3 V (Green wire)
19 5 MOSI (through 1K, Yellow wire)
21 6 MISO (through 1K, Orange wire)
23 7 SCLK (through 1K, Red wire)
25 4 GND (Brown wire)
NA 3 B group GPIO for ATtiny (I used Black wire)
''Attiny88 Pins'':
Pi GPIO ATtiny88 Description and wire colour
15 1 GPIO22 to Reset (through 1K, Blue wire)
17 7 3.3 V (Green wire)
19 26 MOSI (through 1K, Yellow wire)
21 25 MISO (through 1K, Orange wire)
23 24 SCLK (through 1K, Red wire)
25 8 GND (Brown wire)
NA 9 B group GPIO for ATtiny (I used Black wire)
We connected the GPIO22 of the Pi to the ATtiny reset pin. This pin must be set low to program the ATtiny. If all operations had been successful no error should be shown on terminal window.
For the ATTiny85:
sudo gpio -g mode 22 out
sudo gpio -g write 22 0
sudo avrdude -p t85 -P /dev/spidev0.0 -c linuxspi -b 10000
sudo gpio -g write 22 1
For the ATTiny88:
sudo gpio -g mode 22 out
sudo gpio -g write 22 0
sudo avrdude -p t88 -P /dev/spidev0.0 -c linuxspi -b 10000
sudo gpio -g write 22 1
Now we will create the "blinker" prject:
cd ~
mkdir ATtiny
cd ATtiny
mkdir blinky
cd blinky
Create the "blinky.c" file into the just created directory
#define F_CPU 1000000L #include <avr/io.h> #include <util/delay.h> int main(void) { DDRB = 0xFF; // PORTB is output, all pins PORTB = 0x00; // Make pins low to start for(;;){ PORTB ^= 0xFF; // invert all the pins _delay_ms(100); // wait some time } return 0; }
And the "Makefile" file. There must not be spaces at the beginning of lines. All beginning of lines with spaces must be tabs!!!
Note that the first two lines must be changed for the ATtiny85:
MCU=attiny85 AVRDUDEMCU=t85
MCU=attiny88 AVRDUDEMCU=t88 CC=/usr/bin/avr-gcc CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=$(MCU) OBJ2HEX=/usr/bin/avr-objcopy AVRDUDE=/usr/local/bin/avrdude TARGET=blinky all : $(CC) $(CFLAGS) $(TARGET).c -o $(TARGET) $(OBJ2HEX) -R .eeprom -O ihex $(TARGET) $(TARGET).hex rm -f $(TARGET) install : all sudo gpio -g mode 22 out sudo gpio -g write 22 0 sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:$(TARGET).hex sudo gpio -g write 22 1 noreset : all sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:$(TARGET).hex fuse : sudo gpio -g mode 22 out sudo gpio -g write 22 0 sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m sudo gpio -g write 22 1 clean : rm -f *.hex *.obj *.o
Then compile the whole thing and install it on the ATtiny:
make install
Now the led should blink happily!!
Just to ease the development: