Program AVR Type Microcontroller by Raspberry Pi GPIO



It is very easy to program any type of Arduino board with the Arduino IDE. But if you want to use only the microcontroller, not the entire Arduino board or some other microcontrollers from AVR family (Atmenga series or Attiny series) then this experimental work is for you. There are a number of options to program such kind of microcontrollers. You can use another Arduino board as Arduino ISP or you can use an FTDI breakout board to program the microcontrollers. I must say those are really good options. But if you have a Raspberry Pi around you then there no need for FTDI or extra Arduino board. You can program the microcontrollers with the GPIO pins of the Raspberry Pi. In this project, we are going to describe what the packages we need to install, how to compile an Arduino sketch and download it to the microcontroller.

Hardware Needed:

  1. Raspberry Pi (any model) with Raspbian installed
  2. Any AVR type Microcontroller (for our case we are using Atmenga328P and Attiny88)
  3. Jumper wires for connection
  4. Some peripherals like LED (Totally optional)

Working Principle:

This entire experiment is just following the workflow of the Arduino. The complete Arduino package contains three separate binaries. The first and most obvious Arduino IDE or Arduino, the second one is Arduino-mk and the rest one Avrdude. Arduino IDE is the Graphical User Interface to write the code. Arduino-mk helps to compile the code and create a hex file from it. Finally, the Avrdude download that hex file to the actual hardware.

But Arduino IDE has all those facilities to call those package and compile and download the code to the hardware just by clicking a couple of buttons on the IDE. To use this button click methodology a USB interface like Arduino build-in interface or FTDI module obviously needed. But without those interfaces, we can program the hardware with the GPIO pins of the Raspberry Pi.

There are two ways to program the hardware with the Raspberry Pi's GPIO:

  • In the first method, we can use the Arduino IDE to write and compile the code and then use the Avrdude to download the hex file into the hardware.
  • In the second method, we can write the code in any text editor like vi, nano etc. Then compile with the Arduino-mk and finally download with Avrdude.

Here we will discuss both the methodology and for referencing we are going to use 'method 1' and 'method 2'.

Hardware Setup:

The hardware setup is pretty easy for this experiment. we need only 6 jumper wire to connect the AVR microcontroller with the Raspberry Pi's GPIO. If you are using the Arduino board itself then you can directly use the ISCP pins for the program the hardware or you can directly use the GPIO pins of the chipset for any other microcontroller. The following image and table help you to figure out the pin number.

Uno 11 or ICSP-4 12 or ICSP-1 13 or ICSP-3 res or ICSP-5
Mega2560 51 or ICSP-4 50 or ICSP-1 52 or ICSP-3 res or ICSP-5
Leonardo ICSP-4 ICSP-1 ICSP-3 ICSP-5
Attiny88*** 17 18 19 1

*** Physical Pin Number

Now this MOSI, MISO, SCL, Reset and VCC, Ground pins need to be connected with the GPIO of the Raspberry Pi. The following table helps you to do that.

Raspberry Pi Hardware
MOSI (GPIO 10)[Physical 19] MOSI
MISO (GPIO 09)[Physical 21] MISO
SCL (GPIO 11)[Physical 23] SCL
Reset (GPIO 08)[Physical 24] Reset
Ground Ground


Here we have some photographs of the original hardware.

this is the hardware setup of Raspberry Pi with the Attiny88 microcontroller. I made some PCB for some other project and using that PCB directly. you can use the microcontroller with the breadboard and after programming, the microcontroller put it in the original project.


This the hardware setup of Raspberry Pi with the Arduino Uno

Software Setup:

Method 1:

Step 1:

Open the terminal of your Raspberry Pi and run the command to install the three packages.

sudo apt-get install arduino arduino-mk avrdude

Step 2:

After that open the Arduino IDE from the menu or directly from the terminal then write the code. Before compiling the code go to File > Preferences and checked the compilation checkbox. It is a very important step to get the hex file location. Then select the board type that you want to program (we are using the Arduino Uno) and then compile the code by clicking the 'verify' button. Here I am not going to discuss the compilation process in deep. please refer to this blog for more information or check out the video at the end of the blog.

Step 3:

Now make a new folder in your workspace. for me, I am using home location only and then copy the hex file and the avrdude.conf file into the folder.

mkdir ~/workspace
cp hex_file_location/file.hex ~/workspace
cp /etc/avrdude.conf ~/workspace

Step 4:

Now we have to make some changes to the avrdude.conf file. you can open the file in any text editor or IDE and add those lines end of the file and save it.

  desc = "Program with Raspberry Pi GPIO";
  type = "linuxgpio";
  reset = 8;
  sck = 11;
  mosi = 10;
  miso = 9;

Step 5:

Then we can directly program the hardware with this command.

For atmega328p chipset use: avrdude -v -Cavrdude.conf -pm328p -clinuxgpio -e -Uflash:w:hex_file_name.hex

For atttiny88 chipset use: avrdude -v -Cavrdude.conf -pattiny88 -clinuxgpio -e -Uflash:w:hex_file_name.hex

If you are using some other chipset then set the -p parameter according to that.

To find the part no: avrdude -v -Cavrdude.conf -ppartno -clinuxgpio 

Done!!! your hardware is now programmed with your code.


Method 2:

Step 1:

In method 2 we are not using the Arduino IDE. To write the code we can use any other text editor and compile with Arduino-mk and make the hex file. after that, the rest processes are the same as method 1. First, we need to install the packages by the command

sudo apt-get install arduino-mk avrdude

Step 2:

Now open any text editor and write the code and save it with .ino extension. In that same folder create another file with the filename as Makefile. And add those lines in that Makefile.

include /usr/share/arduino/

Then save the file and hit the make command for the terminal. This will create a hex file in the same location. 

Step 3:

Now follow steps 3, 4 and 5 from Method 1.


For more details check this video out.



This is experimental project work. There are so many alternative ways that are present in the market to perform the same work with less effort. But if you want to make a complete project where you need to program the microcontroller on its own then this work may help you. 


If this small effort can help in any project then my effort will be successful. Please put feedback On our contact page.

If you faced any problem please send an email to Thanks for being with us.

Thank You

Leave a Comment

View Previous Comment

Subho Basak 04th Jun, 2020

Love this work. Here you describe all the things in very simple way and also there is a video which will help us for clear understanding.

Show 1 Reply