In this tutorial I will show you how to program an ATtiny2313 microcontroller chip using Arduino.
What is ATtiny2313 ATtiny4313
The ATtiny2313 and ATtiny4313 are 20 pin processor chips. It has 17 I/O pins, but it do not have an ADC. It can be configured to run at 1 MHz and 8 MHz without an External Crystal Oscillator. I previously shown you how to program the ATtiny85 using Arduino, which is an 8 pin chip suitable for much smaller projects.
Connection with the Arduino
Connect your Arduino to the Attiny2313 following these pins.
Arduino Attiny2313 13 19 PB7/SCK 12 18 PB6/MISO 11 17 PB5/MOSI 10 1 PA2/Reset 5v 20 VCC GND 10 GND
Arduino-Tiny Libraries and Arduino IDE
- Download the Arduino-Tiny library.
- Follow these instructions to install the library. (make sure the Arduino IDE is NOT running yet!)
- Upload the ArduinoISP to the Arduino
- Connect a 10 µF capacitor from reset to ground on the Arduino (If you are using Arduino Duemilanove use an 120 ohm resistor from reset to Vcc)
- Open the blink example sketch, change the LED pin number from 13 to 15 (which is pin 18 on the chip)
- Select Attiny2313 board from Tools->Board-> [email protected]. You will notice that you have a lot of options to choose. This is because that ‘tiny’ folder that we put in the ‘hardware’ folder gave the Arduino program more board options.
- Select ArduinoISP: Tools->Programmer->Arduino as ISP
- Upload your sketch by selecting File->Upload using programmer, if you are getting any error, check out this post to troubleshoot the problem.
- Connect a LED with resistor to pin PB6 on the ATtiny2313 or 4313 (pin number 18 on the chip)
- Now you should have a blinking LED on your Attiny2313
Check this diagram to match the pin number we use in programming and the physical pin location.
Running at different speed
Note the chip will run at 1 MHz in the above example, as specified when selecting the ATtiny board in the IDE. If you want to run it at 8 MHz you need to use select a different board option and also the burn bootloader option. It does not really burn a bootloader on your ATtiny chip, it will only set the fuses to another clock-speed. Also it’s recommended to connect an 0.1 uF capacitor between VCC and GND, and an 10 Kohm resistor between RESET and VCC when running at this speed.
Select board -> [email protected] Select ->Tools->Programmer->Arduino as ISP Select ->Tools->Burn Bootloader
Debugging ATtiny and display information on the Arduino IDE
Easiest way to debug the Arduino is using Serial.print() function, and fortunately you can also do that on the Attiny2313 too.
The difference between ATtiny2313 and ATtiny4313
I have not got a ATtiny4313 yet so I can’t test this Arduino programming method on it. But they seems to be very similar as they appear on the same datasheet. The datasheet says “The ATtiny2313A and ATtiny4313 differ only in memory sizes.” So I suppose all you need to do is to select the different board before upload the sketch in the IDE. I will update this section once I am sure of this, or let me know to confirm it if you have done it.
Programming ATtiny chips with Arduino using Shields
Connecting the cables every time you want to program a ATtiny chip is quite time-consuming and messy. This instructable is quite handy if you are a frequency ATtiny chip programmer.