close-circle
Close
0%
0%

AVR Programmer for Raspberry Pi

A simple board that lets you use the SPI interface on a Raspberry Pi to program ATMEL AVR microcontrollers.

Similar projects worth following
close
This project is a simple board that allows an ATMEL AVR microcontroller to be programmed using the SPI interface of a Raspberry Pi. It also has a header that can provide buffered outputs for up to four of the Raspberry Pi's GPIO pins.

BACKGROUND

I have worked with a number of microprocessors and microcontrollers over the years. My current interest lies with AVR microcontrollers from ATMEL. I have a development system consisting of a motherboard and plug-in boards that hold the AVR, and other peripherals. I wrote and compiled programs for my AVR parts on a Raspberry Pi. I used a usbtiny connected to the Pi to program AVR parts plugged in to the CPU board of my AVR development system. This worked great until one day the usbtiny stopped working. I have an idea about what happened.

My Raspberry Pi and my AVR development system are powered from different sources. When I was writing code to interface with some hardware I often left the usbtiny connected between the Pi and the development system. Powering the development system without power to the Pi (or vice versa), or changing wires between the development system and a solderless breadboard, must have damaged the AVR on the usbtiny programmer. The LEDs on the usbtiny were no longer lighting up when connected to the Pi and the Pi wasn't seeing the usbtiny.

The usbtiny is a simple board with a single AVR AT90S2313 as the main component. When I drew up a schematic for the board I discovered there is no protection for the I/O pins of the onboard AVR which go to the AVR part to be programmed. I was now without a programmer for AVR parts and unable to continue work on some projects I had started. I had to decide whether to repair my usbtiny (if possible), buy another one, or use a different programmer.

I searched for information on the usbtiny to see if there was information available that would let me repair it. I found information about a very similar programmer to the usbtiny. It used an ATtiny2313 and included the program for the AVR. The ATtiny2313 is a replacement for the 90S2313 (which is no longer available). I think some changes to the pin assignments in the software I found should let me get the usbtiny board working again but I would still need a way to program the AVR microcontroller.

That is where this project comes in.


DETAILS

While searching for information that could help me repair my usbtiny AVR programmer I saw information about using the SPI interface of a Raspberry Pi to program AVR microcontrollers. I have a Raspberry Pi sitting on my workbench and was already using it to cross-compile programs for AVR microcontrollers. The wiring between the Pi and the AVR microcontroller is simple and I wouldn't need any components I didn't already have on hand. The software needed to program the AVR parts using the SPI interface is avrdude (which I was already using with my usbtiny). It sounded like the ideal solution to my problem of how I was going to continue programming AVR parts.

It didn't take long to wire up an AVR to my Raspberry Pi using a solderless breadboard. I use Raspbian on my Pi. I soon discovered that the version of avrdude available in the standard Raspbian repositories did not support using the SPI interface. That problem was solved by downloading, compiling, and installing the latest source for avrdude. After updating avrdude I was able to read the signature bytes from an AVR part I already had on my solderless breadboard.

I soon verified I could use avrdude to read and write the memory of an AVR using the SPI interface of my Raspberry Pi. It worked well, most of the time. (See the instructions section below for why I say "most of the time".) Now that I knew it all worked the next step was to design a circuit and PCB so I could free up space on my solderless breadboard and simplify the wiring when I needed to program an AVR part.



FEATURES

  • Has both 6-pin and 10-pin programming headers
  • Can feed +5V to an external circuit by installing a jumper on an on-board header
  • Uses an IC powered by 3.3V to buffer signals but it is 5V tolerant
  • Can buffer up to four signals from (or to) a Raspberry Pi's GPIO header

avrdude_gui.py

A front-end GUI for avrdude written in Python using wxPython.

x-python - 59.83 kB - 07/31/2016 at 17:18

