Attiny85 with Arduino Mega

There are many locations that show you how to program a Attiny85 with an arduino uno.  But through out my research, I could not find a good site explaining how to program a Attiny85 with an arduino mega  with that, there are many discrepancys on the pins for the ATtiny and which pin does .  Time to fix that issue.

The Controllers:

An Attiny is a AVR architecture micro controller.  It is small and low power consumption.  Great for simple small projects that don’t need 10 digital IO or 14 analog IO.

687474703a2f2f6472617a7a792e636f6d2f652f696d672f50696e6f7574543835612e6a7067

Figure 1: ATtiny85 Pinout (1)

The first thing we need to understand is how the pins are numbered.  This is seen by a physical circle on the IC (Integrated Circuit)

hole locaiton

Figure 2: ATtiny85 Hole location

This circle is on all IC’s.  It is either next to pin one or at the top of the IC.  You position the IC so the circle is at the top. With that figured out and with Figure 1 we can see what each pin is on our physical ATtiny85.

Now for the Arduino mega, below is a image of the pins on the board.

Arduino Mega 2560 Pinouts

Figure 3: Arduino Mega Pinout

Now that we have all this information, we can move on to setting up the arduino mega as the programmer for the ATtiny. and get up the board from the Arduino IDE.

First lets get the ATtiny support on the Arduino IDE (2).  To do this, open the arduino IDE software, got to File->preferences, then “Additional Boards Manager URLS”.  A dialog box will open up, in that box you will paste the following URL.

Select “Ok”

Preferance

Figure 3: Preferance locaiton

https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json

URLloading

Figure 4:URL pasting

 

then press OK.

board manager

Figure 5: Board Manager

 

Next go to “Tools” then “Board:”  there at the top you will see “Boards Manager..”, select this.  scroll to the bottom and find ATtiny.  When you select ATtiny a install button will appear on the right side of it.  Select “Install” to, as you might guess, install the support for the ATtiny.  Once all that is done, you should see ATtiny in the “Boards” menu.

ATtiny board

Figure 6: Install ATtiny

ATting in place

Figure 7: Atting ready and waiting

Now that the Arduino IDE software knows what a ATtiny is, we next have to let the Ardruion Mega know we want to use it as the programmer.

First we have to go to file-> examples-> ArdruinoISP.  open this stetch and upload it to the arduino mega. just make sure you have the arduino mega set at the board you are going to.

MEgaISP

Figure 9: Mega ISP

megaboardIDE

Figure 10: mega selected as ISP

Before we can upload the sketch we will need to modify the sketch a little.  first we need to make sure the sketch shows what pins are what. since the sketch was originally made for an arduino Uno, we need to change the pins its sending the information to.

First we need to change the #define RESET form pin 10 to pin 53 (since that is the reset pin on a arduino mega.

Next we have to change:

  • #define PIN_MOSI 51
  • #define PIN_MISO 50
  • #define PIN_SCK 52

pin changing

Figure 11: Changing pins

This little part had me stumped for a little but. Had a little Ah-HA! moment.

Upload the sketch and the arduino mega is ready to go.

Now that we have the Mega as the programmer, Arduino IDE knows what the ATtiny is, we can start wiring stuff up to be able to program a ATtiny.  The first thing we do is add a capacitory over the reset and ground pins of the Arduino Mega.  this is done to “turn off” the Arduino Mega, so it does not try to take the code you wrote for itself.

Now we have to connect the pins from the Arduino mega to the ATtiny.

    • Mega Pin 51 to ATtiny Pin 5 (MOSI)
    • Mega Pin 50 to ATtiny Pin 6 (MISO)
    • Mega Pin 52 to ATtiny Pin 7 (SCK)
    • ATtiny pin 4 GND (Ground pin)
    • ATtiny Pin 8 to VCC (5V)
    • Mega Pin 53 to ATtiny Pin 1 (SS)

 

Program ATing85_bb

Figure 12: ATtiny Wire up

Once everything is set up, we will upload the LED blink program.  That is found in File-> examples, LED Blink.

We can not just go ahead and program the ATtiny, we need to adjust the code a little.  The main thing is that we need to change the pin that will be blinking.  In the code it is pin 13.  Since the ATtiny only has 8 pins, we can’t use pin 13.  in the code where it says pin 13, replace that with pin 0 which is the physical pin 5.

We will also wire up a led with the corresponding resistor so we can see our program work.  To do this, connect the LED to physical pin 5 with the positive side on the pin, and a resistor connecting form the negative pin of the led to ground.

Before we upload the blink program lets run through the check list to make sure everything is set up.

CHECK LIST:

  • Mega has ISP
    • Change the pins in the code
  • Wires connected correctly
  • ATtiny85 set up as the “Board”
  • Frequency set up as internal 8MHz
  • “Programmer” set to arduino as ISP
  • com port set to the correct port for the comptuer

With all that set up, upload the program and watch that LED blink.  You can now disconnect the usb form the Arduino mega, remove the wires that connect the CLK, MOSI, and MISO.  with only the ground, and VCC(5V) still connected, once you plug the usb back into the mega, it will supply power to the attiny and now you know your ATtiny is up and running.

 

Now do a little happy dance.

Referances:

(1)     SpenceKonde. “SpenceKonde/ATTinyCore.” GitHub, 28 Feb. 2018, github.com/SpenceKonde/ATTinyCore.

(2)     High-Low Tech Group. “Programming an ATtiny w/ Arduino 1.6 (or 1.0).” Highlowtech, 5 March 2018, http://highlowtech.org/?p=1695