I ordered some ATtiny85 chips from Amazon. They are an Amtel 8-bit AVR microcontroller, with 6 I/O pins. They have an internal clock, so you don't have to supply any external circuitry. You can program them using the Arduino Uno (you first load the "ArduinoISP" sketch onto your Arduino, you can find it in the Arduino IDE under File, Example, ArduinoISP).To support the ATtiny85 you also need to add support for the board (in the Arduino IDE choose File, Preferences, Additional board url: (https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json, then Tools, Board, Board Manager, set the "Type" dropdown to Contributed, and then scroll down to attiny in the list and click Install.) You need to connect pins from the Arduino to the ATtiny85, then setup your IDE to point to the ATtiny85. Make sure you change the Tools, Programmer from "AVRISP msii" to "Arduino as ISP". If you change the speed of the clock speed, then you need to use the Tools, Burn bootloader. How to program ATTiny85 with Arduino Uno (part 1) – 42 Bots is a little outdated, but it shows you how to connect the wires.
The ATtiny85 I ordered are in a standard 8-pin DIP packing, but they come in a variety of different shapes (so if you are making a custom PCB you don't need to do 8-pin DIP.)
The project I wanted to create was a device that connects to the end of a LED strip (WS2812 NeoPixel lights) and acts like a WS2812 LED but triggers a relay when the color matches some value (GREEN brightness:63 in my case) instead of glowing colors. I have a 16 foot strip of LEDs wrapped around the inner part of the tree, and now the end of the strip connects to the ATtiny85 which turns on a relay that gives power to the star at the top of my Christmas tree.
The WS2812 runs at 800KHz, with the first 1/3ish time being HIGH, followed by the data bit (e.g. HIGH or LOW) and then the last 1/3ish being LOW. The ATtiny85 has an INT0 (hardware interrupt) that I use to know when there is a pulse and run my ISR code. That code has assembly instructions that basically take a set number of samples and count how often the data was HIGH; so if Green (the first byte) was sent with brightness 63 (0b00111111) then the number of samples will be must higher than if you sent brightness 0 (0b00000000). I didn't know Amtel assembly so I ended up reading these two documents which were really helpful (although it turned out I didn't need to know most of the information but I was so new I didn't know what I needed to know)... Atmel ATtiny25, ATtiny45, ATtiny85 Datasheet (microchip.com) and AVR® Instruction Set Manual (microchip.com). In the future if I ever need take advantage of low power, do watchdog stuff, etc. I'm ready now. Overall, all I really needed to know was EOR, SBIC, INC, NOP; any maybe a few other commands. I had to laugh about EOR ("Exclusive OR" hurt my brain, I just always think about "eXclusive OR" and write it as XOR).
Here is a video of my proof of concept:
The next improvement I want to add is skipping the first 3 bits of the signal (so that I can more clearly detect on vs. off color channel; this should fix the glitches where the relay turns off/on when it shouldn't.) I also want to add three separate variables for the green, red, blue components; so that at the end of the ISR routine you have 8 states (GREEN [on:off], RED [on:off], BLUE [on:off]) that you can decide what to do with (there are 5 IO ports available to have all kinds of fun.)
The LEDs on our tree do more of a random twinkle effect (which means I actually update them a lot less than in the sample video.) I need to figure out what is a good "random" time for the star. I also might look at using a triac and cadmium sulfide photocell instead of the relay, so there is no clicking noise.
My wife has been amazing, listening to me talk about the ATtiny85 for the last three days (and letting me blink the light on the top of the tree.)
Kommentare