A Fast Introduction to Arduino and Addressable LED Strips
-
Upload
atuline -
Category
Technology
-
view
1.002 -
download
1
Transcript of A Fast Introduction to Arduino and Addressable LED Strips
![Page 1: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/1.jpg)
By: Andrew Tuline
A Fast Introduction to the ArduinoAnd Addressable LED Strips
![Page 2: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/2.jpg)
![Page 3: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/3.jpg)
Spark FUN
![Page 4: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/4.jpg)
The Arduino Family
![Page 5: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/5.jpg)
Early Projects
![Page 6: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/6.jpg)
Too Many Pins
Someone has more skills, patience and time than I do!
![Page 7: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/7.jpg)
Addressable LED Strips
• Addressable LED strips provide circuitry to communicate serially
• Each LED has a chip to receive, decode, drive LED’s and propagate data
![Page 8: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/8.jpg)
Form Factors
Also 30, 60, 144 pixels/m
![Page 9: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/9.jpg)
Enter Adafruit
• Adafruit has branded WS2812’s and APA102C’s
• They are called NeoPixels and DotStars
Adafruit sells addressable LED’s in many shapes and sizes!
![Page 10: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/10.jpg)
NeoPixels vs. DotStars
DotStars
• Data and clock pin
• High data rate
• Interrupt compatible
• More $$
• Currently strip only
• APA102C
https://learn.adafruit.com/adafruit-dotstar-leds/overview
NeoPixels
• Data pin only
• Slow data rate
• Not interrupt compatible
• Less $$
• Strips and more
• WS2812 & WS2812B
![Page 11: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/11.jpg)
A Typical Addressable Strip
Strips include:
• WS2812, WS2812B• APA102, APA102C• WS2801, others . .
12V accent lighting strips don’t count!
![Page 12: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/12.jpg)
Simple APA102C Connection
D12 –D11 –
5V –Gnd –Vin –
Data inClock in5VGnd, Battery -Battery +
If using the Arduino 5V pin, keep the strip SHORT and reduce brightness!
![Page 13: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/13.jpg)
Addressable LED Libraries
• Adafruit NeoPixel library
• Adafruit DotStar library
And then there’s:
• FastLED
![Page 14: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/14.jpg)
Why FastLED?
• FastLED is a fast, easy-to-use Arduino library for programming addressable LED strips.
• It supports multiple microcontroller platforms.• It supports multiple addressable LED types.• It has a lots of of function calls.• FastLED is used by thousands of developers.• The developers count clock cycles.
Do a YouTube search for ‘FastLED’
![Page 15: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/15.jpg)
Downloading FastLED
• Follow the link at www.fastled.io
• The current version is on GitHub at:https://github.com/FastLED/FastLED
• Download the zip file
• Extract the directory FastLED-master.
• Rename the directory from:
FastLED-master to FastLED
• Place that directory into:
C:\Program Files(x86)\Arduino\libraries
I use the development version (currently 3.1)!
![Page 16: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/16.jpg)
FirstLight Example
• In the Arduino IDE, select
‘File | Examples | FastLED | FirstLight’
• I’m using APA102C, so I need to change some definitions
We need to configure it for our LED strip!
![Page 17: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/17.jpg)
Modified FirstLight Code#include "FastLED.h"
#define NUM_LEDS 20#define DATA_PIN 12#define CLOCK_PIN 11uint8_t max_bright = 64;
CRGB leds[NUM_LEDS];
void setup() {FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);FastLED.setBrightness(max_bright);
}
void loop() {for (int count = 0; count < NUM_LEDS; count++) {
leds[count] = CRGB::White;FastLED.show();delay(100);leds[count] = CRGB::Black;
}} The white LED should march across the array.
// Include the library
// Number of LED’s// Our data pin// Our clock pin// Define brightness limiter
// Define the LED array
// Run once// Initialize the LED library
// Limit the brightness
// Run continuously// Cycle through all LED’s// Set the current one white// Show it// Wait for a bit// Set it to black
![Page 18: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/18.jpg)
Setting LED values
• leds[9] = CRGB::Cyan; // Web colours
• leds[9].g = 255; // Just set green
• leds[0] = CRGB(255,0,0); // CRGB values (red, green, blue)
• leds[0] = 0x0000ff; // Use a long hex value
Or via HSV
• leds[9] = CSHV(hue, sat, bright); // Each goes up to 255
FastLED provides lots more ways to assign colours to LED’s
![Page 19: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/19.jpg)
FastLED Is Just Getting Started
FastLED contains a LOT of functions including:• Random number generation
• Fast 8 and 16 bit basic math functions
• Fast trigonometry
• Setting RGB and HSV values
• fill_rainbow, fill_gradient, fading, scaling, blending, noise, palettes, palette blending, beats and more. . .
• Power management
We’re talking loads of functionality and FAST
![Page 20: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/20.jpg)
![Page 21: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/21.jpg)
Rainbow March#include "FastLED.h"
#define LED_DT 12 // Data & clock pin
#define NUM_LEDS 20 // Number of LED's
#define COLOR_ORDER BRG // Change the order as necessary
#define LED_TYPE WS2812 // What kind of strip are you using?
uint8_t max_bright = 64; // How bright do we want to go
struct CRGB leds[NUM_LEDS]; // Initialize our array
uint8_t thisdelay = 8; // A delay value for the sequence
uint8_t thishue = 0; // Starting hue value.
uint8_t deltahue = 5; // Difference in hue between LED’s
Use variables where possible
![Page 22: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/22.jpg)
Rainbow March cont’d
void setup() {
LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(max_bright);
}
void loop () {
rainbow_march();
FastLED.show();
delay(thisdelay); // or FastLED.delay(thisdelay);
}
void rainbow_march() {
thishue++;
fill_rainbow (leds, NUM_LEDS, thishue, deltahue); // FastLED does the heavy lifting
}
It boils down to just a few lines of loop code
![Page 23: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/23.jpg)
Power Managed Rainbow March
1) In setup add:set_max_power_in_volts_and_milliamps(5, 500); // Power management set at 5V, 500mA.
2) Change delay from:delay(thisdelay); // or
FastLED.delay(thisdelay);
To:delay_at_max_brightness_for_power(thisdelay); // Power managed FastLED delay.
3) Change show from:FastLED.show();
To:show_at_max_brightness_for_power(); // Power managed display of LED's.
![Page 24: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/24.jpg)
More FastLED Demos
• FastLED provides several demos with the library
• I’ve also written several demos downloadable at:
https://github.com/atuline/FastLED-Demos
• There’s loads of other demos available
The FastLED community is at Google+
![Page 25: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/25.jpg)
My Demos include
• one_sine demo
• pop_fade_demo
• ripple
• two_sin_demo
• noise16_demo
• three_sin_demo
• rainbow_march_demo
• aalight
aalight provides many routines, IR, keyboard, serial and button input
• fht_log
• matrix_demo
• soundbracelet
• soundmems
• and more. .
![Page 26: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/26.jpg)
High School Trigonometry
• An increasing linear input value yields a sine wave output value
• Map the output to brightness or location
• Change frequency, phase, amplitude
• Mix multiple sine waves
• 8 or 16 bit
Why count pixels when you can use sine waves
![Page 27: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/27.jpg)
More Topics
• Power issues• Data line conditioning• Troubleshooting, getting support• Diffusers• 2D matrix• POV• Sound reactive, MSGEQ7 vs FFT• Other platforms (ie. Teensy 3.1, Octo WS2811)• IR and other kinds of control• DMX• Loop friendly routines
![Page 28: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/28.jpg)
LED Research
• fastled.io
• github.com
• pastebin.com
• arduino.cc/tutorial
• playground.arduino.cc
• learn.adafruit.com
I mostly use my Google-fu
![Page 29: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/29.jpg)
Sources for Parts
• Lee’s Electronics
• Adafruit
• Sparkfun
• eBay
• Aliexpress
All it takes is a VISA card and your imagination
![Page 30: A Fast Introduction to Arduino and Addressable LED Strips](https://reader033.fdocuments.us/reader033/viewer/2022061618/55a6a1fc1a28ab27578b47b4/html5/thumbnails/30.jpg)
Demo Time