Tuesday 26 August 2014

Arduino as ISP for ATTiny85

Following on from my previous post (ATTiny85 with Arduino Uno as ISP), I thought that I would have a crack at explaining the method of using the Arduino as an ISP for an ATTiny85.

The first step that I missed, the one that I had a lot of trouble finding, was configuring the Arduino UNO as an Inline Serial Programmer. This is really quite an easy step to complete and doesn’t require anything other than the Arduino UNO, the USB connection to your computer and the IDE.

Connect the UNO to the computer using the USB cable and launch the Arduino IDE.

When the IDE is open, click File > Examples > ArduinoISP. This sketch comes with the IDE, so there isn’t anything to download (so long as you already have the IDE).

In the comment block, the sketch contains the information that you need to connect a device serially to program it.

// This sketch turns the Arduino into a AVRISP
// using the following arduino pins:
//
// pin name:    not-mega:         mega(1280 and 2560)
// slave reset: 10:               53
// MOSI:        11:               51
// MISO:        12:               50
// SCK:         13:               52

It also gives you some other information so that you can display the progress of the sketch load from the Arduino.

// Put an LED (with resistor) on the following pins:
// 9: Heartbeat   - shows the programmer is running
// 8: Error       - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave

In addition to the connections from the Arduino to the ATTiny, it really does make sense to add in a couple of LED and resistors to show that the communication between the two is happening and the real time results. I for one am going to go back to my simple ISP PCB design and add in these LED. This is really something that I should have been doing all along.

When the sketch is loaded onto your Arduino, the next step is to connect your ATTiny85. I have simplified the connection diagram here.

ATTiny85_To_Arduino

Connect the ATTiny85 to your Arduino UNO according to the diagram and then connect the LED to the Arduino for real time monitoring of the UNO.

Load the blink sketch into the IDE and change the Board (Tools > Board > ATtiny85 with 1 MHz clock).

The Programmer should be Arduino as ISP (Tools > Programmer > Arduino as ISP), so change that too.

The example Blink sketch has pin 13 configured for the LED. There isn’t a pin 13 on  the ATTiny85, so you will need to change it to something else. For example, Pin 5 on the ATTiny85 maps to PB0, change the sketch to use PB0 instead:

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 0;

Save the sketch (File > Save) and give it a filename that indicates that it is for ATTiny85.

At this point, you could connect an LED to pin 5 of the ATTiny85. Connect the long leg (the Anode) of the LED to pin 5 and then the short leg (Cathode) to a resistor, then the other end of the resistor to pin 4 of the ATTiny85 (Ground).

So far, we have programmed the Arduino UNO as an ISP and connected the ATTiny85 to our ISP. We have also connected the load to the ATTiny85 so that when we’re done, the LED will blink.

Right … upload the sketch (File > Upload Using Programmer or Control-Shift-U). You should see the LED on pin 9 and 7 of the Arduino flashing and then … the LED attached to pin 5 (PB0) of the ATTiny85 will start blinking.

You can expect to get the avrdude error that everyone tells you is OK – “avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85”. At this stage, that kinda means that it all went OK and your sketch is loaded … the proof should be that the LED is blinking on Pin 5 (PB0).

Job Done.

The ArduinoISP sketch handles the reset function of the Arduino, so there is no need to connect a resistor or capacitor across the Arduino RESET pin.

I plan to return to the avrdude error, I’m sure that this is just a configuration issue with boards.txt, but we’ll see.

Hopefully, you will find this article and follow it rather than the plethora of other articles that were probably right for previous versions of IDE/Arduino. Good luck, and watch out for those hungry, hungry hippos.

No comments:

Post a Comment

Paypal Donations

Donations to help me to keep up the lunacy are greatly appreciated, but NOT mandatory.