Saturday, September 23, 2017

Programming the ATtiny 85 chip using Arduino as a Programmer

The ATtiny 85 is a 8 pin chip, and can be programmed with an Arduino.
In this blog - I will attempt to turn LEDs on and off using the Arduino as a Programmer and configuring the ATtiny to read from the Arduino.

This is the flow diagram

Computer -> Arduino -> ATtiny85 -> LEDs.

i.e ( Mac OS -> Arduino IDE -> USB cable to Arduino -> ATtiny85 -> LEDs to Pin PB3 and PB4 )

Prerequisites :

Arduino  Uno -1
Arduino IDE v1.6.12 and above installed on your laptop.
ATtiny 85 - 1 ( 8 pin )
2 LEDs
270 ohm resistors -connected to the LEDs Anode - 2
and access to this package.
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json









Pin Diagram of ATTiny 85 Pin diagram.






Connections :

Arduino   ATTiny85

Pin 13      SCL   (7)
Pin 12     MISO ( 6)
Pin 11     MOSI  ( 5)
Pin 10    Reset  (1)
GND       GND   (4)
Vcc +5V    Vcc  (8)

                PB3-> 270 ohm resistor -> Anode of LED

Common GND            Cathode of LED
==


Setup Programmer on the Arduino IDE as follows:

Include this line into the  Arduino -> Preferences -> "Additional Boards Manager URL" pane in the Arduino Boards Manager:

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



Bring up the "Tools" -> "Boards Manager" and install the "attiny" package by David A. Mellis.
Click on Install.



Check that the install did work, by Tools -> Board, and you see the ATtiny85.




Now, you will see the ATtiny 25/45/85 in the "Tools -> Boards" panel - Select the ATtiny.
This indicates successful installation of the package in the IDE.

=========================================

Next, Reset the "Boards" back to Arduino Uno.




Select File-> Examples -> ArduinoISP ->  ArduinoISP and upload it. This will prepare the Arduino Uno to pretend to be an ISP for the ATTiny.
Programmer -> AVRISP mkrll (setting is default as in Arduino)
( at this time the ATTiny may be connected , but will have no effect on this )


Possible errors and how to resolve it:
If you get a "Serial undefined" error, check if the Board -> Arduino Uno, ( it may have been set to ATTiny 85 ). Reset to Arduino Uno.

If you get a "avrdude: ser_open(): can't open device "/dev/cu.wchusbserial1420": No such file or directory
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troub "
Check if the Tools->Port is set to the Arduino's COM port .





When successful.

File -> Examples -> Basics -> Blink
Change the "LED_BUILTIN" to 3 ("PB3" also works), indicating PB4 of the ATTiny85.
Add a new line ( copy and paste ) and set physical pin 2 , indicating PB3 of the ATTiny85
[ PB3 is physical pin 2 of ATTiny85 ]
[ PB4 is physical pin 3 of the ATTiny85 ]



Same in text format.

Blink Code is modified to turn LEDs on and off at Pins PB3 and PB4.

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(3, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite (4, HIGH);
  delay(1000);                       // wait for a second
  digitalWrite(3, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
 
  delay(1000);                       // wait for a second
}


Change the Board to ATtiny85




Notice the setting " Processor -> Attiny85"




Set the Clock Internal 8Mhz



Burn Bootloader ( not required - during 2nd trial )



If successful, the status should say success.

If not, then check if the Programmer is set to -> "Arduino as ISP". It could be that you have set it to "ArduinoISP". This is confusing ! There are two entries and the correct one should be as shown above.
Or else you will get a "Could not upload" error.




Now Upload the code for the LED, Click on the right arrow button in the top panel.

At this time if you get the error message "not responding", go back and check the Tools-> Programmer -> Arduino as ISP.

( it is set to Programmer -> AVRISP -> mkll as default for the Arduino Uno)






Assuming that the LEDs are connected - they should start blinking.

Troubleshooting :The Arduino ISP has to be uploaded to the Arduino first , File -> Examples -> ArduinoISP -> Arduino ISP
Next, the correct package has to be installed - from

Include this line into the  Arduino -> Preferences -> "Additional Boards Manager URL" pane in the Arduino Boards Manager:
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json


If you are getting a "Not responding to programmer" - that means - the Arduino was not File-> Examples -> ArduinoISP was not installed first ! to the Arduino.


So go back and install this first.