download-circle
Download

  • 1 × PCB Electronic Components / Misc. Electronic Components
  • 1 × 74LVC245 Logic ICs / Receivers, Transceivers
  • 3 × 220 ohm resistor
  • 1 × 1k ohm resistor
  • 1 × 10k ohm resistor

View all 13 components

  • Comments on avrdude_gui

    Kevin09/30/2016 at 20:57 0 comments

    The UI of the avrdude_gui program available here isn't very good but the UI of the original C++ version wasn't any better. There are too many options in the one window. UI designers seeing it are probably gagging. I don't have the time or interest to make a radical change in the look and feel of the program. What you see is the result of a quick and port of the program from C++ to Python. I just wanted something easy to use without having to keep looking up all of the command line options available in avrdude.

    Porting the program from C++ to Python gave me an excuse to do a bit more programming in Python and learning more about using wxGlade to make a complicated screen layout. There are a couple of minor issues in the layout that I can't be bothered to try fixing but they are so minor most people may not even notice.

    Bottom line is the program may not be pretty but it works and can be helpful in working out the command line you need to perform some operation using avrdude.

  • The avrdude GUI is now available

    Kevin08/01/2016 at 03:53 0 comments

    I have uploaded the graphical front end that I've been using for the avrdude program. The front end program is based on a C++ program called avrdude_gui. I rewrote the C++ program in Python and used wxPython for the graphical display. I kept the general look and layout of the original C++ program but added support for many new options available in the 6.1 version of avrdude that were not available when the original C++ program was created.

  • Improved design

    Kevin08/01/2016 at 03:27 0 comments

    I have been using this interface to program an AVR microcontroller I'm using in another project. It has been working but I sometimes experienced reliability issues. The avrdude program couldn't always communicate with the AVR or the output pins of the AVR wouldn't behave properly after it was programmed. I found myself moving a wire before I used avrdude to program the AVR and moving the wire back after the programming of the AVR was complete. It soon became annoying having to do that each time I wanted to test changes to code I was using in the AVR. I started thinking if I could put the outputs of the '245 in to tri-state mode when it wasn't being used to program an AVR it would simplify things and make it easier to use the programmer.

    The change needed to the circuit was minor. The reset line from the Pi can also be used as the chip enable line of the '245. When the line goes low to reset the AVR part to being the programming process it enables the outputs from the '245. When the line goes high, allowing the AVR to run the program it just received, the outputs of the '245 are put in to tri-state mode. I added a jumper to the PCB so the chip enable input of the '245 can be driven by the reset line or it can be tied to ground when the '245 is being used to buffer GPIO lines.

    I added the new jumper to the schematic and PCB. While I was updating the PCB layout I made some additional changes. I modified the silkscreen so all component references can be seen and added the part values for the resistors and capacitor. I also reduced the board width by 0.05". The images in the gallery have been updated with the latest version of the schematic, PCB layout, and 3D model of an assembled board.

    I have been using the modified version of the programmer for the last 5 days and it has really been a big help. I no longer need to move any wires when switching between running a program on the AVR and programming the AVR with new software.

  • PCB changes and completed instructions

    Kevin01/09/2016 at 07:05 0 comments

    It has been a while since I last added to the project project log. I've been working on some other projects and I took a bit of a break for the Christmas holidays and new years.

    I have just completed work on the instructions section for this project. There have also been additional changes to the PCB layout since I made my last project log entry.

    While I was working on adding the last few items to the instructions section I thought of having an option to provide either 3.3V or 5V to external circuit but decided it was too dangerous. If the external circuit was being separately powered by 5V and the programmer board was set to provide 3.3V the external 5V power would get fed back to the 3.3V rail of the Raspberry Pi which would ruin the Pi.

    The other thought that came to mind while finishing the notes for the instructions section was to make it easier to use the unused buffers in the 74LVC245. That resulted in additional changes to the PCB. I moved the resistors and the '245 to allow room for pads to allow access to the unused inputs of the '245. I then had to widen the board by 0.05" to make room for a header to be installed in the new pads and allow for the use of a socket for the '245. I think the PCB is now done and won't need any further changes, but I've thought that before while working on another PCB.

    The last thing I still need to do related to this project is make my updated version of avrdude_gui available for download.

  • Corrections to components list

    Kevin10/25/2015 at 00:31 0 comments

    The quantities of 220 ohm and 10k ohm resistors required, as stated in the components list, were around the wrong way. I have updated the required quantity for these resistors.

  • Minor design changes

    Kevin10/22/2015 at 20:11 0 comments

    After I made some changes to the first revision of the PCB I sent the design to OSHPark to get some boards made. It was only after I received the boards from the PCB maker that I became aware of a minor problem with the design.

    There was nothing wrong with the wiring of the board. The problem was a mechanical issue. I had placed P1 beside the GPIO header. That resulted in the left side of the PCB extending out past the left edge of the Raspberry Pi PCB. This won't have any impact on the ability to use the board when the Pi is not in an enclosure. If the Pi is sitting in an enclosure there may not be enough clearance to allow the AVR programmer board to be plugged in to the GPIO header.

    To fix the problem I moved the location of P1, and reduced the overall width of the board from 1.9" to 1.75". In the most recent PCB revisions I modified a few traces to shorten them and I added a ground plane to the bottom of the PCB.

    I have added a 3D view of the latest revision of the AVR programmer board to the gallery. I also added front and back views of the second revision of the PCB as it was when I sent it out to OSHPark in March. I will write up some notes for the instructions section of this project page in the (I hope) near future.

