Raspberry Pi based standalone ZIF Socket AVR Programmer
Program AVR chips with one click of a button:
Project Home Page: https://eeproto.com/portfolio/avr-programmer/
You designed a piece of hardware around an AVR microcontroller, maybe the popular ATmega328. I love this powerful and inexpensive chip. Many projects use it, maybe because it is also the core of the even more popular Arduino UNO.
If you produce your new design two or three times, you flash your AVRs straight from your workstation. If you make 1,000, your distributor will gladly flash them for you. But what if you want, say, 50?
This project gives you all the parts to make a standalone, easy to use AVR programmer. It is Open Source, released under Creative Commons Attribution-ShareAlike 4.0 International License, and it borrows from many other Open Source designs, including Sparkfun's Pi AVR Programmer HAT.
Hardware and software were tested with ATmega168 and ATmega328 chips. Feel free to adapt it to other AVR chips that support SPI programming.
To make your own, get a Rasperry Pi. Any version should work, I tested it with a Pi 2 Model B v.1.1.
Make the custom PCB that connects the AVR socket, buttons, LEDs, etc. to the Pi.
Use the KiCad project in the hardware
folder to order your board. I got some from a low-cost PCB shop along with a stencil. It is a two-layer board with surface mount components on one side. There is a set of Gerber and drill files in the hardware/plots
folder. The BOM in the same folder uses pretty generic components. The octopart BOM might still be up.
Populate the surface mount components first. I use solder past, a stencil, tweezers, and a ReflowR by Lafras H. There are many other ways to do that, including hand soldering or reflowing with hot air like in this EEVblog video.
The 28 pin ZIF sockets can be a little hard to get, the major distributors might not have them in stock. Generic sockets through ama*** worked, too. Just make sure you get 28 pins in two rows with a 7.62mm / 0.3in row spacing.
If you don't feel comfortable with all of that, email me, maybe I have some left over.
Add the through-hole parts. Double check you did not make any inadvertent solder bridges, then plug it in.
Support the PCB on top of your Pi with Nylon hex standoffs and secure everything with M3 screws.
Install the software by following the Installation Guide.
In order to program the AVR, you need two things:
- A compiled HEX flash file.
- The device configuration.
Write and test your AVR firmware as usual. You can use PlatformIO, the Arduino IDE, a straight avr-gcc
toolchain, or any other way. Build your project.
Find the compiled HEX file. For Platform IO, look for a file firmware.hex
in a folder .pio/build/uno
underneath your project directory.
Copy this file to the root of a USB drive and name it firmware.hex
. A standard FAT32 formatted drive works fine.
Create a JSON file called device.json
next to the HEX file on the USB drive. You can use the file from the samples
folder as a starting point.
Adjust the AVR fuse settings to your needs. Here are a few samples:
Fuses | Settings |
---|---|
(E:FF, H:D9, L:E2) | Internal 8 MHz oscillator |
(E:FF, H:D9, L:62) | Internal 1 MHz oscillator |
(E:FD, H:DE, L:FF) | External 16 MHz crystal |
(E:FD, H:DE, L:FF) | default Arduino UNO settings |
Set the chip type so avrdude knows what signature to expect. Common types:
Type | Signature |
---|---|
atmega168 | 1e9406 |
atmega168p | 1e940b |
atmega168pb | 1e9415 |
atmega328 | 1e9514 |
atmega328p | 1e950f |
atmega328pb | 1e9516 |
Check this post for a full list.
Example configuration file:
{
"E": "FF",
"H": "D9",
"L": "E2",
"type": "atmega328p"
}
- Assemble the hardware and install the Pi firmware.
- Prepare the USB flash drive with your hex file and device configuration.
- Power the Pi.
- You should see the
Power
LED turn on. - The
Ready
LED is flashing until a USB drive with a valid device configuration and hex file is plugged in. Plug it in and wait for theReady
LED to turn solid green. - Insert an AVR chip that matches your device configuration into the ZIF socket and lock the socket. The index notch is at the top next to the title print.
- Press the
Go!
button. - The
Active
LED turns on. - If the device needs updated fuse settings, the
Fuses Pass
LED should go green after a moment. - The
Flash Pass
LED goes green once flashing was successful. - If at any time a
Fail
LED starts flashing, the programmer was unsuccessful communicating with the AVR chip. Check everything is wired correctly and the AVR is secure in its place with Pin 1 at the top. Try a different AVR chip. If this problem continues to exist, try reducing the programming bitclock in the Python script.
The Pi runs a small Linux OS based on PipaOS. On boot, it starts a Python script as a background system service.
This script reads the USB drive, looking for both a flash HEX file and a device configuration JSON file.
If both are there, the script starts monitoring the big pushbutton labeled Go!
.
When you press the button, the script runs avrdude to first check the device signature. Then, it reads the fuses. If they need to be programmed, it does that. Last, it writes the HEX file contents to the AVR flash memory.
Looking at the output of the avrdude commands, the script lights the LEDs to tell you what worked and what did not.
You can pull power from the Pi without shutting it down, because PipaOS allows the SD card to be mounted read-only.
The custom PCB mainly connects the SPI lines provided by the Pi to the AVR. A 4066 isolates the two chips when not programming, as the AVR might go into SPI master mode after releasing the RESET line. One momentary push button with a little ESD protection starts the programming, another one allows a clean shutdown of the Pi, in case you decide to run with a different OS setup.
To connect the AVR, you can use any standard socket, although a ZIF socket allows for frustration free insert and removal.
Although it looks like a HAT, technically this is not a HAT according to the HAT Design Guide. It still fits nicely on top of the Pi.
For reasons I don't know, my prototype assemblies would only flash at a bitrate of around 200 kHz. A dirty breadboard assembly ran up to 2MHz. Need to figure out why that is.
This project depends heavily on other people's great open source work, including:
- The PipaOS Linux distribution by Albert Casals
- avrdude AVR programmer
- Kevin's linuxspi extension for avrdude
- Steve's programmer design with 74LVC244 isolating buffers
- adafruit's linuxgpio-based design
- Mark Williams shows how to operate the Pi with the Arduino IDE
- QCPete's writeup on the design of the Pi AVR Programmer HAT
- Volker Urban's Pi/AVR summary (german)
- KiCad, an exceptional and Open Source electronics design software
- Chris Gammell's Contextual Electronics Forum as an endless source of great knowledge.