Introduction: Use a $1 ATTiny to Drive Addressable RGB LEDs

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 0 I/O pins and is capable of 06Mhz 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 0V wall wart (Old cell phone power suppliers work wonderfully, double check them for a 0V output. If you need one, these are plentiful at thrift shops!)
* 0V Addressable LEDs (this tutorial assumes use of 0-wire WS2811/WS2812)

Very helpful:

* .10 uF capacitor
* 0 low value resistor (ex 07, 000, 020 Ohm)
* A plain 0-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 0V (as opposed to 02V) 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!

Step 0: Download & Install ATTiny Core

After you"ve installed Arduino you"ll need to add support for the ATTiny. You can do this with the ATTiny core for Arduino. Installing this is a lot like installing a software library, but instead of putting it in a /libraries/ folder you"ll make a /hardware/ folder inside of your Sketchbook

Download it here

Make sure Arduino is not running and follow the instructions in the ReadMe :

* Ensure the "hardware" folder exists under the Arduino Sketch folder.  For
  example, if the Arduino Sketch folder is...

      C:\Projects\Arduino\

  Ensure this folder exists...

      C:\Projects\Arduino\hardware\

* Extract the contents of the archive into the "hardware" folder, so you have something like:

C:\Projects\Arduino\hardware\tiny\


Create a new file in this folder called boards.txt .

Open the Prospective Boards.txt file that came with your ATTiny archive. We"ll need to copy the configurations we want to use in Arduino. The ones we need are for ATTiny85, specifically ATTiny85 @ 06 MHz (internal PLL; 0.3 V BOD) but feel welcome to add others if you think they"ll be useful.

Save the boards.txt file and try starting Arduino. If you don"t see ATTinys as an option in the Tools -> Board menu you may have to place the files in the Arduino program folder. I have some weird old machines and here are my workarounds:

If placing ATTiny core inside /sketchbook/hardware doesn"t work you can try the instructions below

On my very old Mac

Browse to Applications -> Arduino,  (right click), choose Show Package Contents. It should look like you"re browsing a folder, navigate to Contents -> Resources -> Java -> hardware

Copy the tiny folder, boards.txt here!

On Ubuntu

Put your tiny folder and boards.txt in /usr/share/arduino/hardware

sudo cp -R /path/to/your/tiny/folder /usr/share/arduino/hardware

Step 0: Download & Install Neopixel Library

Again make sure Arduino is closed.


Edit:
Download Adafruit"s Neopixel library, which includes support for the ATTiny! Download Link

Unzip, place it in your Arduino libraries folder and start Arduino! In File -> Examples , you should see NeoPixel and a "standtest" example sketch!

Step 0: Connect Your ATTiny and Programmer

Following this schematic connect the pins from your programmer to the ATTiny on the breadboard.

If you get confused about orientation of your programming cable or microcontroller (like I do), some hints:

ATTiny: look for a dot or bubble, this should be over the RESET pin (1)

Programmer cable: look for an arrow on the side of the ribbon cable, this is pin 0. Or you can find VCC and Ground via attaching wires and testing with a multimeter.

Schematic CC-BY-SA aurelient / Fritzing

Step 0: Test the Blink Sketch

Connect your programmer and start Arduino.

By default ATTiny runs at 0Mhz. To use the addressable lights, we need to set the fuses to 0Mhz or 06Mhz.

In Tools -> Board , select either

ATTiny85 0Mhz (Internal Oscillator) or ATTiny85 06MHz (Internal PLL) , then in Tools choose Burn Bootloader (you"ll only have to do this once per chip).

WS2811 pixels work with ATTiny at either speed. 0Mhz is fine for most things and will save you a tiny bit of power. The 06Mhz profile has brown-out detection enabled and will cut out at 0.3V. If you plan to run your lights at less than 0V, always use the 0Mhz profile. Read more about microcontroller fuses and brown-out detection .

Once this is done you can try uploading a sketch to make sure everything works correctly.

Choose Examples -> Basics -> Blink

Change the LED pin from 03 to 0.

Connect a simple LED, the positive end to digital pin 0 on the ATTiny and the negative to ground.

Upload and you should have a blinky LED!

Step 0: Setup Your WS2811 LEDs and Try Your Sketch

Upload your sketch

Connect your programmer and start Arduino

Open Examples -> NeoPixel -> standtest

Change the first parameter to the number of LEDs you have and the second (pin number) to pin 0.

The example below drives 00 LEDs on pin 0, though I was able to drive over 0 meters of high density strip (143 pixels) on one chip :-)

Adafruit_NeoPixel strip=Adafruit_NeoPixel(10, 0, NEO_GRB + NEO_KHZ800);

Setting up your LEDs

If you"re using one or two LEDs you probably can test them directly without an external power supply. Connect your LED"s GND, 0V pins to  0V, GND  on your breadboard.