View all 6 project logs

  • 1
    Step 1

    Project Requirements

    To program AVR microcontrollers using the AVR Programmer for Raspberry Pi board there are several things you will need. They are:

    1. A Raspberry Pi (naturally)
    2. An assembled AVR Programmer for Raspberry Pi board
    3. An AVR cross-compiler toolchain (optional)
    4. The avrdude program (built May 26, 2013, or later) that includes linuxspi support
    5. The avrdude_gui front-end GUI for avrdude (optional)
    6. An AVR microcontroller you want to program
    The interface board of this project has a 26-pin header that plugs on to the GPIO header of the model 1 A or B versions of the Raspberry Pi. You might have some difficulty in plugging the board on to a model A+, B+, or 2B which use a 40-pin GPIO header.
  • 2
    Step 2

    Configure the Raspberry Pi

    I use the Raspbian distribution of Linux on my Raspberry Pi. In Raspbian the kernel driver for the SPI interface is disabled by default. The SPI driver must be enabled before you can use it to program AVR microcontrollers.

    To enable the SPI interface you must remove the blacklisting entry for spi-bcm2708 in the /etc/modprobe.d/raspi-blacklist.conf file, or use the raspi-config to enable the SPI interface.

    Once you have removed the blacklisting of the SPI driver you must either reboot the Raspberry Pi or load the driver manually with:
    $ sudo modprobe spi-bcm2708

  • 3
    Step 3

    Install an AVR cross-compiler (optional)

    If you are going to use the Raspberry Pi to write and compile programs in C for AVR microcontrollers you will need to install a cross-compiler. Install the following packages to compile programs for use on an AVR microcontroller:

    • gcc-avr - The GNU C cross-compiler for AVR
    • binutils-avr - Binary utilities supporting Atmel's AVR targets
    • avr-libc - Standard C library for Atmel AVR development

View all 11 instructions

Enjoy this project?

Share

Discussions

Aleksejs Mirnijs wrote 08/01/2016 at 14:20 point

Hi! Nice project. I personaly programm Atmer microcontrollers with my desktop Raspberry Pi and always can't find some time to make board like this. 

Maybe you can put here PCB/Schematic desing files?

  Are you sure? yes | no

Kevin wrote 09/30/2016 at 20:58 point

I do intend to provide the design files for this project. I need to regenerate the gerbers so they are up to date with the last minor change to the PCB layout before I release the files.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates