Friday, July 10, 2015

Intermediate: Getting Started with ATtiny13A-PU

Hi, everyone. It's been sooooo long since I last posted a new blog. Mostly because I'm busy and lazy. :D

Anyway, I'm in a good mood today - though pretty sleepy - and I'd like to share with you guys something that I'm currently playing with. It is called ATtiny13A-PU. It is an Integrated Circuit (IC) from Atmel, which also manufactured the lovable ATmega328, used by the Arduino UNO, Nano, etc.



I bought the chip from the one and only GI Electronic which you can find here (http://www.gie.com.my/products.php?action=ic/atmel/ATtiny13A-PU). It is pretty cheap compared to an ATmega328.

As you might have noticed, the different between ATtiny and ATmega is the word 'tiny' and 'mega' itself. ATmega has tons of I/O pins while ATtiny has 8 pins, minus VCC, GND, and RESET pins leaving just 5 GPIO pins left. However, it would still be great if your project doesn't require too many pins. (It even have 2 PWM pins, though.)

There are a few other ICs which resembles ATtiny13 like ATtiny45, ATtiny85, etc. They vary in some specs. However, there are quite a bunch of tutorials that already cover those ICs. I'm writing this blog because I found out that there isn't much about ATtiny13, specifically, or some of them aren't complete. I also stumbled upon quite a number of problems which they discussed in separate forums, blogs, instructables, etc.

So, I'm going to put all my findings here and I hope you would also able to follow them.

What do you need?
1. Arduino UNO (Or Mega or something else. We are just going to use it to program ATtiny through the ISP)
2. Some male-to-male jumper wires.
3. LED (Optional, for testing)
4. Resistor (Optional, for testing. 220R, 100R, 470R, or others within acceptable range for LED)
5. Breadboard

How to hook it up?

* You may also use 5V as well instead of 3.3V

Setting up Arduino IDE
At the moment that I'm writing this blog, the library that I've downloaded doesn't work with the latest Arduino IDE. I've tested with Arduino 1.6.5, and the IDE wouldn't even launch. So, I tried using Arduino 1.0.6. So, you might want to do that as well.

I suggest using the (.ZIP) and extract it somewhere, so you wouldn't need to install it. You can still keep the latest version of Arduino IDE installed. Do not launch the application yet.

Step 2: Download the ATtiny13 hardware file. (https://github.com/tekstop/attiny/tree/Arduino1)
There are some adjustments needed to be done later.

Step 3: Open the folder where you've extracted the Arduino 1.0.6 IDE. Navigate to the folder called hardware inside it.
Example: C:\Users\Shah\Desktop\arduino-1.0.6\hardware

Step 4: Extract the folder attiny from the ATtiny13 hardware file downloaded earlier into the folder.

Step 5: We are going to fix something now. Open the extracted folder and edit the file boards.txt
Example: C:\Users\Shah\Desktop\arduino-1.0.6\hardware\attiny\boards.txt

Step 6: Scroll to the bottom and find (or simply press Ctrl+F) something like:
"attiny13.build.f_cpu"
Change the value to 1000000L.

Step 7: We need to add something to the file wiring.c in the Arduino IDE. Navigate back to the Arduino hardware folder. Go to arduino/cores/arduino and edit the file wiring.c using your favourite editor or notepad.
Example: C:\Users\Shah\Desktop\arduino-1.0.6\hardware\arduino\cores\arduino\wiring.c

Step 8: Go to line no. 44, the one that has something like:

#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)

At the end of that line, add the following:

|| defined(__AVR_ATtiny13__)

So, now that line look something like this:

#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny13__)

Step 9: Now you can finally launch Arduino IDE 1.0.6. Open sketch ArduinoISP from File > Examples > ArduinoISP

Step 10: Hook up your Arduino UNO or Mega and select the port number as usual. Go to Tools > Programmers and select Arduino as ISP

Step 11: Upload the ArduinoISP sketch to the Arduino UNO or Mega as usual.

Step 12: Open Blink sketch from File > Examples Blink
Change all the pin number 13 to 4. There is no pin 13 on ATtiny. The LED that you've hooked up to if you follow the schematic accordingly should be on pin 4.

Step 13: To upload this program to ATtiny, File > Upload using programmer (Ctrl + Shift + U)

The LED should be blinking right now. You can play around with it and make something awesome out of it. I pray that you succeeded and have some fun with it. Just a heads up, the maximum sketch size is just around 1MB only, so, use it wisely.

Good luck and have a nice day or whatever~