ATtiny85

Page

Stránky / Mikrokontroléry /

This is a page that serves as a signpost for experiments with a smaller version of Arduino. ATtiny85 has 8K of flash memory, 512 SRAM and 512 EEPROM. It may seem a little, but even in such a small memory you can get a pretty big program. ATtiny85 is my favorite microcontroller and only in exceptional situations I replace it with ATtiny84 microcontroller, which has more pins and a bit better peripherals.

Why use ATtiny85 instead of a full-fledged Arduino?

The main reason is the price. You can buy the microcontroller for the Euro, and when something happens, nothing happens. In addition, it is simple to made circuitry that is robust, can be connected to a higher voltage (using a voltage regulator) and you can easily control other circuits with the digital pins.

Programming

How to program ATtiny85 using the Arduino can be found in a separate article Arduino as an ISP programmer. There is also the second option that you can lay down a development board and program it using USBasp.

In order for the microcontroller to be programmed, support must be installed in the Arduino IDE. The procedure applies to IDE 1.6.4 and above:

  • Use the menu function File/Preferences.
  • In the dialog displayed in the field Additional Board Manager add https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json and press OK. Although the core is referred to as the first, but I do not recommend using it. It was the first of historical reasons, but its author did not have much time to develop as the core, referred to in the paragraph on alternative cores.
  • Use the function Tools/Board/Boards Manager.
  • In the list of boards, find the attiny and install it.

Alternative cores

The previous core is good for the basic programming of ATtiny85. However, if you want to use more options of the microcontroller, it is advisable to look for more redesigned cores. They support the changing of many parameters. For example, changing fuse settings, different clock sources, and code optimization during the translation.

Digital output

Five digital pins are available in the default settings. It is possible to switch the microcontroller to the state when it uses the last pin instead of the reset, but it is a one-time issue and it is no longer possible to program it using the Arduino. That is why we will not even take this option into account. The individual pins are controlled as follows:

  • PB0(5) - digitalWrite(0, HIGH);
  • PB1(6) - digitalWrite(1, HIGH);
  • PB2(7) - digitalWrite(2, HIGH);
  • PB3(2) - digitalWrite(3, HIGH);
  • PB4(3) - digitalWrite(4, HIGH);

PWM output

There are three pins available:

  • PB0(5) - analogWrite(0, 128);
  • PB1(6) - analogWrite(1, 128);
  • PB4(3) - analogWrite(4, 128);

Analog input

There are three inputs available:

  • PB2(7) - ADC1 - analogRead(1);
  • PB4(3) - ADC2 - analogRead(2);
  • PB3(2) - ADC3 - analogRead(3);

There is a fourth analog pin, but it is on the same pin as RESET and its use is not easy.

ADC conversions provide more choices and those are examined in a separate article of the ADC.

Internal EEPROM

Working with EEPROM works just like in the usual Arduino. If you want to make programming easy, find the inspiration in the article on the practical use of EEPROM.

Adjusting the speed of the microcontroller

If there are no serious reasons for this, leave the microcontroller at the 1 MHz factory setting. If the speed is important, it can be switched to 8 MHz and in the case of extra speed requirements it is possible to go up to 20 MHz but only at the cost of pins 3 and 4. Speed setting is described in the article Arduino as an ISP programmer.

The information on the occupation of pins 3 and 4 is not entirely correct. There is a possibility to switch ATtiny85 into a mode that even at higher speed uses an internal oscillator. It is called PLL and can be used to achieve higher speeds. The easiest way to do this is to use the core ATTinyCore and set it in the menu. Be sure to use the menu item Burn bootloader.

Program it like Arduino?

Again what is in the previous paragraph. To add work, you can program it with low-level functions. But at ATtiny85 we have 8 kB of memory available, and it's enough for regular size programs. That's why it's much more convenient to write digitalWrite than to worry about bitwise port operations.

Only when it comes to speed or more significant memory savings, optimization techniques are needed. The old programmer's rule is that the customer does not really care how many years you've spent the program for flashing the LED. When it works, the customer will never see your source code.

Projects

List of projects with ATtiny85. If you want to program the microcontroller more, it's a good idea to build a development board. In projects, you can find the boards in the DIP design and the boards with SMD components. The LED strip dimmer was my pilot project I was learning. But surprisingly, this model of dimmer uses about 10 of my friends on my boards and an unknown number of hobbyists who have been inspired with this project.

Blog

List of articles about ATtiny85. I wrote many articles about this microcontroller, so I tried to divide them into logical groups.

For beginners

On these pages I never wrote about Arduino directly for beginners. The reason was that there are enough examples of Arduino on the Internet that will teach you the basics of programming. With the ATtiny85 microcontroller it's different. Examples are few and difficult to find examples that would be simple enough. I'm trying to do this in this series and describe the topics and examples I do so that after reading a series of these articles a less experienced user could program these small microcontrollers.

  • Blink - Basic LED flashing.
  • Fuses - Set fuses that affect the speed and behavior of the microcontroller.
  • Buttons - Button control.
  • PWM - Control of LED brightness with pulse width modulation.
  • A/D converter - Reading analog values.
  • Preparing - the analog comparator.

Programming

Different ways of programming a microcontroller.

The rest

Other articles that could not be categorized.


10.01.2019


Menu