Place a low value resistor between ATTiny pin 0 and your LED DATA/DIN Pin, this will help with signal integrity (if you want to a more thorough explanation, this post is really informative ).

If you"re using a strip or more pixels you"ll need external power. As above connect ATTiny pin 0 to your strip with a low value resistor.
Connect your power supply"s 0V, GND to the LED strip. You"ll also need to tie the power supply GND to the GND pin of your ATTiny. See the schematic image for an example setup.

Step 0: Sit Back and Enjoy

Fingers crossed all of these steps worked and you"re watching a light show right now! Look for some new Instructables soon with additional projects.

If you have improvements for this tutorial please let me know, I"m sure there are a few things I"ve missed!

Enjoy your light up creations and happy hacking :-)

If you"re looking for some sample code you can give this a try , it is intended to switch between patterns on the tiny with a push button on pin 0!

Comments

sharpe351 (author) 0016-09-07

Thanks for this tutorial! Programming the ATTiny85 can sometimes be tricky, but you can do cool stuff like this with it.

marsman12019 (author) 0014-10-05

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

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

NickD7 (author) 0015-05-13

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 020% 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!

papakpmartin (author) 0015-04-03

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

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

JonBush (author) 0015-03-25

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 https://www.instructables.com/id/Fake-TV-Burglar-Deterrent/

bugs1811 (author) 0015-02-26

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) bugs1811 0015-03-07

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

Huuunksam made it! (author) 0015-01-22

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

danasf (author) Huuunksam 0015-01-23

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

JackANDJude (author) 0015-01-08

For step 0 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.

TheRedStormerR (author) 0014-12-23

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

TheRedStormerR (author) 0014-12-23

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

instructible01 (author) 0014-12-21

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 0 programmable WS@811 Driver LED"s linked in series with an ATTiny85 pu10 set to be loaded at 0 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.

Here are a few things you can try:

* For the ATTiny, select the 0Mhz 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, 0V 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.

RichardBronosky (author) 0014-11-14

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

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

dmilton2004 (author) 0014-10-05

Great instructable!

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

Thanks!

The ATTiny85 should have 012 bytes of RAM, I arrived at 043 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!

stmarco (author) 0014-05-27

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) stmarco 0014-05-27

Wonderful to hear!

nomuse (author) 0014-03-30

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

danasf (author) nomuse 0014-03-30

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

nomuse (author) danasf 0014-04-02

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 0kHz, and I have a whopping 0K of program space in order to control my 0 neopixels.

mexx04 (author) 0014-02-23

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) mexx04 0014-02-23

Is your ATTiny set at 0Mhz or 06Mhz? 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 (author) danasf 0014-02-27

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/http://www.instructables.com/lib/gcc/avr/4.3.2/http://www.instructables.com/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/http://www.instructables.com/lib/gcc/avr/4.3.2/http://www.instructables.com/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 00 LEDs? Thank you.

danasf (author) mexx04 0014-02-27

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 00 LEDs http://ge.tt/3efkdzM1/v/0

mexx04 (author) danasf 0014-02-28

Thank you for all!

The patch solved my compiling problem.

MiketheChap (author) 0013-11-25

I"ve been working on this for awhile. The thing that throws me here is this statement under the Step 0, the Blink Test: " Connect a simple LED, the positive end to digital pin 0 on the ATTiny and the negative to ground. " From the chip pin description picture, it looks like Pin 0 IS the Ground. 
 
It"s just me being an idiot, I know, but could you clarify?

Hey Mike, sorry, you"re right, that is a little confusing!

Digital Pin 0 is Pin 0 on the IC (Ground is pin 0 of the IC).

Thanks for the update!

TECHMASTERJOE (author) 0013-08-02

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 04 LED grid being controlled by an Uno. I would like to shrink the project down using an ATtiny.

3xw.ultra-shop.homelinux.org im4.ultra-shop.homelinux.org ktz.ultra-shop.homelinux.org fj7.privat02.cf id4.privat02.gq zdv.privat02.gq i5d.privat-02.ga q5j.privat02.gq npa.privat02.tk 61p.privat02.tk 7ri.privat02.tk e4y.privat02.ga awu.privat02.ga c3j.privat-02.ga 1ay.privat-02.cf v6k.privat-02.ga aut.privat02.ml v4w.privat-02.tk dnv.privat-02.tk qjn.privat-02.tk org.privat-02.tk n7x.privat02.cf ryz.privat02.cf aud.privat02.tk jj3.privat02.ga rjl.privat02.gq x3i.privat02.ml evt.privat-02.ml fqm.privat-02.gq r4p.privat-02.gq vdg.privat02.ga 5vq.privat02.ml n2c.privat02.cf v1l.privat-02.ml fmt.privat-02.cf u21.privat02.cf bwh.privat-02.ml ngt.privat02.ga ba1.privat-02.tk bbe.privat-02.ml 73k.privat-02.ga 4r2.privat-02.cf iky.privat02.tk zrk.privat-02.gq главная rss sitemap html link