Raspberry Pi As An AVR Programmer

AVR programmers can be bought for just a few dollars on the Internet, but if you’re building an expansion board with an AVR for your Raspi, this is the build for you. It’s a safe way of programming an AVR via the Raspi’s GPIO pins that uses an extremely minimal circuit.

The AVR ISP interface looks a lot like an SPI interface, and the easiest way to program an AVR with a Raspi would be to bitbang all the commands from the GPIO pins. Sometimes, though, the logic of the AVR and Raspi would be at different levels, so while bitbanging may work in a pinch it’s not something anyone should use regularly.

To get the Raspi and AVR talking to each other safely, [Steve] built a small circuit from a 74244 buffer and a FET. With the added support for Linux GPIO avrdude programming, it’s a snap to program an AVR with a Raspi.

A few days ago we ran across a hugely overwrought PIC programmer for the Raspi, so we’re glad to see another round in the PIC/AVR holy war go to the AVR camp.

Thanks [Mateusz] for sending this one in.

23 thoughts on “Raspberry Pi As An AVR Programmer

  1. “AVR programmers can be bought for just a few dollars on the Internet, but if you’re building an expansion board with an AVR for your Raspi, this is the build for you.”.

    In other words “The Raspberry PI is the ultimate solution looking for a problem, here’s another example.”

    If I can buy a USBasp for $3.50 shipped, why would I buy a $47 Raspberry PI and then hand build an AVR programmer on top of it? (No, the Raspberry PI was never $25 nor ever will be). Is HAD is getting kickbacks from Broadcom? And what about Atmel (for all the older Arduino blather)?

    1. How does a raspberry pi cost $47? Were you including shipping, because if so, that’s not fair to the Raspberry Pi Foundation. I got mine for $35 plus $8 for shipping to the US, which I would not consider too terrible considering its from the UK. As for the $25 price, when the model A comes out, it will cost $25. Why are you so sure that it won’t cost $25?

      1. Go to google and search it.
        Newark: $46.64 with est. tax & shipping
        Try to find one for less.

        Not fair to the Raspberry Pi Foundation??? Aiya!
        Hubris achieved new high today.

        Shipping is always a factor in the price of any product. Especially one that weighs like 5 ounces.

    2. If I can buy a USBasp for $3.50 shipped, why would I buy a $47 Raspberry PI and then hand build an AVR programmer on top of it?

      If you wanted to have rpi and extend it with some avr’s, you can now reprogram them in field without having additional programmer.

      1. If your basis is you wanted to have an rpi and are looking for something to do with it and that something has already been done (very cheaply), that’s a solution looking for a problem.

        Is the cost worth it?

    3. You’re partly right about a solution looking for a problem, in the original blog post (mine) I covered that point:
      “You might reasonably wonder what is the point if extra hardware should be used since external USB programmers can be bought cheaply from Ebay. However, if you are going to add an extension PCB to your Raspberry Pi anyway, for instance to communicate with a remote Atmel processor, then including an ISP programmer makes sense and adds very little cost.”

    4. I bought my RPi for AUD$41.80 including GST (Australian sales tax) and shipping. I also got other things with the RPi as well, but that’s beside the point ;P

      Regarding this being a waste, it depends. If you suddenly need to program microcontrollers, can you really wait upto a month for that cheap ebay programming to be delivered? If you already have the parts laying around (note, I have 2 RPis, I don’t intend to use them just as microcontroller programmers ;P) then why not quickly program the AVR with the board? Sure, if you have the time, you could wait for something dedicated, or you could make your own USB AVR programmer (some people do this, and have to find a way to program that AVR) with bits from the local store and a RPi.

  2. Nice write up and all, but a uC paired with an embedded computer is crying out for bootloader. Get an ATMega32u2/4/6 and it comes pre-programmed with a decent boot loader already supported out of the box by Raspian:
    apt-get install dfu-programmer
    Just a 2-wire USB connection required.

    1. Sometimes you just want your own bootloader installed. I’m using the Ciseco XRF module to communicate between the Raspberry Pi and an ATmega1284P at 9600 baud. I’ve not seen any pre-programmed ATmegas operate at such low baud rates.

      I’d like to allow as many people as possible to be able build my AuroraWatch magnetometer so I am hoping to use only through-hole components. Since the ATMega32u2/4/6 is only available in very fine pitch surface mount packages it isn’t compatible with my target audience.

  3. I put a little tutorial for some friends on this last week, and had no trouble programming chips even after omitting the line level converter.
    This works on the latest rasbian update (as of last week)

    :~$ wget http://project-downloads.drogon.net/files/wiringPi.tgz

    :~$ tar xzf wiringPi.tgz
    :~$ cd wiringPi/wiringPi
    :~$ make
    :~$ sudo make install
    :~$ cd ../gpio/
    :~$ make
    :~$ sudo make install

    :~$ wget http://project-downloads.drogon.net/files/avrdude-doc_5.10-4_all.deb
    :~$ wget http://project-downloads.drogon.net/files/avrdude_5.10-4_armhf.deb
    :~$ dpkg -i *.deb

    and pin assignments

    mosi miso sck vcc gnd reset
    20 22 24 1 6 6 raspberry pi (zigzag counting
    from the top)
    19 18 17 7 8 1 atmega328 (down-left side
    up-right side counting)

    :~$ sudo apt-get install arduino
    :~$ arduino

    open up a project and compile it while holding shift(verbose output)
    there should be a line at the bottom that says something like

    :~$ cd /tmp/build12949127349021743091/
    :~$ sudo avrdude -p m328au -c gpio -v -U flash:w:blinky.cpp.hex

  4. As [johnlmitchell] pointed out above in a comment, the first link in the article should be to the stevemarple’s website, not to the mailing list archive (the latter I’d expect to be linked only as “Linux GPIO avrdude programming”).

  5. So I have tried programming an avr using this method but i am not sure my connections are OK. have installed wiringPi and avrdude and when i try to program both atmega16 and atmega32 i get:
    avrdude: AVR device not responding
    avrdude: initialization failed, rc=-1

    I have hooked up 5V pi to VCC (mega).
    MOSI ->MOSI.
    MISO<-Voltage dividerSCK
    GND ->GND and RESET

    Not sure if this configuration is possible but dont have any lvl-shifters and as far as i can see ATmega16 required 5V to operate so thats why i tried with a voltage divider on miso. Have triple checked connections but can’t get any further.
    Anyone have an idea?

    PS. The hexfile i took from ave studio library, project built for each type of proc ive tried with (16/32).
    Command used: sudo avrdude -p m16 -c gpio -v -U flash:w:Test1_16.hex.


    avrdude: Version 5.10, compiled on Jun 18 2012 at 12:38:29
    Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
    Copyright (c) 2007-2009 Joerg Wunsch

    System wide configuration file is “/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 : gpio
    AVR Part : ATMEGA16
    Chip Erase delay : 9000 us
    PAGEL : PD7
    BS2 : PA0
    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 4 10 128 0 no 512 4 0 9000 9000 0xff 0xff
    flash 33 6 128 0 yes 16384 128 128 4500 4500 0xff 0xff
    lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
    lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
    hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
    signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
    calibration 0 0 0 0 no 4 0 0 0 0 0x00 0x00

    Programmer Type : GPIO
    Description : Use sysfs interface to bitbang GPIO lines

    avrdude: AVR device not responding
    avrdude: initialization failed, rc=-1
    Double check connections and try again, or use -F to override
    this check.

    avrdude done. Thank you.

  6. I’ve got a AVR ISP “Cap” in my Tindie store now. It uses the SPI GPIO pins for MOSI, MISO and SCK and uses a non CE GPIO pin for !RESET so that if you use SPI instead of bit-banging then !RESET can be separately asserted and released.

    I also included a power supply voltage switch that lets you choose between 3.3v, 5v or no target power. And the power is fed through an AP2331 current limiting switch to protect the Pi from shorts and hot-plug voltage sags and the like. And the programming is done via a tri-state bus buffer chip powered by the target power, so it’s agile to any (reasonable) target power voltage.


Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.