K4ICY's Arduino ProjectsArduino Projects  By Mike, K4ICY  

Weekend Radio 
Click Here for More Electronics Projects and Tutorials By Mike Maynard, K4ICY

_

HOW TO PROGRAM AN ATtiny85

.     And of Tiny AVR Microcontroller Varieties

   ATtiny85-20PU
       This page is still very much under construction and I'll add more as I explore this tiny MCU...

.
   I would like to cover the following: [Updates to eventually follow]

   • Installing a good working "core" in the Arduino IDE which will make working with the Tiny (almost) as easy as an Uno.
   • Setting up a programmer interface for the ATtiny.
   • Building a programming 'shield' for the Uno.
   • Building a Fuse Setter for the ATtiny and its implementation.
   • Using an FTDI and 1 pin (using SendOnlySoftwareSerial) to debug and talk to the Serial Monitor.
   • Pitfalls and workarounds - including no UART and the Tiny's issue with noise in its ADC while switching I/O states.
   • Improving code (low-level stuff) to gain the most space and speed.
   • Example sketch, as well as powersaving/sleep features.
   • Moving over to the newer UPDI ATtiny devices including breakout board solutions and programming options.

     Most of the information I provide will be a compilation of various sources online, including YouTube, plus my own example, and I felt that a one-stop primer wouldn't hurt.

.

       The ATtiny85 and is a small 8-pin AVR microcontroller which is the much smaller cousin to the Arduino's ATmega328p.  The 'Tiny' comes with a lesser fraction of the features of its larger cousin but is a perfect solution for the majority of Arduino projects which tend to be smaller and simpler.  The ATtiny85 is part of a much larger family of AVR's.  It was released back in 2005 but because of its low price point and Maker friendly 8-pin DIP(DIL) through-hole package, it is still in production by Microchip today.  There are still large quantities available from vendors including Digi-Key despite recent chip shortages, and is basically the go-to for DIY maker projects.  SMD options in 8-pin SOIC and 20-pad QFN/MLF.

       You can read up on an incredible wealth of detail covering the ATtiny family of MCU packages including comparisons, release dates, specs and production profiles at Wikipedia of course:  https://en.wikipedia.org/wiki/ATtiny_microcontroller_comparison_chart
.
Features of the ATtiny85 Include:

   • 8-Bit Harvard-like RISC Architecture - 120 Instructions, 32x8 General Purpose Registers
   • 8K Flash Program Flash Memory - 10,000 Write/Erase Cycles
   • 512 Bytes EEPROM - 100,000 Write/Erase Cycles
   • 512 Bytes SRAM
   • 8-bit Timer/Counter with Presacler and 2 PWM Channels
   • 8-bit High Speed Timer/Counter with separate Prescaler, and other features
   • 10-bit ADC (4 single-ended channels, 2 differential pairs)
   • Watchdog Timer
   • Analog Comparator
   • On-chip Debugging
   • ISP(ICSP) via SPI port
   • External and Internal Interrupt Sources
   • 16 MHz External Crystal-Controlled Clock (up to 20 MHZ), 8, 4 and 1 MHz Internal Oscillator
   • 6 Programmable I/O lines (Reset is I/O line - with fuse resetter)
   • 1.8(V series), 2.7(standard) - 5.5 volt Operation
   •  Low Power Consumption at 300uA (1 Mhz, 1.8v), Power-Down Mode at 0.1uA at 1.8v.
 

    REFER TO MICROCHIP(ATMEL)'S MANUAL HERE FOR DETAILED INFORMATION

.

   An ATtiny ISP Programming Shield for the Arduino Uno

         Instead of wiring up a solderless breadboard project every time you need to program your Tiny, strap this on!

..ATtiny ISP Programming - Arduino Uno Shield

      Shown here is a homebrew ISP Programming Shield prototype for the Arduino Uno.
      This shield will allow for programming of ATtiny 8-pin chips as well as external AVR devices via connector, and when
      detached from the host Uno, this shield becomes a breakout board to try out sketches.

      [I'll be having a PCB version made by JLCPCB soon (Files Below) and I'll post pics and results here!]

      Included is an 8-pin DIP socket for an ATtiny chip, breakout female Dupont headers for each representative pin,
      a 6-pin standard ISP (ICSP) header for programming of other devices such as other Arduino boards, ATmega328p and etc.,
      3 status indicator LED's for the Arduino as ISP sketch, an external power supply header (5v) for running detatched from the Uno,
      an LED connected via enable jumper to pin #3 for Blink sketch verification and a header for choosing 3.3v and 5v operation.
      I'm considering a PCB design for JLCPCB for anyone interested to have made.

..ATtiny ISP Programming Shield for Arduino Uno

       
[Click on the schematic image above to download the .PDF.]
.
       Here is a through-hole PCB version. [Untested as of this post]
       You can download the GERBER file HERE and use a service such as JLCPCB or PCBWay to make them for you for a few bucks a piece.
.
..ATTiny Programming Shield - Top
.
..ATtiny Programming Shield - Bottom

