Sunday, September 7, 2014

ATtiny85 and ATtiny84 DIY Programming Shield

To program an ATtiny85 or ATtiny84, smaller microcontroller brothers to the ATmega328 used in the Arduino, you can use a dedicated ISP programmer, or breadboard the chips and use an Arduino. I used the latter technique, but as I wanted an easier and more reliable way to work with a handful of chips for multiple projects, I decided to build my own programmer shield.

The Omega-MP, which I bought on eBay, is a great shield to program the ATtiny85 (and many other chips) but didn't support the ATtiny84, so my shield here will support only the ATtiny85 and 84.


Here's a Fritzing diagram of how it's wired. Ignore the labeling of the 14-pin connector. That should represent the 14-pin DIP of the ATtiny84. Pin 1 for both chips is to the left and down (yellow lead on the 85 and red on the 84). The Fritzing program didn't have an exact representation of the prototyping shield I used, so the actual wiring and the diagram will be different in practice. I used a cheap prototyping shield that's readily available on Amazon or other retailers' websites. Use a 10uF capacitor between the ground and reset pin of the host Arduino.

Here's the pinout diagram for the chips: ATtiny Pinouts and ISP Guide

I followed the linked diagram to initially breadboard my chips and then to wire up the shield. I used DIP sockets for the completed shield, but ZIF sockets would probably work well too (but take up a lot more room).

Here's my completed shield, with crappy soldering and all!

Completed Shield on an UNO R3
Top View
Bottom View
I ran the wires for the ATtiny84's 14-pin DIP socket on the bottom, tying them into the Arduino pins. I then routed the ATtiny85's 8-pin DIP socket on top, tying them in to the shared pins alongside the 14-pin socket.

This shield will program one (at a time, won't do two chips at once) ATtiny85 or ATtiny84. It'll also work with related chips from those families, but I don't know why you'd want to use an ATtiny25 or 45, or the 24 or 84 as the price difference at the hobbyist level is nil, but since they are pin identical to their siblings with more memory, they will work.

Friday, September 5, 2014

Control Stop Light with an ATtiny85 or Arduino

One of my first projects with Arduino was to provide a little automation to an old stop light (and crosswalk signal) I had out in the garage. I'd already wired them to individual switches (good for games of "red light, green light"), but the allure of having it operate light a real light (green, then yellow briefly, then red, repeat) was too great. Arduino seemed like the perfect fit.

Of course, the Arduino can't switch anything high voltage nor high amperage. So you'll need to use a relay. I am a big fan of the cheap relay boards like these. For a regular stop light, you'll need three individuals or a four in one. I used a four in one relay board and a two in one separate board for the crosswalk lights. I stuffed it all in a plastic enclosure box. Don't undertake the high voltage part of this project without a firm understanding of the risks involved. This post isn't about high voltage relays or how to integrate them with the Arduino, so I'll assume you know how to do that. Follow along if you want to build a stop light simulator with 5mm LEDs, the same principles apply.

ATtiny 85
I recently wanted to find a way to experiment with using an ATtiny (baby brother of the ATmega microcontroller in the Arduino). I picked up some ATtiny85 and ATtiny84 chips off an eBay vendor. The ATiny can be programmed, with a new library, in the Arduino IDE, are much cheaper than an ATmega ($1.3/ea for the ATtiny85 vs $2.30 for the ATmega328p, and $5+ if you don't want it shipped from China), but are limited in the number of input/output options. The ATtiny runs slower (internal clock, the ATmega uses an external), uses less energy, and comes in a bare chip form factor (need some soldering skills to get beyond the breadboard phase). Here's a good comparison of the two chips.

Since the ATtiny chips run off 5v I planned on using a commodity USB power supply. Since the ATtiny85 has an internal clock chip, it's easier to build a circuit (no external crystal).  My original stop light controller was powered by an Arduino Micro (about $20). So I wanted this new controller to be smaller and cheaper. My total cost to replace the Micro was about $3.

Since I used only 5 outputs and no inputs for my light controller, the ATtiny85 is about the smallest and cheapest of the Atmel chips that will do the job.

First, to program the chip. I used a programmer shield, but you can use some hookup wire and do it yourself or build your own shield. Follow these directions if you want to take that route.

Program it!
Here's the code:

"


int Walk = 3;
int DontWalk = 4;
int Green = 0;
int Yellow = 1;
int Red = 2;

void setup()
{
 

  pinMode(Walk, OUTPUT);
  pinMode(DontWalk, OUTPUT);
  pinMode(Green, OUTPUT);
  pinMode(Yellow, OUTPUT);
  pinMode(Red, OUTPUT);
}


void loop()
{

  //HIGH = ON, LOW = OFF
 
  digitalWrite(Walk, LOW);
  digitalWrite(DontWalk, LOW);
  digitalWrite(Green, LOW);
  digitalWrite(Yellow, LOW);
  digitalWrite(Red, LOW);
 
  digitalWrite(Green, HIGH);
  digitalWrite(Walk, HIGH);
  delay(800);
  digitalWrite(Walk, LOW);
  digitalWrite(DontWalk, HIGH);
  delay(50);
  digitalWrite(DontWalk, LOW);
  delay(50);
  digitalWrite(DontWalk, HIGH);
  delay(50);
  digitalWrite(DontWalk, LOW);
  delay(50);
  digitalWrite(DontWalk, HIGH);
  delay(50);
  digitalWrite(DontWalk, LOW);
  delay(50);
  digitalWrite(DontWalk, HIGH);
  delay(50);
  digitalWrite(DontWalk, LOW);
  delay(50);
  digitalWrite(DontWalk, HIGH);
  delay(200);            
 
  digitalWrite(Green, LOW); 
  digitalWrite(Yellow, HIGH);
 
  delay(350);
 
  digitalWrite(Yellow, LOW);   
  digitalWrite(Red, HIGH);  
 
  delay(1200);             

}
"


Now to breadboard it. Follow this pinout guide to wire it up. Here I used LEDs to take the place of the relay outputs to see if it looked like a stop light and to test my timings. Since my relays are triggered by a "high" signal, when the LED is on, the relay would be triggered to send the high voltage to the light.


It works! Now to solder.

Top of the board
Bottom, my lackluster soldering skills...
Now back out to the garage to plug it in to the relays and the lights.


Here is the final, ready to be buttoned up project.

This photo shows the dramatic size reduction you can realize switching from the already small Arduino Micro to a basic ATtiny85 on some perfboard.

Provided you don't need a bunch of inputs/outputs the ATtiny might be a cost, and perhaps more importantly size, effective solution.

Here's the Fritzing diagram:


Search This Blog