Arduino libraries are wrappers on top of libc functions. They abstract a lot of internal workings to allow an average user to run their project in Arduino boards without having to worry about implementation. For an average programmer, it’s better to stick with it. Cause venturing into Avr-c without a basic foundation in C and electronics will be confusing. But once you get past the learning curve, it will help you grow to appreciate the system and the effort that went into it.

We will dive head on into basic coding in this article. Keeping theory only as much as required. With that in mind, lets start with installing the dependencies.


Install all avr-c and all the dependencies.

$ sudo apt-get install gcc-avr binutils-avr avr-libc avrdude


When you start coding, You have to refer to Atmel data sheet one for two hundred times. For quick reference you can see the pin mapping that will help you start.

mcu to arduino pin mapping

Before we start with the first project. Lets start with building some terminology. DDRB is a data direction register for port B. In Arduino uno, there are 3 port registers:

  • B (bitmap for digital pins from 8 to 13)
  • C (analog input pins)
  • D (bitmap for digital pins from 0 to 7)

They control if the given pin is input or output by setting the corresponding bit as 0 or 1. If the bit is high its output and you can write to the pin, if the bit is low it acts as input and you can only read from the pins… By default all the values in the DDRB is set to 0x00, i.e. they are all input.

The current state of all the pins can be read using PINB. And if you want to set the bits to high or low you will perform operation in PORTB.

DDRB is 8 bit, with the lowest bit at PB0 represents digital pin 8 in Arduino board. Dot led is connected to pin 13. In DDRB is its bit 5 (PB5). For this we have to set DDRB = b’00010000’

#diy #c-programming #avr #arduino-uno #arduino

Avr-c for Arduino-uno
2.05 GEEK