ATtiny programming and Custom blinkM

Apr 17, 2012 No Comments by

Today I have accomplished two things, I finally managed to program the attiny45 and the attingy2313 with an Arduino as ISP and I managed to create a simple dead bug style RGB led with the attiny45. This is the start of creating my own blinkM modules.

Let me start telling you about the really fun part, the part that can be reused in several  embedded projects, about the programing of the attiny micro controllers. If you are using an Arduino board as a ISP programmer the process is super simple, I’m sure that it is super simple if you use a designated programmer as well, but I haven’t tried that yet.

So the first step is to upload the ArduinoISP sketch to your Arduino board, and voila your Arduino card is ready to program a lot of stuff. The second step is to download these files and place them in a new folder called “hardware” that you place in your arduino sketch folder. This folder is often located in your documents folder on windows and mac. After these files are placed in the hardware folder you must restart your Arduino IDE, then you will find a range of attiny options in your board menu in the Arduino IDE.

Now the next step is to connect everything up correctly, the first thing I would do (so I don’t forget) is to put a 330ohm resistor between the reset pin and the 5v pin on the Arduino card, this is so the card wont reset itself when we upload code. If a 330ohm resistor don’t work try a 120ohm, I even read rumors about a 500ohm resistor working.

So the next step is to connect the attiny you want to program up to power and ground, on both chips the pin on the top right should be connected to 5v and the bottom left connected to ground (GND). Then we can connect the reset pin on the attiny to pin 10 on the Arduino card. The attiny reset pin is pin number one, on the up left corner. Then we can connect the MOSI pin to Arduino pin 11. That’s pin 17 on attiny2313 and pin5 on attiny45. Following we connect Arduino pin 12 to the MISO pin, that’s pin 18 on attiny2313 and pin 6 on attiny45. Then the last pin is the SCL that is connected to Arduino pin 13, that’s pin 19 on attiny2313 and pin 7 on attiny45. The pin layout for the attiny’s can be seen below

 

                   +-\/-+
 RST  (D 17) PA2  1|    |20  VCC
 RX   (D  0) PD0  2|    |19  PB7 (D  16)  SCL
 TX   (D  1) PD1  3|    |18  PB6 (D  15)  MISO
      (D  2) PA1  4|    |17  PB5 (D  14)  MOSI
      (D  3) PA0  5|    |16  PB4 (D  13)*
 INT0 (D  4) PD2  6|    |15  PB3 (D  12)*
 INT1 (D  5) PD3  7|    |14  PB2 (D  11)*
      (D  6) PD4  8|    |13  PB1 (D  10)
    *(D  7) PD5  9|    |12  PB0 (D  9)
            GND 10|    |11  PD6 (D  8)
                  +----+

b

                           +-\/-+
  Ain0  RST  (D  5)  PB5  1|    |8   VCC
  Ain3       (D  3)  PB3  2|    |7   PB2  (D  2)  INT0  Ain1  SCL
  Ain2       (D  4)  PB4  3|    |6   PB1  (D  1)        pwm1  MISO
                     GND  4|    |5   PB0  (D  0)        pwm0  MOSI
                           +----+

And all the connections in a tidy table.

Arduino Attiny45 atiny2313
pin 13 pin 7 pin 19
pin 12 pin 6 pin 18
pin 11 pin 5 pin 17
pin 10 pin 1 pin 1
5v pin 8 pin 4
GND pin 4 pin 10

Now that everything is connected right it’s time to program something cool, and nothing is cooler the getting your first led to blink on a new platform. So load up the blink sketch from the arduino example library and change the pin number to something appropriate. For example digital pin 0 is pin 5 on attiny45 and pin 2 on attiny 2313. Then select the appropriate board from the board menu, ATtiny 45 @ 8Mzh or  ATtiny2313 @ 8Mzh. Then you upload the code as usual and the ArduinoISP loaded on your arduino board will make sure that the program is loaded on the connected micro controller. When this is done connect a led and a resistor to the appropriate pin and watch it blink like the little mayhem it is.

The three top leds are staus leds for the ISP scetch, and the bottom yellow is controlled by the ATtiny2313 and the red is controlled by the ATtiny45

 

Now that you have managed to program your own ATtiny micro controller the world of making small stuff is at your feet’s, I know what I am going to do, namely continue to create my own variant of the blinkM module. So far I have only made a dead bug style RGB controller that cycles through RGB. The LED is soldered to the ATtiny45 with three 330ohms resistors and a little piece of wire. And now I can place it anywhere, give it power and it will glow for as long as it can.

The next step is to implement a communication protocol over I2C so that it will become really easy to communicate with the little chip.

Here is some pictures and a video:

Code, DIY, Project, Uncategorized

About the author

Sometime I write, sometime I don't. But most of the time I program, build a curcuit or just do something completely different.
No Responses to “ATtiny programming and Custom blinkM”

Leave a Reply