These instructions tell you how to setup and program the ATtiny85 microcontroller from a Raspberry Pi via the SPI interface. Lots of people use the Ardiuno to do this (then you can use the Arduino IDE and simplified C commands), or you can use a USB based programmer. I do not have an Ardiuno and don't want to buy a dedicated programmer. I do have a Pi, so I was pleased to learn I could use it as a way to get into microcontroller programming.

You will need:
Raspiberry Pi
ATtiny85 chip
5 x 1K resistors (or similar)
LED of your choice
A connection to the GPIO of the Pi, and a breadboard and wire.

Based on http://www.instructables.com/id/How-to-program-ATt...
and http://www.raspberrypi.org/phpBB3/viewtopic.php?t=...
and http://www.instructables.com/id/RGB-LED-Mood-Light...

Step 1: Setup the Raspberry Pi

At the terminal of the Pi:

Download and build avrdude

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

Setup SPI on the GPIO

sudo raspi-config
and Enable SPI device in the Advanced Options (see picture)
You can check this at the command line with lsmod, no need to reboot. (Maybe need to sudo modprobe spidev)

Download and build WiringPi for the gpio commands

cd ~
git clone git://git.drogon.net/wiringPi
cd wiringPi


<p>I am lost when it comes to coding... Where should the TABS go? Can someone please post a picture of the correct code?</p>
<p>Hi,</p><p>I have the code on Github now:</p><p><a href="https://github.com/paulbarber/ATtiny85_RaspberryPi/tree/master/blinky" rel="nofollow">https://github.com/paulbarber/ATtiny85_RaspberryPi...</a></p><p>Cheers!</p>
<p>Thankyou so much! I had purchased 10x ATtiny84a's and had no idea, until I stumbled upon this. Much Appreciated:) </p>
<p>Thank you so much, I have made it work with my Atmega8-16PI and will try with the Atmega8535-16PI</p>
<p>Hi, this helped me to get going, but you should update/change one thing.</p><p>After reading this post: <a href="http://kevincuzner.com/2013/05/27/raspberry-pi-as-an-avr-programmer/" rel="nofollow">http://kevincuzner.com/2013/05/27/raspberry-pi-as-...<br></a>I noticed that the 'linuxspi' programmer by default uses the GPIO pin 25 for reset, so your reset wrapper script is not needed. Else, great work ;)</p>
<p>Thank you.</p>
<p>This is a fantastic tutorial, and it really helped me get started. I'd like to point out a couple things I learned along the way, however. I don't know about at the time you were doing this project, but the &quot;linuxgpio&quot; configuration for avrdude exists in /etc/avrdude.conf on the RPi (after you install avrdude, of course); you simply uncomment the lines and set the pins to what they should be. Second, because the AVR and the RPi both run at 3.3v, I didn't find any need to use resistors for anything other than the LED itself, and that was only to protect the LED. And finally, if you hook the LED's positive pole to one of the SPI pins, the LED will happily blink for you as the RPi uploads data, which is cool and gives some nice feedback!</p>
<p>Oh, and I used this with an ATmega88; I'm sure you can use it with any ATmega that supports 3.3v operation, which, for all I know, is all of them.</p>
<p>Works with atmega8. When I poweroff the Raspberry Pi the Reset pin GPIO 22 gets to zero, stopping the program on the microcontroller. I added a pullup resistor of 10 k to 3.3 v to GPIO22 and now it works after Pi poweroff too :) . Thank you. I made it but I don't yet have a camera / photo capable phone so no images...</p>
Is it possible to program Atmega8-8PU using this?
<p>Thank you! Thank you! Thank you! My L.E.D.s are flashing, and my stepper motor is spinning. I could not have gotten this far this fast without your VERY helpful Instructable!</p>
<p>i dont know nothing about makefile, could you help me, which is the path where the file should be, i have to paste or create a new file ? </p>
<p>hi im having this error&quot;28:*** target pattern contains no '%' .Stop</p><p>Can anyone help me with this....</p>
<p>On the strength of getting blinky to work following this instructable (thanks for that), I thought I'd use what I'd learnt to install Atmel's TWI Bootloader on a ATTiny85 (Atmels Application Note: AVR112).</p><p>Unfortunately I fell at the first hurdle running the 'make' with error </p><p> 'fatal error: ioavr.h: No such file or directory'</p><p>Has anyone done this successfully? If so, some pointers on getting passed this would be much appreciated.</p>
<p>Problem solved by replacing lines:</p><p>#include &lt;ioavr.h&gt;<br>#include &lt;inavr.h&gt;</p><p>with:</p><p>#include &lt;avr/io.h&gt;</p><p>Running the 'make' again gives error message:</p><p> Common_Define.h:164:1: error: unknown type name &lsquo;__no_init&rsquo;</p><p>Line 164 in Common_Define.h is:</p><p>__no_init uint8_t pageBuffer[PAGE_SIZE];</p><p>Can anyone throw some light on why code from Atmel doesn't seem to work?</p>
<p>I try to upload this code instead of blinky but i got a lot of error and i don't know why if someone can help me</p><p><a href="http://www.instructables.com/files/orig/F95/O60L/I45HOS1E/F95O60LI45HOS1E.txt" rel="nofollow">http://www.instructables.com/files/orig/F95/O60L/I...</a> from <a href="http://www.instructables.com/id/MASON-JAR-MOOD-LAMP/?ALLSTEPS" rel="nofollow">http://www.instructables.com/id/MASON-JAR-MOOD-LAM...</a></p><p>PS : It works perfectly when i upload blinky</p>
<p>Hi,</p><p>That code uses the Arduino code libraries (&quot;digitalWrite&quot; etc.). You can program these devices that way but I do not cover it here.</p><p>I am using the avr-libc library. By the way this gives you the possibility to have three pwm outputs from the ATtiny85. I have mood light code I have used in the past, it's here:</p><p><a href="https://gist.github.com/paulbarber/fd0467d912f3a2d644bd" rel="nofollow">https://gist.github.com/paulbarber/fd0467d912f3a2d...</a></p><p>I hope you can work out from the comments what the circuit should be like.</p><p>Cheers,</p><p>Paul.</p>
Thanks for the help i understand why it doesn't work now.<br>I gonna try to directly upload the hex generate by arduino and if it doesn't work i gonna use your code to make mine.<br><br>Thanks again
<p>Works good! thankyou!</p><p>I made it work with my custom ATmega32u4 board. I had to supply it with an external 3.3v supply. </p><p>Later I plan to supply with wiht USB power (5V) but im still waiting for my level converters to come in the mail. </p>
<p>Hello and Thank you for your Tutorial.</p><p>But i have a few problems.</p><p>When i run make install it flashes ok, but i receive failure:</p><p>&quot;avrdude verification error content mismatch&quot;</p><p>and &quot;avrdude safe mode lfuse changed&quot;</p><p>What i doing wrong ?</p><p>I am trying to programm attiny45 </p>
<p>Hello and thank you for tutorial. </p><p>But i have a problem. I would like to program Attiny45 and when i run make install ist says :</p><p>avrdude verification error content mismatch</p><p>avrdude safe mode louse changed, was 62 and now is 0</p><p>and when i set y to change fuse back then it freeze ...</p><p>Could you please help me</p>
<p>Very straightforward tutorial. Used it with the ATtiny25 and worked well. Thank you!</p>
<p>Many thanks! Your suggestion was spot on!!!!</p>
<p>Hello, I've followed your tutorial and get as far as 'Makefile'. When I run the 'make' command I get .....</p><p>'Makefile:9: *** missing separator. Stop'</p><p>Any help would be appreciated.</p>
<p>Probably a lack of tabs. You need a hard tab, or a ';' before each command. Where there is a gap at the beginning of the line in the picture of the code, make sure this is a hard tab. See also:</p><p><a href="http://stackoverflow.com/questions/14109724/makefile-missing-separator" rel="nofollow">http://stackoverflow.com/questions/14109724/makefi...</a></p><p>Hope this helps.</p>
<p>Probably a lack of tabs. You need a hard tab, or a ';' before each command. Where there is a gap at the beginning of the line in the picture of the code, make sure this is a hard tab. See also:</p><p><a href="http://stackoverflow.com/questions/14109724/makefile-missing-separator" rel="nofollow">http://stackoverflow.com/questions/14109724/makefi...</a></p><p>Hope this helps.</p>
<p>Great tutorial! All of the steps were very clear. The wiring diagrams were a big help. Took me no time to set this up. Everything worked on my first try (well... almost everything. I accidentally mixed up two ports). </p>
<p>And technically I'm using ATtiny25, but switching processors was actually fairly trivial. :)</p>
<p>I wasn't fully done before...I just got it all working now. Great !<br>It is flashing.</p><p>Great job man.</p><p>one more 'enter' for separate &quot;cd ~ mkdir ATtiny85&quot; and &quot;cd blinky&quot; for easy line copying newbies like me ;o)</p><p>You did the most understable tuto I got for this. Hope you will have success.</p>
<p>Thanks, clarified that more. As with all instructables:</p><p>The more we use it, the more we improve it.</p><p>Cheers,</p>
<p>Hello,</p><p>Really nice step by step instructable. I searched hours for it.Thanks !</p><p>2 suggestions for perfect cut &amp; paste tutorial :</p><p>&quot;sudo raspi-config&quot; instead of &quot; sudo raspi-coinfig&quot;</p><p>&quot;cd ~ &amp;&amp; git clone git://git.drogon.net/wiringPi&quot; instead of &quot;cd ~ git clone git://git.drogon.net/wiringPi&quot;</p><p>This allowed me to continue the tuto.</p><p>Have a nice day.</p>
<p>Hi,</p><p>Thanks for the comments, glad it was of help. Corrections made.</p><p>Cheers,</p>
<p>is it ironic that I want to do this, so I can make an USB AVR programer? (http://www.instructables.com/id/VUSBTiny-AVR-SPI-Programmer/?&amp;sort=ACTIVE&amp;limit=40&amp;offset=40#DISCUSS) lol</p>
<p>Yes, I for one did not think it was possible to interface to the ATtiny via USB to make an AVR programmer. That's awesome!</p>
<p>Yeh it is, and alot cheaper than a standard usb AVR programmer. Its limited on what chips it works with, but should save alot of time and effort in the future :D</p>

About This Instructable




More by prb3333:Programming the ATtiny85 from Raspberry Pi Raspberry Pi  Bluetooth In/Out Board or "Who's Home" Raspberry Pi Snail Mail System 
Add instructable to: