(AT)Tiny Controller for WS2812B
by janth in Circuits > Microcontrollers
9172 Views, 42 Favorites, 0 Comments
(AT)Tiny Controller for WS2812B
Since using an arduino to control the WS2812B inside my christmas decoration was a little overkill i designed a smaller one: Making some standalone snowflakes e.g. as gifts (while keeping my arduino :-)
The MSP430G2452 which i had at hand works only with 3.3V - not enough work reliable with the WS2812B, which expects 5V. (Although it works fine using 5V overvoltage for the micro controller - at least until now... might be interesting how long it will work :-)
So i decided to use a cheap Attiny85. All files and explanations for programming can be found at High-Low-Tech - this awesome webside made the descision easy which attiny to use. Since i use the Adafruit neopixel library, i just tested the different attinys if the example program compiles - for example using the attiny with an internal 1MHz clock won't work... to slow. But the rest seems to work fine.
Basically i used one pin for the data output to the leds and two for a double DIL switch - using the MISO/MOSI/SCK lines for that make programming simple.
Add one double pinheader on one end for voltage and a triple pinheader on the opposite end for connection with the leds.
Some capacitors for buffering and a pull-up resistor(not really necessary, you can also use the internal programmable pullup resistor) finish the layout.
Milling & Soldering
Having a PCB-mill makes life easier (ok, i didn't have one, but at least i can use one in the fablab Aachen).
Etching would also work fine, and using an Attiny in a bigger housing allows even using a stripboard.
In any case: There are just a few components to solder:
- The 10k pullup resistor (not necessary) and the capacitors (100 nF, 4.7µF, or something similar)
- Most important: The Attiny
- A double DIL switch for switching between different modi (also not necessary)
- The triple and double bended pinheader on each side
(In my case i thereafter removed the rest of the pinheaders on the backside for a flat backside)
Programming
Back to the High-Low-Tech webside: Using my old Arduino as an ISP Programmer and connecting VCC, GND and MISO/MSOI/SCK/Reset of the Attiny with the pins 13-10. Don't forget the 10µF capacitor between Reset and Ground on the Arduino... But all this is best explained on their webpage.
Then upload the Bootloader for setting the fuses and program the Attiny with a modified Adafruit neopixel strandtest: The DIL switch uses pin 0 and 1, leds are connected with 2 (instead of pin 6 of the original example).
So the only modifications are:
At the beginning:
#define PIN 2
int switch1 = 0;<br>int switch2 = 1;
In the setup routine add:
pinMode(switch1, INPUT_PULLUP); pinMode(switch2, INPUT_PULLUP);
(Stupid mistake: Shouldn't have copied my MSP430 code (with INPUT_PULLDOWN), which didn't exist on the Attiny - but at least the PCB was already correct :-)
And change the loop routine to:
void loop() {if (digitalRead(switch1)) { if (digitalRead(switch2)) { rainbowCycle(20); } else { rainbow(20); } } else { if (digitalRead(switch2)) { theaterChase(strip.Color(127, 127, 127), 50); // White theaterChase(strip.Color(127, 0, 0), 50); // Red theaterChase(strip.Color( 0, 0, 127), 50); // Blue } else { theaterChaseRainbow(50); } } }
So it won't cycle through the differnet example styles, but use the DIL switch to select one. Oh, and don't forget to change the number of leds:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, PIN, NEO_GRB + NEO_KHZ800);
Hook up 5V on on end and you snowflake or whatelse WS2812B object you have on the other end & Enjoy!