Saturday, 6 April 2013

ATTiny85-10PU

Arduino Uno

Ages ago I bought an Arduino as I had a project in mind involving monitoring of a solar inverter at a site that is infrequently visited during winter.. The plan was to read the inverter status using MODBUS over RS485, log the time of day and voltage/readings into a file on an SD card.

I made some progress but then ran out of time/interest. I will probably go back to it. The hard part is the MODBUS interface as I have to take all my kit to where the inverter is to work on it.

Project

Anyway my son came to me with a project to construct a container that can protect a wine glass dropped from a 4 story building. His plan was to use an accelerometer to find out when the object is falling and then activate a servo that deploys a parachute.

We don't want to drop an Arduino off a building so the tool of choice was an ATTiny. The ATTiny 85s are super cute 8 legged chips that contain a complete microcontroller and need no external parts to run!

The first problem is that the standard servo library doesn't work on this uC as the built in timers are different. There is an alternative version available from here http://www.cunningturtle.com/attiny4585-servo-library/

First things first, my son ran some simple examples on the Arduino, made LEDs blink, made servos sweep etc. Easy.

Now the ATTiny came in the post so we wanted to program one of these.

Programming an ATTiny

To begin with I just wanted to see blink work on the ATTiny but this proved harder than it looks.

First to program the ATTiny you use the Arduino as an In System Programmer (ISP). There are instructions for doing this here http://hlt.media.mit.edu/?p=1695 that work for the 1.0.4 Arduino IDEm and the Arduino Uno (which we have). The important points are:


  1. Connect the ATTiny as follows: Pin 8 (of chip) to VCC, Pin 4 Gnd, Pin 7 (SCK) to Arduino Pin 13, Pin 6 (MISO) to Arduino Pin 12 and Pin 5 (MOSI) to Arduino Pin 11, Pin 1 (RESET) to Arduino pin 10
  2. DON'T put the capacitor between Gnd and Reset on the Arduino yet!
  3. In the Arduino IDE, with everything setup normally for programming the Arduino (i.e. board is Arduino UNO) load the example called ArduinoISP. Load this into the Arduino.
  4. Unplug, put a capacitor between GND and RESET. Note the stripe must go to GND if you are using an electolytic capacitor.
Now you have to make the Arduino IDE know about an ATTiny. Go here and download the zip https://github.com/damellis/attiny/archive/master.zip Open the zip and copy the attiny folfrt into your Arduino IDE folder under the hardware folder. Restart the Arduino IDE.

Now go to the Tools->Board menu and you should see a bunch of ATTiny options. There is no 10MHz option which confused me to begin with. Choose 8MHz ATTiny 85 (you want to use the 8MHz clock speed to make the 8Bit servo library work).

Now choose tools->burn bootloader. This will set the fuse bits to make the chip run at 8MHz as well as some other settings. You will get a warning like:

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

but you can ignore this.

Now load the blink example sketch, change the led pin to 0 instead of 13 and upload this. Again you get the PAGEL etc warning and it is done. Connect a 330Ohm resiste and LED to pin 5 of the chip and it should blink!

Stuff that went wrong

It took a *lot* of stuffing around to get to this point. It took a while to twig about running the Arduino ISP sketch and THEN uploading to the ATTiny. Ditto the reset pin capacitor.

I got an error along the lines of 

avrdude: Yikes! Invalid device signature
               Double check connectiona and try again, or use -F to override this check

The fact that my ATTiny is a 10MHz one and not an 8 meant I kept wondering if this was the cause of the problem. I though that I should be able to run it at 8 by setting the fuses but it refused to work.

The invalid device signature problem was caused by me confusing the drawing that shows how to wire up the ATTiny. The picture was rotated compared with our setup and I accidentally had SCK and MOSI the wrong way round.

After this I was able to burn the bootloader. Then I tried to burn the sketch but this failed with a verification failure:

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: verification error, first mismatch at byte 0x000         
                        0x47 != 0x00
avrdude: verification error; content mismatch

This turned out to be to do with power. I read that noise can cause problems and that putting a cap across the supply lines can fix this but for me it didn't. The problem was that the power lines on the Arduino are in between the legs of the reset capacitor and we had it plugged into 3.3v instead of 5v. Once I corrected this the sketch burned Ok and I could run blink.

No comments:

Post a Comment