Arduino for $ 1

As an introduction, I will not talk extensively about how people who did not hold a soldering iron in their hands, did not know the words “programmer”, joyfully stick wires with the children into the connectors of the electronic “designer” called Arduino. And I will not remember with any word the camp of “hardcore” people who consider this a mischief and / or abuse of the very ideology of microcontrollers.

I will say for myself - I like Arduino. The fact that you can quickly build something working. In fact, I do not like just the prices. Well, expensive. A module is an order of magnitude more expensive than the microcontroller used in it. Such thoughts repeatedly pushed me to “jump off”, but then I opened Aliexpress and ordered another portion. The Chinese version of the Arduino Nano is $ 3-4. Pro Mini (without USB) - $ 2-3.

Then it became interesting - and where is the minimum retail (or micro-wholesale) price limit. But so that you can work, and not look for hacks in order to save a couple of bytes. A couple of questions for the global mind, the shortest study of the materiel, the solution: "I will be picking with ATTiny, but with Arduino."

Before moving on to hardware, software, rakes and curses, I will mention the nature of the tasks to be solved. Just two examples. The first is a four-channel timer for turning on and off the lights above the bird cages. The second is a LED strip controller for lighting an electrified garage (protection against overdischarge of a lead battery, PWM brightness control). Primitively, but for a penny there are no ready-made solutions.

ATtiny 44ATtiny 84ATtiny 45ATtiny 85Note
Max. frequency, MHz8888From the internal generator
RAM, byte256512256512
Flash, Kb4848
I / O pinseleveneleven55RESET do not consider
Price, $1.661.81.491.69DigiKey retail, just for comparison

Okay, to the point. We will consider microcontrollers ATtiny 44/84 and 45/85. Basic characteristics are given in the plate. As an experimental, I have the 85th in a DIP package, with a price of $ 1 apiece when I buy a dozen from the Chinese.

What can be achieved?

On ATTiny 85, you can use 5 pins (RESET is not considered, its useful use in the case of the Arduino is associated with a tambourine of a decent diameter). ATC is available on three, PWM on two. That is, my second task, an illustration (there you need 2 ADC channels, one PWM and one LED) is already being perfectly solved. ATtiny 84 allows you to use 11 pins, but more expensive - and we have a cheaper sport.

How to program?

The easiest way is through the ISP. As a programmer, you can use the Arduino board, or a penny ISP programmer.

The first rake appears on the scene.

For the experiments, the ATtiny 85 and, in fact, the programmer were ordered. The latter was confidently identified by the PC as a USB HID device. This is bad, in this form the gadget can be used with a minimal amount of software, the Arduino IDE is not included there. However, a quick googling showed that the problem is known and solved. There is a ready-made firmware that turns the miracle of Chinese science into USBASP.

Yes, I take the second programmer (it was a dubious piece called SP300 found in the bins), connect it with the ISP cable to the first, plug both into USB, put the destination in the software SP300 - ATmega8 ISP, and after a split second I get the coveted USBASP

Arduino IDE

In order to work with ATtiny, you need to add descriptions of boards (in fact, chips) to the IDE. I usedthese . The descriptions are placed in the sketch folder as follows:% folder-with-sketches% \ hardware \ attiny, there will be the Variants directory and the boards.txt file.

Materialization of the second rake I

install the chip in the “breadboard”, connect it to the programmer, install the resistor at 10 kOhm ( Potentially an extra recommendation, the pull-up resistor is built in. But in an electromagnetic-noisy environment, as they say in the comments, it is recommended to put it in an apnote to prevent accidental reset. ) between the power plus and the RESET pin (because the reset signal is low). I select the USBASP programmer in the IDE, try to flash the bootloader - and silence. More precisely, AVRDude claims that there is no connection with the microcontroller.

The casket opens simply, but not absolutely obvious. The fact is that the “naked” ATtiny is not flashed with the AVRDude settings used in the Arduino IDE. Too high clock frequency for ISP programming. Moreover, this frequency cannot be specified in the IDE settings.

Solution: we take AVRDude and flash the ATTiny fuses using the command line so that the chip is clocked from the internal generator with a frequency of 8 MHz. At the same time, we indicate the low frequency (to be precise - it is not the frequency that is indicated, but the duration of the clock cycle) of clocking during ISP programming (switch -B). As a result, the “magic line” is as follows:

avrdude -p t85 -c usbasp -U lfuse:w:0xC2:m -U hfuse:w:0xDF:m -U efuse:w:0xFF:m -B 5

After that, the ATtiny 85 is normally flashed through the Arduino IDE. A performance check is performed using the legendary Blink demo project. We change the pin in the sketch from the 13th to the 4th (this is the 3rd output of the ATtiny 85), connect the LED and the resistor, perform the download using the programmer. The LED flashes, the goal is reached.


We conclude that with the ATtiny 85 microcontrollers (as well as 44, 84, 45) it is quite possible to work through the Arduino IDE. Those interested can be horrified by the fact that the blinking code LED eagerly eats almost a kilobyte of memory (with 8 available).

I can’t draw an unambiguous conclusion about the practical value of the research (the savings are small, but there are not enough memory and conclusions), but it was funny enough.

Source of inspiration

Also popular now: