In the life of the Arduinschik, sooner or later there comes a time when it becomes crowded in the standard development environment. If the skits no longer have enough memory, you need hard realtime and work with interruptions, or you just want to be closer to the hardware, then it’s time to switch to C. Experienced electronic engineers will contemptuously scowl at the mention of Arduino and send the newcomer to the radio shop for a soldering iron. Perhaps this is not the worst advice, but we will not follow it yet. If we discard the Arduino IDE and the wiring / processing language, we will have in our hands an excellent debugging board, already equipped with everything necessary for the operation of the microcontroller. And, not least, a bootloader is already sewn into the memory of the controller, allowing you to download the firmware without using a programmer.
For C programming, we need the AVR GCC Toolchain.
Windows:Install
WinAVR , which contains everything you need.
Debian and Ubuntu:sudo apt-get install gcc-avr binutils-avr avr-libc
')
MacOs X:Installing
CrossPack for AVR DevelopmentWe also need the Arduino IDE installed, because it contains the avrdude utility, which is needed to download the firmware to the controller. CrossPack also contains avrdude, but the version that comes with it cannot work with Arduino.
After everything is installed, create our first project. First we write a
Makefile . It will allow us to avoid entering long commands manually at each compilation and firmware download.
In this file we need to enter our command to run avrdude. On different systems, it will look different. To find out your version, launch the Arduino IDE and tick the option “Show verbose output during upload” in the settings.

Now we load into Arduino any sketch and look at the messages displayed at the bottom of the window. We find the avrdude call there, copy everything except the -Uflash parameter and paste it into the Makefile after “AVRDUDE =”.

A quick note: all indents in the Makefile are made with tabs (Tab). If your text editor replaces these characters with spaces, the make command will refuse to build the project.
Now we will create a file
main.c - the actual text of our program, in which we traditionally blink an LED.
#include <avr/io.h> #include <util/delay.h> #define LED_PIN 5 int main() { DDRB |= 1 << LED_PIN; while(1) { PORTB |= 1 << LED_PIN; _delay_ms(1000); PORTB &= ~(1 << LED_PIN); _delay_ms(1000); } return 0; }
Our project is ready. Open the console in the directories of our project and enter the "make" command:

As you can see, the size of the resulting firmware is only 180 bytes. A similar arduinovsky sketch occupies 1116 bytes in the controller's memory.
Now back to the console and enter “make flash” to load the compiled file into the controller:

If the download has passed without errors, then the LED connected to pin 13 of the board flashes happily. Sometimes avrdude cannot find a card or falls off on time-out - in this case, over-shaking the USB cable can help. Also, in order to avoid board access conflicts, do not forget to close the Arduino IDE before the “make flash” command.
Perhaps many of the things described in this article will seem obvious to experienced developers. I tried to describe the process in the most understandable language for the beginner arduinschik and collect in one place the information that I managed to obtain from various sources, and verified by experience. Maybe this article will save someone a couple of hours of time.
Good luck in mastering microcontrollers!
Happy New Year!