AVR Progamming Shield for Arduino
by MakersBox in Circuits > Arduino
16686 Views, 93 Favorites, 0 Comments
AVR Progamming Shield for Arduino
Do you need a quick and easy way to program AVR chips. Did you know you can use your Arduino and the Arduino IDE? This Arduino shield makes the process much easier.
You can:
- Burn a bootloader onto a replacement Atmega328 for your UNO.
- Make a stand-alone Atmega328 breadboard project.
- Use inexpensive Attiny chips for smaller projects.
- Reprogram a chip in an existing circuit with an ISP header.
This shield lets you:
- Quickly setup to program chips.
- Program a variety of chips easily:
- 8, 14, and 20 pin Attinys.
- 28 pin Atmega168 or Atmega328.
- Quickly see if a sketch is working on pin D3.
- Use on a Arduino Mega (with optional jumpers).
- Create a stand-alone programmer.
There are a lot of AVR programming shields available. That is why we call this one "Yet Another Programming Shield", or YAPS for short. We think ours has a lot of advantages. If you want to learn more about how we developed it, check out http://makersbox.blogspot.com/2013/12/anatomy-of-small-open-source-hardware.html
This project was recipient of a 2013 Innovation Grant from Wyolum which helped us get it to the kit stage.
The kit is available on Tindie.com. Purchasing the kit will save you the time and expense of ordering from several different vendors and avoid the minimum PCB order premium. You will also be helping us develop and share other projects!
Gather the Parts
To start, check to see you have everything:
Bill of Materials:
- PCB available at OSH Park ($20.70 for three copies).
- (1) x 28-pin DIP ZIF socket
- EMSL 9220005 $2.25ea
- Adafruit 382 $3.00
- Sparkfun ZIF PRT-09175 $2.95
- (1) x 6-pin DIL ribbon cable
- $2.50 (EMSL) 3" - or-
- 2 x Ribbon Crimp Connector - 6-pin (2x3, Female)
- Sparkfun PRT-10651 $0.35ea
- Digikey 609-2842-ND $0.90
- Digikey 609-2841-ND $0.82
- (4) x 2x3 male header (or order extra 36 pos. straight header) Digikey 609-3218-ND $0.26
- (3) x 3mm leds (Green, Yellow, Red) yellow
- Digikey 1080-1106-ND $0.33 green,
- Digikey 1080-1115-ND $0.33 red,
- Digikey 1080-1123-ND $0.33 yellow
- (3) x 330-ohm resistors (Digikey 330QBK-ND)
- (1) x 10 uF cap (Digikey P975-ND)
- (1) x 16-Mhz resonator (Digikey X908-ND)
- (1) x straight header (Digikey S1011EC-40-ND, $0.67) [0.120" tail]
- (1) x tactile button (Digikey SW402-ND $0.42)
Optional (for Arduino Mega):
- (1) x 2x2 female header Digikey A26452-ND $1.25
- Four male jumpers
Optional (for Optiboot or Adaloader):
- (1) x Piezo Buzzer
- PS1240Adafruit 160 $1.50
- Digikey 445-2525-1-ND $0.73
Gentlement, Start Your Iron
We are going to assume you have some kit-building experience. If you need some help soldering, head over to http://www.sparkfun.com/tutorials/213 to brush up.
The order of assembly is largely a matter of preference. If you don't have a helper or a vice, I generally go from lowest height to tallest so when the board is reversed on the table, the parts stay in place. Picture numbers correspond to the step numbers:
- Three 330-ohm resistors
- Tactile button
- LEDs:
- Long lead is positive. Look for the "+" on the PCB.
- Green -> Heartbeat, Red -> Error, Yellow -> Programming
- Solder one lead first, check it is seated correctly, and then solder other lead.
- Capacitor (short lead is negative, look for the "-" on the PCB.
- (2x3) headers:
- Use the ribbon crimp connector to hold the header in place.
- Crystal (no polarity, but put the value facing out).
- ZIFF connector:
- Solder one pin on each opposite side, check the seating, and then finish.
- Shield headers:
- It is easiest to place them in an Arduino first to hold them in alignment.
Inspect the board for missing, bridged, or incomplete solder joints. Solder bridges can be fixed using solder braid or a solder-sucker.
Jumper and Options
- The jumper cable is creating by placing one end of the six-strand cable in between the upper and lower parts of the crimp connector and then applying enough pressure to make it lock. Do not use pliers. Use something flat to press down on it.
- With one crimp connector in place, put the jumper on the ISP header and check the length you need to reach the far Attiny85 header.
- Crimp the remaining side on and trim the excess.
Arduino Mega:
This shield will work with the mega, but needs a 2x2 female header added in the lower right corner and four jumper wires to connect with Mega pins 50 - 53.
Adafruit's Sketches:
Adafruit has modified ArduinoISP to give audible indication of programming status. You can add a piezo speaker to the underside of the board.
Adafruit has also modified the Optiboot sketch which will allow you to upload a bootloader or firmware to just about any AVR chip. This process can be done stand-alone, and is very quick if you have a lot of chips to program.
Setup Arduino and IDE
If you want to program anything other than the standard bootloaders, you will need to add the appropriate "cores" to the Arduino software:
- For a "Breadboard Arduino", which is an Atmega328 running on its internal crystal at 8 MHz, you must install the files from "Breadboard.zip" at http://arduino.cc/en/Tutorial/ArduinoToBreadboard into the "hardware" folder in your Arduino "sketchbook" folder.
- For Attiny chips, there are several cores available:
- I like Arduino-Tiny core based on work by David A. Mellis, René Bohne, R. Wiersma, Alessandro Saporetti, and Brian Cook because it supports the tone() command if you want to play sounds on a piezo speaker.
- If you want to program the Attiny2313, you can use the Attiny core.
Setting the settings:
- The stock Arduino software comes with the "ArduinoISP" sketch in the "Examples" section. This sketch must be uploaded without the shield in place since the shield has a capacitor to over-ride the reset signal (or you could use a manual reset before upload, like in the old-old days).
- With the sketch uploaded, install the shield. You should see the green heart LED begin it's pulsing.
- In the IDE, select "Tools" -> "Programmer" -> "Arduino as ISP".
- Select the target chip type using "Tools" -> "Boards".
- Place the jumper cable between the "ISP" header and the correct header for the chip type.
Feel the burn:
Setting fuses is a scary and confusing topic if you look in to it much. Don't bother. They are basically setting that tell the chip how to behave and have to be done only once to a new chip.
- Place the chip in the ZIFF socket, all the way to the left, with Pin 1 in the lower-left corner.
- With the correct "board" selected for the target chip, select "Tools" -> "Burn Bootloader".
- For an Atmega chip going in to a UNO or breadboard, this will set the fuses and upload the correct bootloader.
- For an Attiny, this just sets the fuses. For us, this primarily concerns chip speed.
Upload a Sketch:
- Load the sketch for the target chip. Start with the basic blink "File" -> "Examples" -> "01.Basics" -> "Blink".
- Change the "led" variable from "13" to "3".
- Click the upload icon, or "File" -> "Upload".
- You should see the yellow LED flash and get an "Upload Complete" message.
- If all is well, the target chip should start blinking the yellow LED (attached to D3).
If all is well, pat your self on the back and start planning your next project. If not, move to the next step to do some trouble shooting.
Shoot the Trouble
Troubleshooting:
Go back and check the following:
- "Tools" -> "Serial Port" -> Correct port selected.
- ArduinoISP sketch uploaded and green heartbeat beating.
- Sometimes the sketch will hang and need a reset.
- "Tools" -> "Programmer" -> "Arduino as ISP".
- "Tools" -> "Boards" -> target chip selected.
- Jumper cable set to correct target ship type.
- Target chip in the correct position with pin 1 to the lower left.
We've tried hard to make this as easy and trouble free as possible, but it is still a pretty advance topic as far as life in Arduino Land goes.
- Have faith you can figure it out.
- Run through the steps again.
- Google it.
- Then ask for help.
Some Notes on Attiny Cores
PAGEL and BS2 Warnings:
AVRdude, which is the underlying software for talking to AVR chips generates the following warnings for Attinys:
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny84 avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny84
These warnings can be ignored.
Digital and Analog Pin Numbers:
If you want to engage pullup resistors, and then read an analog value, you need two pin numbers which may or may not match. Take a look at the Attiny85:
// ATMEL ATTINY45 / ARDUINO<br>// // +-\/-+ // Ain0 (D 5) PB5 1| |8 VCC // Ain3 (D 3) PB3 2| |7 PB2 (D 2) INT0 Ain1 // Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 // GND 4| |5 PB0 (D 0) pwm0 // +----+
Note that A3 and D3 are the same, but if you want to engage the internal pull-up resistor on PB2 (physical pin 7), you need the following:
pinMode(2, INPUT);
digitalWrite(2, HIGH); int val = analogRead(1);
A bit confusing. Let me know if you figure out a better way to handle this!
Attiny84 Pin numbers:
Depending on the core you use, the pin numbers are different!
/* “tiny” CORE, aka https://code.google.com/p/arduino-tiny/:
Arduino-Tiny is based on work by David A. Mellis, René Bohne, R. Wiersma, Alessandro Saporetti, and Brian Cook. “attiny84at8.name=ATtiny84 @ 8 MHz (internal oscillator; BOD disabled)” ATMEL ATTINY84 / ARDUINO +-\/-+ VCC 1| |14 GND (D 0) PB0 2| |13 AREF (D 10) A0 (D 1) PB1 3| |12 PA1 (D 9) A1 PB3 4| |11 PA2 (D 8) A2 PWM INT0 (D 2) PB2 5| |10 PA3 (D 7) A3 PWM A7 (D 3) PA7 6| |9 PA4 (D 6) A4 PWM A6 (D 4) PA6 7| |8 PA5 (D 5) A5 PWM */
/* “attiny” CORE aka https://github.com/damellis/attiny/, David A. Mellis “attiny84-8.name=ATtiny84 (internal 8 MHz clock)” ATMEL ATTINY84 / ARDUINO +-\/-+ VCC 1| |14 GND (D 10) PB0 2| |13 AREF (D 0) (D 9) PB1 3| |12 PA1 (D 1) PB3 4| |11 PA2 (D 2) PWM INT0 (D 8) PB2 5| |10 PA3 (D 3) PWM (D 7) PA7 6| |9 PA4 (D 4) PWM (D 6) PA6 7| |8 PA5 (D 5) PWM */
Developing Attiny Sketches on Arduino Board
Developing a sketch for an Attiny can be a bit challenging because it is hard to figure out what is occurring on the chip. With Arduino, you can use Serial.print() to get debugging information easily on the console. Since the actual processing under the AVR hood is very similar, shouldn't you be able to write and test something on Arduino, and then upload it to an Attiny?
Yes! Take a look at the following Blink example, which will compile and run for either an Attiny84, Attiny85, or Arduino:
// Use preproccessor commands to determine board type and pin assignments #if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny84__) #define ARDUINO 0 #define led 3 #else #define ARDUINO 1 #define led 13 #endif void setup() { pinMode(led, OUTPUT); #if ARDUINO Serial.println("I'm an ARDUINO!"); #endif } void loop() { digitalWrite(led, HIGH); #if ARDUINO Serial.println("LED ON"); #endif delay(1000); digitalWrite(led, LOW); #if ARDUINO Serial.println("LED OFF"); #endif delay(1000); }
Other Uses
In addition to placing DIP chips in the ZIFF socket, you can also use adapter sockets to pre-program SMD chips. For my I Can Surface Mount Solder kit I use a DIP to SOP adapter in the ZIFF socket (Image 1). For the Misery Edition of the SMD Challenge, I use a QFN to DIP socket wired to ISP lines (Image 2).
I also use a pogo adapter from Geppetto Electronics to program Geek Spinners after they have been assembled (Image 3 & 4).
Finally, in case you need to program a 3.3V volt system, you may need to use a level shifter. I've used a SparkFun TXB0104.