Thursday, August 18, 2011

ATTiny2313 with Arduino

Note - you'll want to have completed or looked over this post as well. It shows how to make the Arduino Sketchbook folder if you don't know how to already, as well as setting up the 'core' file and such.

So, the ATTiny85 is good and everything; it's small, it's easy to program, but it only has five usable pins. Plus, it's memory isn't too great. Sometimes, you need more like 17 pins. That is when the ATTiny2313 comes in handy. It is a twenty-pin chip, has UART (your basic serial connection), I2C, SPI... a lot more than the Tiny85 (Which only has USI, or Universal Serial Interface). In this post I'm going to show how to install the cores, which is really the same as installing the ATTiny core, but there are a few hints.

Getting the Cores

    Just as with the ATTiny85, we first have to get the cores. The cores are the files that the Arduino program uses to determine how to program the chip, how big the program can be, etc. I used the one from this page (this is the actual download link). Download that file and unzip it if it isn't already unzipped. If you open it up, you'll see something like this:

    There are two tricky things that have to be done. See the file, fourth from the top, that's called main.cxx? It has to be changed to main.cpp. Then, open it up add #include <WProgram.h> at the top.

main.cpp should look like this.
    The other thing is similar to the ATTiny85 tutorial. With the debut of Arduino 1.0, these "W-things" (like WProgram and WInterrupts) aren't used anymore. But the core we've got still has these. Thanks to Maverick, who commented on one of the '85 tutorials, the best way to fix this is to add a new file in the the WFiles called 'Arduino.h'. Then, put in that file this one line:

  #include "WProgram.h"

    The Arduino IDE will include this Arduino.h in the sketch's program, and this edit makes Arduino.h include all the old WStuffs.
Now, close main.cpp and navigate to your Arduino sketchbook. How to find this is in the ATTiny85 core installation post (Not to overstate, but if you haven't read the '85 tutorial, you should. It'll make much more sense). Open /hardware/attiny45_85/boards.txt. Here's a helpful file path:

This will have a lot of definitions for the '85 and '45 if you have installed them. Just add this at the top or the bottom.

    This bit of text tells the Arduino program about the chip we're using: the name, the upload protocol, the memory size, the speed, and some other things. 

That's about it for configuration. Take a look at this page for how to get the program to the chip. The process is the same: connect the SPI lines of each microcontroller and attempt and upload! Leave a comment with any questions!


  1. Think someone might overlooked...
    The entire attiny2313 folder in the zip file should be put into the following folder for it to work.

    1. Hmmm... I believe it is. Look at the last picture. It shows the file structure that works, and I think it already is how you described it.

  2. It would be great if you posted the pinout to program the attiny2313!

  3. Hi
    I am still getting an error. This a link to the error screen shot.
    Would you be able to give me some pointers on what i may be doing incorrectly.



  4. i'm a newbie at arduino, so, the 2313 doesn't have the arduino bootloaader right? you just use arduino tu program it? and the code in the ide, can I code as if I was doing it for arduino?

  5. still have the same problem with philiwayne. It seems it doesn't work :P Please help!