loading
Picture of Use a $1 ATTiny to drive addressable RGB LEDs
0.028378358234288914IMG_20130524_091555.jpg
0.8397143550053319IMG_20130524_084659.jpg
Arduinos are wonderful and easy to work with, but there are some projects where you need a microcontroller, or want to add some interactivity but don't really want to dedicate a $20-30 board!

At a little over $1/each (less in bulk) the ATTiny85 is a great chip for the job: it has 6 I/O pins and is capable of 16Mhz with minimal external components, is enough to work with many sensors, even drive popular addressable LEDs like Adafruit's NeoPixels, WS2811 strips.

The setup process is a little technical, but not too scary I promise, and you can use the familiar Arduino programming environment.

What you'll need:

* An ATTiny (this tutorial uses the ATTiny85-20PU)
* a USB ISP AVR Programmer (My tutorial uses this one)
* a breadboard
* some jumpers or wires (color coded wires are really helpful)
* a computer with the latest Arduino software installed (if you don't already have it, download here)
* a 5V wall wart (Old cell phone power suppliers work wonderfully, double check them for a 5V output. If you need one, these are plentiful at thrift shops!)
* 5V Addressable LEDs (this tutorial assumes use of 3-wire WS2811/WS2812)

Very helpful:

* .10 uF capacitor
* 1 low value resistor (ex 47, 100, 220 Ohm)
* A plain 1-color LED for testing

If you're looking for addressable RGB LEDs try Adafruit's Neopixel line or WS2811. They come in strips, pixels, segments, modules of many varieties. Working with 5V (as opposed to 12V) will be easier for this tutorial, so that's what I recommend!

You can try this sample code if you want to use your ATTiny with lights and a push button or touch sensor!
 
marsman1201910 months ago

What is the purpose of the capacitor in the circuit?

The mouse over on the schematic calles it a "Decoupling capacitor". http://en.wikipedia.org/wiki/Decoupling_capacitor

danasf (author)  marsman1201910 months ago

The decoupling capacitor is helpful when there is noise / fluctuation in your power supply. It can also be a good practice to put a pull-up resistor on your reset line to keep it from floating and your board resetting. It will likely work without these things but can be a good practice.

Adafruit has some nice best practices for the lights themselves:

https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices

NickD73 months ago

hi! first off, great writeup! I have a question: So i'm not using just an Attiny85, but instead an Olimex85s arduino-compatable board that has the attiny built in. Since the people at olimex designed the board with a bootloader, I had to remove a couple modes from your sketch since I was using 120% of space on the chip. I was able to bring the size down and upload the sketch, but what i'm seeing though is that the mode only changes when the button is held down, then when released, it defaults back to the lasrson scanner mode, i'll hold the button down again, and then it'll change to another mode, but when released, back to the larson scanner. So my question is, did you write the code to change modes on a single button press, or when, and only when, the button is held down? thanks!

papakpmartin4 months ago

I'm having trouble programming the ATTiny85. Details here. Any ideas?

https://forums.adafruit.com/viewtopic.php?f=20&t=71466&p=362416#p362416

JonBush5 months ago

This was very helpful for me to get my first AtTiny project off the ground a few weeks ago. I made something else using this knowledge two days ago and posted the instructable at http://www.instructables.com/id/Fake-TV-Burglar-Deterrent/

bugs18116 months ago

Unless I'm missing something obvious, this should also work with an ATTiny45 too. Thoughts? Their just a fraction cheaper, but hey.. if you can shave a few more pennies, why not?

danasf (author)  bugs18115 months ago

Yes, ATTiny45 should work here as well, the trade-off being less RAM and flash for your program!

Huuunksam made it!7 months ago

My first Arduino project (!) and AtTiny project !!Thanks a bunch for the extremely helpful tutorial and links !

IMG_4048.JPG
danasf (author)  Huuunksam7 months ago

Wonderful, I am so happy for you! Congrats and happy hacking :)

JackANDJude7 months ago

For step 5 I get the below error. Any idea why?

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

none of these work!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

none of these work!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I am stuck and cannot find anything that will tell me why everything works through the blink test but the LED's wont work after that . I have 5 programmable WS@811 Driver LED's linked in series with an ATTiny85 pu10 set to be loaded at 8 MHz. I have modified the strandtest example for my correct pin. When I run it all lights go full brightness white. No other change happens. Any ideas? Thanks.

danasf (author)  instructible018 months ago

Here are a few things you can try:

* For the ATTiny, select the 8Mhz configuration in the boards menu and then try setting the fuses again (you can do this via 'Burn Bootloader' in Arduino IDE). Then re-upload your sketch.

* Double-check the wiring your WS2811s, make sure GND, 5V and Data are all correctly connected. Make sure output from microcontroller is going to Data In. Try your code on a full Arduino board to make sure the lights are okay.

