Author Topic: how to burn bootloader with Raspberry Pi  (Read 5136 times)


  • Newbie
  • *
  • Posts: 13
    • View Profile
how to burn bootloader with Raspberry Pi
« on: March 25, 2020, 06:00:07 PM »
For the images, down load the attachment,

How to Program an AVR/Arduino using the Raspberry Pi GPIO
In this tutorial I am going to show you how to program an AVR(ATmega328) and an Arduino nano using the GPIO on the Raspberry Pi.
Hook up the Raspberry Pi to the Arduino nano or AVR.
You need to use specific pins on the Arduino, but you can use any of the available pins on the Raspberry Pi. I used these:
    Pin D11 (MOSI) on Arduino to pin 20 on RPi
    Pin D12 (MISO) on Arduino to pin 16 on RPi
    Pin D13 (SCK) on Arduino to pin 21 on RPi
    Pin RESET on Arduino to pin 12 on RPi
    GND on Arduino to GND on RPi
    5V on Arduino to 3.3V on RPi
Arduino should normally be powered by 5V,  Raspberry Pi has 5V on GPIO pins.
The result looked like this:

 ***images in attached docs

The image below shows how to hook up an ATmega328 (DIP package) to a Raspberry Pi 2.
For pinout on raspberry pi, you can use the pinout command

***images in attached docs

NEEDed to preform this operation:
Raspberry Pi just about any verision over 2
raspbain preference full blown image, but not manditory (should already have and know how to install)
USB stick
wire, and possibly some soldering involved depending on what you have
breadboard comes in real handy
TV and hdmi cables
connection to the interenet to get the recommended files
****you do not need the ribbon cable in the pictures above

Install avrdude
Once you have your devices hooked up, it is time to install avrdude. Avrdude is an AVR programmer for Linux, which  allows us to use the GPIO pins on the Raspberry Pi to program an AVR or Arduino.
First you need to install some prerequisites
pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get upgrade -y
pi@raspberrypi ~ $ sudo apt-get install bison flex libusb-dev -y

Now install avrdude from source;
pi@raspberrypi ~ $ cd /tmp
pi@raspberrypi ~ $ wget
pi@raspberrypi ~ $ tar xfv avrdude-6.1.tar.gz
pi@raspberrypi ~ $ cd avrdude-6.1

Enable linuxgpio in the avrdude source, make and then install;
pi@raspberrypi avrdude-6.2/~ $ ./configure --prefix=/opt/avrdude -enable-linuxgpio
pi@raspberrypi avrdude-6.2/~ $ make
pi@raspberrypi avrdude-6.2/~ $ sudo make install

Now we need to tell avrdude to use the GPIO and we need to let it know what GPIO pins to use. This can be done by editing the config file;
pi@raspberrypi avrdude-6.2/~ $ sudo nano /opt/avrdude/etc/avrdude.conf

Look for "linuxgpio" and you should see this section; 3/4 the way down, long file
#  id    = "linuxgpio";
#  desc  = "Use the Linux sysfs interface to bitbang GPIO lines";
#  type  = "linuxgpio";
#  reset = ?;
#  sck   = ?;
#  mosi  = ?;
#  miso  = ?;

remove the # and make the following changes(make it look exactly like this including the last ; )

  id    = "linuxgpio";
  desc  = "Use the Linux sysfs interface to bitbang GPIO lines";
  type  = "linuxgpio";
  reset = 12;
  sck   = 21;
  mosi  = 20;
  miso  = 16;

If everything is connected and configured properly, you should be able to run this now and get into the avrdude console.

sudo /opt/avrdude/bin/avrdude -p atmega328p -c linuxgpio -v -t

Below is from a successful test;

avrdude: Version 6.2, compiled on Mar  9 2016 at 11:41:53
         Copyright (c) 2000-2005 Brian Dean,
         Copyright (c) 2007-2014 Joerg Wunsch
         System wide configuration file is "/opt/avrdude/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping
         Using Port                    : unknown
         Using Programmer              : linuxgpio
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
         Programmer Type : linuxgpio
         Description     : Use the Linux sysfs interface to bitbang GPIO lines
         Pin assignment  : /sys/class/gpio/gpio{n}
           RESET   =  12
           SCK     =  21
           MOSI    =  20
           MISO    =  16
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)
avrdude done.  Thank you.

to exit the command, type: quit

Load the hex file you need for you laser etcher in your downloads folder
use the raspberry pi folder browser to copy the hex file from your USB stick to the download folder so you can get to it easy for upload purposes.

*****take out the brackets {below}****** they are not needed*********
We will use avrdude to upload the file;
pi@raspberrypi ~ $ sudo avrdude -c linuxgpio -p atmega328p -v -U flash:w:/home/{change username}/Downloads/{filename.hex}:i

once you have dropped that command it should go through the process of erasing the eeprom, and then writing the firmware you designated to the bootloader.  You should see towards the bottom, that it wrote it, verified it and was successful. 

At this point you have the firmware you need on the arduino nano, and do not need to reflash the image in the laser etching software, unless you used a generic firmware. 

If you do not have the hex files, do a little looking around the forums, i think i seen it either on the website or this forum some where, it will turn up.

Place the arduino back on the controller board, and start etching, or at minimum you might have to re-do the bootloader if you used a generic hex image to get the thing work.  Either way you should be ready to go. 

Hope this helps someone out there from spending hours or days trying to get a laser etcher back up and running again. 
It took me about 3 to 4 days to find all this, and about 2hrs to download and set everything up, and less then 1 min to drop the file on the arduino. 

Good luck.
« Last Edit: March 25, 2020, 06:12:07 PM by sigswood »