.
       How to use this shield:  Upload the "Arduino as ISP" sketch from the Examples list in your Arduino IDE and attach the shield pins to the correct Arduino header sockets.  Where you see "H3" on the top of the PCB is the pin that aligns into digital I/O pin 7.  The pin on the bottom left of the PCB is aligned with the Arduino Vin pin.  Place your 8-pin ATtiny into the IC socket (mind the pin 1 orientation, etc.) and follow the established procedures for either loading a sketch or a bootloader to device.  [More specifics will be written in time.]

       Without an ATtiny IC installed, you can use the 6-pin ISP header on this PCB to connect directly with any other Arduino/AVR device or bare AVR IC on a breadboard via Dupont cables or a dedicated cable (such as an ATmega328p).  When operating, the Red LED will slowly fade in and out like a heartbeat to indicate the Arduino as ISP sketch is running.  When Uploading your sketch [Using Programmer], all the LED's will flash on their established timings to indicate operation and the Blue LED will mainly indicate a successful programming process. If the Yellow LED flashes primarily or stays lit, then that is an indication of a damaged IC or a bad wiring connection! [Hopefully not in this PCB, but check your wiring with a multi-meter.]

       After programming, if you've uploaded the "Blink" sketch with ATtiny pin 3 (PB3) set to blink an LED, the White LED (or whatever color you wish) should indicate operation.  You can try reducing the input voltage to the ATtiny by moving the power jumper (on the bottom left) from 5v to 3.3v and is a good way to test variances in timing and such.  DO NOT initiate a programming sequence with the power set to 3.3v!  It might not matter, but you will be programming with 5 volt data lines on a 3.3v powered device.

       ALSO, another thing to look out for is programming a target device which is already under power.  If it is not running off the same power supply, this can cause a serious problem for the programmer Arduino or target device.

       With a programmed ATtiny, you can remove the shield from the Arduino Uno and connect a 2v - 5.5v power supply up to the supplied external power header pins (upper left of PCB) and run your ATtiny on its own development board!  The female header pins adjacent to the IC are directly linked.

       If there are any errors in the PCB I apologize up front as I have not had any made yet, it's not exactly easy to double check the traces either from the files.  Well, it will be good soldering practice for some of you builders anyway. ;)


.

      Programming an Attiny+Homemade Arduino Shield  [GreatScott!]

   

.

      Making the ATtiny85 Easier to Program  [Ralph S. Bacon #84]

   

.

      Six, yes SIX, GPIO pins on an ATTiny85  [Ralph S. Bacon #87]

   

.

      ATTiny85 + I2C + SPI and more!  [Ralph S. Bacon #82]

   

.

   ATtiny Fuse Setter with 12 Volt Charge Pump

         Will work for ATtiny13, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45 and ATtiny85

.

..ATtiny Fuse Setter with Charge Pump - Arduino Shield

.    Shown above:  I built this project as an Arduino Uno shield and it works as advertised.
      The physical size of the capacitors is not crucial (and these were the only ones I had in stock.)

.

     Get control of your ATTiny's hidden settings, change your Reset pin to I/O Pin 6 (and vice versa) and un-brick your chip
     with this useful Fuse Setter (with built-in 12 Volt charge pump supply) designed by Wayne Holder at Wayne's Tinkering Page.

     Wayne's ATTiny Fuse Reset with 12 Volt Charge Pump requires only the 5 volt supply from your Arduino and generates
     the 12 volts needed at the Reset pin (1) to program the fuses on the ATTiny chips.

     This device is based on his ATTiny Fuse Reset project - Read the page at this link for overall instructions!...

     NOTE:  Building this project and implementing fuse settings will require a bit of experience and a willingness to do a bit of research first
                   and is not recommended for newbies.

     The Arduino pin designations are on the left in the schematic.  Schematic shows the target device as the ATtiny13 but the setup will be the
     same for the other 8-pin chips.  For the 24, 44 and 84 series, you will have to reassign the lines to the appropriate pin locations.

.

Wayne's Tinkering Page - ATTiny Fuse Reset with 12 Volt Charge Pump

     The code is adapted from a design by Paul Willoughby at https://www.rickety.us/2010/03/arduino-avr-high-voltage-serial-programmer/


     Download the sketch HERE:  High_Voltage_Fuse_Resetter_ATTiny85_Charge_Pump_Version_2.ino

     [This sketch has been updated from Wayne's version but I'm not sure where I found it - or I may have tweaked it.]


     You will need to first visit one of these two site for the proper fuse settings:

       http://www.engbedded.com/fusecalc/
       http://eleccelerator.com/fusecalc/fusecalc.php

     Follow the instruction //commented// in the sketch's header section:

       1) Set baud rate of Serial Monitor to 57600
       2) Use Online Fuse Calculator to find desired values... the sketch is setup with defaults.
       3) Change #define values for your setup:

            #define  HFUSE45  0xDF    // DF Reset Enabled, 5F Reset Disabled - PB5 as IO
            #define  LFUSE45  0xE2
            #define  EFUSE45  0xFF


       4) Upload sketch and just Enter anything in the input field on the Serial Monitor.

     Serial Monitor should display the detected AVR chip model, initial fuse settings and new settings for verification.

     NOTE:  BEFORE changing the Reset (PB5/IC pin 1) feature to that of a 'weak' I/O (FHUSE45 0x5F,) remember to upload your project
                   sketch FIRST as ISP programming will no longer be possible until you reset the HFUSE45 back to 0xDF.
                   Memory/programming Lock Bits are not set with this sketch - if anyone is able to add this feature with some explanation,
                   please contact me: mikek4icy@gmail.com

     Please refer to Microchip's manual for detailed information on each fuse setting.

     You should try this out on a protoboard first and you can verify the changing of the Reset/IO option on (pin 1) PB5 by running an LED blink sketch on that pin.  Building a shield for you Arduino Uno R3 will make this a convenient process.
 



 

.



Updated 06/17/23

(c)2023 Copyright - Michael A. Maynard, a.k.a. K4ICY