* Try another library. I believe FastLED supports ATTiny

Thank you for the prompt reply and guidance! I had already tried everything but the bootloader. I bet that is it. I didn't catch that previously. Can't wait to try it out tonight.

Great Instructable! Thanks for taking the time to make it. I have been programming ATTiny MCUs with a Leonardo clone (SparkFun Pro Micro 3.3v). Here is a short video I made documenting the process for my Dad.

[[Video(https://www.youtube.com/watch?v=c4k59CFpYCA)]]

dmilton200410 months ago

Great instructable!

I do have a quick question tho: How did you connect 143 neopixels to a single ATTiny85 without running out of RAM? According to the datasheet it only has 256 bytes of RAM and 143 pixels would take at least 429 bytes! I would love to know how you did that. By my calculations the absolute maximum number of pixels would be 85 (85 x 3 bytes per pixel = 255 bytes). But that would leave only a byte for variables/stack.

Thanks!

danasf (author)  dmilton200410 months ago

The ATTiny85 should have 512 bytes of RAM, I arrived at 143 pixels while testing in practice. http://www.atmel.com/devices/attiny85.aspx

Adafruit's Trinket uses the same chip and they confirm being able t drive ~150 pixels. https://learn.adafruit.com/introducing-trinket/pro...

Happy hacking!

stmarco1 year ago

Thanks for this instructable, i was trying it on my own but my ATtiny was not working at the correct speed, thanks to the flashing of the bootloader everything works now :)

danasf (author)  stmarco1 year ago

Wonderful to hear!

nomuse1 year ago

Did you have to burn fuses to set the ATtiny85 at 16MHz? I thought it came out of the box at 8MHz.

danasf (author)  nomuse1 year ago

I believe the fuses are set at 1MHz by default but I could be wrong. You can use the tiny at either 8MHz or 16MHz to drive the pixels, when I published this the library was only compatible at 16.

nomuse danasf1 year ago
Thanks -- this helped a lot.

I updated my ATtiny defs file with the latest version, then ran "Burn Bootloader" from the Arduino IDE whilst connected to my "naked" ATtiny85 via the same Adafruit ISP you are using.

Success, appears to be running at 8kHz, and I have a whopping 8K of program space in order to control my 4 neopixels.
mexx041 year ago

I can't compile the sketch for ATTiny85, maybe Adafruit has change something.

I have errors like:

C:\arduino-1.0.5\libraries\Adafruit_NeoPixel/Adafruit_NeoPixel.h:47: error: expected `)' before 'n'

danasf (author)  mexx041 year ago

Is your ATTiny set at 8Mhz or 16Mhz? Try the other clock value if you haven't already. Set the value, burn bootloader, upload?

If that doesn't fix it, this old fork of NeoPixel library was designed for (Tiny based) Digispark, what I used before support was added to the main branch. https://github.com/Bluebie/Adafruit_NeoPixel

mexx04 danasf1 year ago

It did not matter what frequency I had set, it did not even want compile.
Now I can compile the Blink and strandtest.ino example, but get the following error in the attiny_pixel_switch.ino:
arduino-1.0.5/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o In function `__vector_default ':
(. vectors +0 x8): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_4 'defined in section text.__vector_4 in core.a (wiring.co).

arduino-1.0.5/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x0): relocation truncated to fit: R_AVR_13_PCREL against symbol `main 'defined in section text.main in core.a (main.cpp.o).
....

Perhaps you could create me one. BIN file for 50 LEDs? Thank you.

danasf (author)  mexx041 year ago

Oh this is the dreaded attiny and sketch >4k problem! See this forum post, for files/solutions to fix it: http://forum.arduino.cc/index.php?topic=116674.0

And here's a .hex for 50 LEDs http://ge.tt/3efkdzM1/v/0

mexx04 danasf1 year ago

Thank you for all!

The patch solved my compiling problem.

I've been working on this for awhile. The thing that throws me here is this statement under the Step 4, the Blink Test: "Connect a simple LED, the positive end to digital pin 4 on the ATTiny and the negative to ground." From the chip pin description picture, it looks like Pin 4 IS the Ground. 
 
It's just me being an idiot, I know, but could you clarify?
danasf (author)  MiketheChap1 year ago
Hey Mike, sorry, you're right, that is a little confusing!

Digital Pin 4 is Pin 3 on the IC (Ground is pin 4 of the IC).
Thanks for the update!
When driving large strips only share ground and data having power crossed can make more noise and make the attiny pll even more unstable then it is. Using a real clock and not the pll can increase the number of lights you can drive by a little bit thanks to a more stable signal.
How many LEDs do you think I can stably drive without adding a quartz crystal? I currently have a NeoPixel 64 LED grid being controlled by an Uno. I would like to shrink the project down using an ATtiny.