While its fresh in my head, I jotted down some notes on some minor progress I made with a simple project I’m working on - my own take on the LED candle. I want to end up with a compact, battery powered/rechargable unit that will sit and flicker candle-ishly. Maybe I’ll write up the project in full, but here’s how I’ve finally got up and running programming the attiny85 microcontroller that is the brains of the thing:
USBAsp programmer, to flash the chip. It provides 3 pairs of pins and little jumpers to set:
- “power” - i.e use the power provided via the programmer’s (the 5V via USB from my pc) to power the chip while we program it
- “slow” - use the jumper for a slower clock speed (i.e 1mhz - which is how they ship IIRC) I had to remove it to program successfully once I’d set the fuse to run at 8mhz
- “service” - is to do with programming the usbasp itself I think?
So the slightly fiddly but 100% reliable method I’m using is this:
- insert the attiny85 into a socket on a the board I prepared with the 10pin headers wired up to the 8 pin socket
- use 10pin ISP ribbon cable to connect usbasp to socket board. Eventually I’ll figure out how to do this in-circuit, but for now, moving the chip from the socket to my breadboard once programmed isnt so bad
- Using Arduino 1.6.5 IDE, which now has a board manager. I got attiny boards package from https://github.com/damellis/attiny, so in Arduino’s preferences, where it says additional Boards Manager URLs, I’ve added
- Open the Boards Manager and it downloads that and its entries will now show up in Tools > Board menu.
- Pick attiny from the boards submenu
- Pick attiny85 from the processor submenu
- Pick Clock 8Mhz (internal) from the clock submenu. Dont pick external clock unless you’ve got the right oscillator to hand otherwise you’ll render it unusable until you do
- (Burn bootloader)
- Flash the code to the chip with “upload” in arduino IDE.
In the code, bear in mind different clock speed from the bigger & faster chip the arduino uses, and calibrate delays/timing as necessary. In order to debug, I’m using SoftwareSerial library. The attiny85 must be running at 8+mhz for this to work. Basically wherever code says Serial., you do mySerial..
- Connect physical pin 2 on attiny to rx on arduino board
- Connect pin 3 on attiny to tx on arduino board
- Connect ground pin 4 on attiny to arduino’s ground.
- Connect vcc pin 8 on attiny to arduino’s 5v out.
- Connect USB from arduino to pc, so we can monitor attiny’s Serial output in arduino’s serial monitor
Bear in mind v. limited space on attinys. Pick appropriate types for variables (e.g. use byte instead of int when you know the value will by <= 255.) Arduino’s String library and lots of its string functions & operators not available. Probably you could include it, but memory is at a premium. Mostly I was just using this for debugging anyhow, so once I figured out that my debug code was my problem, it was easy to work around.
Once code is working:
- Remove the Serial stuff (i used preprocessor define/ifdefs to make it easy to flip all that stuff off).
- Remove the rx/tx connection.
- Wire up intended Vcc/ground (battery or whatever) to finally cut the cord and be free.