How to Get Started Controlling Neopixels With an Arduino
by Tron3398 in Circuits > Arduino
714 Views, 2 Favorites, 0 Comments
How to Get Started Controlling Neopixels With an Arduino
I am going to teach how to get started programming Neopixels with an Arduino and to hook everything up. By the way I am a 13 years old, so my grammar might be a little funky. But just because I am young does not mean I can't teach others :) So I thought it would be fun to share for others that are getting started like me.
First off I want to tell you guys programming neopixel with Arduino might look super hard, but its very easy once you put time and effort into it.
Supplies
- USB cable, to hook up your Arduino to your computer
- Arduino, what controls your neopixels
- neopixel, the lights
- breadboard, what you hook up your jumper wires to
- jumper wires, to hook up your parts like power and data to your Arduino
- Alligators clips, to hook up your neopixels to your breadboard
- capacitor, device that stores energy
- 470 Ohm resistor, it constricts the power
- power supply that can go up to 5v, for power
Download the App
First you need to downloads the Arduino app . Once your at the website, click on software which is on the menu bar. Now see the blue square and it says download option, click what you what.
Now it will ask for you to donate or just download, I just download but you can donate if you want to. Then just install it which should be super easy.
The Connection
So get the jumper wires, Arduino, alligator clips, resistor, capacitor, bread board, and last but not least the neopixels. So get the neopixel and on one end of the neopixel it will say Gnd, Din, 5v. That's the end you want not the Gnd, Do, 5v. Gnd means Ground, and Din means data in, and 5v means 5 volts then Do mean data out. So get 3 alligator clips and clip them to the meta parts on the neopixel, they look like brown half oval. MOST INMPORANT PART IS NOT TO LET THE METAL PARTS OF THE CLIPS TOUCH EACH OTHER OR THE NEOPIXEL WILL FRY.
I am going to give a brief talk about how to hook up the wires to the breadboard, but if you are lost you can look at this instructable: Breadboard Basics for Absolute Beginners
On the top on the step there a picture of a breadboard which show the positive and the negative parts which is important. The alligator clips that clip to the Gnd metal part on the neopixel goes into the left negative part of the breadboard, which is the blue line on the breadboard, there a hole next to it, ,just put that long meta stick into the hole. There's a picture of it above. The next wire is the Din which is the data. On the right side of the breadboard there is another negative and positive lines just like the other side. Next to the negative line there are a bunch of letters. The letters are a,b,c,d,e. Now once you clip the alligator clips to the metal piece that says Din on the neopixel, put the other side of the alligator clip that has the long meta stick into the right side of the breadboard that says c, picture above. The last alligator clip that goes to breadboard and the neopixel is the 5v which is the power. Now grab your last alligator clip and clip it to the meta piece on the neopixel that next to it ,it says 5v and now put the other side of the alligator clip that has the long meta stick. Put it on the positive line which is right above the negative, make sure its above the wire that leads to the Gnd. That whole row on the negative side is all connecting with each other and same thing goes with the positive line.
Now your neopixel should be all hooked up, but now we have to do the Arduino.
Ok on the Arduino it has these black skinny rectangles things that have holes inside of them, that's for plugging in the jumper wires. On one side of it, it will say DIGITAL (PwM ~). That's the side you want to use for now, that the where you plug in wires that will gives the neopixel data or the commands from the Arduino. On the side it has numbers. Plug in one of your jumper wires into the slot that says 6. Before we plug that into the breadboard, we need to put in a resistor, it just limits the power so the neopixel don't fry. You will need a 470 Ohm resistor (of the color of yellow, purple, brown, gold, picture of it above). Put the resistor right above the wire that in "C" on the breadboard and count 8 of those holes to the left and insert it into the hole that you land on. So now we are back with the jumper wire that you plugged into the number 6 on the Arduino. Plug the other end of the jumper wire right above the resistor, so it will be plug into the "a" row. Picture above. Now on the other side of the of the Arduino it has another one of those skinny rectangle that has holes. One of there holes has Gnd hole and there two of them, just plug one of your jumper wires in either one. On the other side of the jumper wire plug that into the negative side and on the same side where the 5v and Gnd alligators clips from the neopixel. picture above.
Now everything is hook up from neopixel to Arduino, picture above of what it should look like. Now lets just handle hooking up the power stuff.
Now get your capacitor and put it on the negative and the positive lines and on the same row where the other cable are on, MAKE SURE THE LINE ON THE CAPACITOR IS CONNECTED WITH THE NEGATIVE SIDE OF THE BREADBOARD, PLEASE LOOK AT PICTURE IF NEEDED .
AND PLEASE CHECK YOUR CAPACITOR LABLES JUST TO BE SURE
Now lets get our power supply, MAKE SURE IT IS OFF .Untwist the nobs and grab some jumper wires and put the meta stick into the red nob gap that you untwist and put the metal parts into it and tighten them so they are tight inside and can't fall out and just insert the other end to random hole. BUT DO NOT TURN IT ON YET! We will hook up the positive wire after turning on the power supply. The power supply can overload the neopixel when turn on. Now grab another jumper wire and put it into the black knob on the power supply and twist it so it does not fall out. Put it into the negative part of the breadboard and the same side where the capacitor is. picture above.
Last thing is to plug a usb into the Arduino to your laptop usb slot or usb hub.
BOOM you are done with the connection.
After turning on your power supply move your power wire to a positive row on the side of breadboard.
CODE
Ok lets open the Arduino app and let get coding :)
Go turn on your power, but make sure just incase wear goggles because your capacitor might go boom if it backwards.
So for this tutorial is for beginnings, so for me I just modify a strandtest and build off that.
But first we need to install a library, a library is a code and basic function that another person wrote for us.
To get the library, go to sketch and then to include library, and then it should open a library manager.
Then go to the search bar and search for "neopixel". Click the one that says "Adafruit Neopixel" and then click install. Once you have that done, you need to do a strandtest so you know your pixels are working. To do that, go and click file, and then examples, then find Adafruit neopixel, then strand test. If you use a RGBW pixels, go and click RGBW strandtest. To launch the code there's a button under file, there's an arrow and there's a checkmark. The checkmark checks the code but it does not launch it. To launch it, you have to press the arrow. I modified the RGBW strand test because I have RGBW pixels. This tutorial will cover the same things. So lets get started ;)
But first, you will need to know what this means...
; Means the end of functions and commands, so it means that is one piece of code
// or /* You might see something like this in front of words, that means to skip over for the computer. So if you say //fullwhite the computer will just skip over it. "note" fullwhite is a function which i get into later
The first thing in the strandtest code it will say
#include <Adafruit_NeoPixel.h>
it includes that library that you just installed, and the other 3 lines just to pull Arduino library. Then you will see
#define PIN 6
that just says to the Arduino what pin you plug in the jumper wire. Then the next will be the same but it says
#define NUM_LEDS 60
it just saying how much pixel you have so i have 13 so i would change it to 13.
#define BRIGHTNESS 50
this line basically tells how bright you want your pixels to be.
This code below initializes the neopixel library and passes in the values specified in the 3 lines above.
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);
Ok now this code is a lot but all you really need to know the first line which is void setup() {then the long code between these brackets} This is a setup function that runs only once to setup the Arduino and the connections to neopixels
void setup() { Serial.begin(115200); // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket #if defined (__AVR_ATtiny85__) if (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // End of trinket special code strip.setBrightness(BRIGHTNESS); strip.begin(); strip.show(); // Initialize all pixels to 'off' only run once, it runs right when you turn it on
we going to skip down to
strip.setBrightness(BRIGHTNESS);
that show the brightness of the pixels and stirp.begain(); says to the computer to start the library so you can make calls to it.
And this key one here is strip.show(): is key because if you say
strip.setPixelColor(5,6,7,8,9)
it will never show the color intel you do
strip.show():
so short story that command enforces that color to show
The next thing is a Void loop() {
This is the main loop so it will keep repeating over what ever is inside of the loop
the loop starts when it hit " Void Loop() {
and it will end when you put }
You can see it says
colorWipe(strip.Color(255, 0, 0), 50); // Red colorWipe(strip.Color(0, 255, 0), 50); // Green colorWipe(strip.Color(0, 0, 255), 50); // Blue colorWipe(strip.Color(0, 0, 0, 255), 50); // White
This is all just calls to a function named colorWipe. A function is basically code that you wrote, give it a name, and then call during the code. You can just put the name down and then the computer will see the name and it will go back to the code that you wrote and do what the code says. In these strandtest they have function already in the code for you, like
colorWipe(strip.Color(255, 0, 0), 50);
That is just function. To find that function highlight the word colorwipe then press crt f so that means control find. Then press find 4 times then it will take you too the code that someone wrote for you in the strandtest, keep in mind you can use functions inside your own functions.
To make your own function start with
Void then name of your function () {The code goes here} maker sure it in between those brackets.
Once you finish the function, you can call the name of the function in the loop, but make sure at the end of every function you put into the loop put this (); at the end.
note: when you are making the name of your function you can not use spaces. So you can do something like
turn_off instead of "turn off"
example:
void turn_off() { strip.setPixelColor(0,0,0,0,0); strip.setPixelColor(1,0,0,0,0); strip.setPixelColor(2,0,0,0,0); strip.setPixelColor(3,0,0,0,0); strip.setPixelColor(4,0,0,0,0); strip.setPixelColor(5,0,0,0,0); strip.setPixelColor(6,0,0,0,0); strip.setPixelColor(7,0,0,0,0); strip.setPixelColor(8,0,0,0,0); strip.setPixelColor(9,0,0,0,0); strip.setPixelColor(10,0,0,0,0); strip.setPixelColor(11,0,0,0,0); strip.setPixelColor(12,0,0,0,0); strip.setPixelColor(13,0,0,0,0); }
Note: I use the function that were in the strandtest already.
You will see the part after strip.setpixelcolor(0,0,0,0,0)
it just means 0 which is the frist pixel because the pixel start as 0 not 1, and then second number is how much red is there, so 0 means none and 255 means full red because 255 is the highest you can go. Then the other one is green, and last one is blue. If you have Rgbw There will be 1 more number which is just white.
Now if you want to repeat a function more than once. Do not just keep pasting the name of the function,
do a loop and here is how to make a loop.
for(int i=0; i <9; i++) { turn_off(); }
for is a type of loop.
i is a variable that set to 0 at the beginning of the loop.
9 is how much times it going to loop. It will loop as long it is less than 9 in this code
i++ means to add another number to i.
Then you put the name of the functions that you want to call in the loop.
To delay the program call
delay(number of millisecond);
which means it will just pause program controlling the neopixels. After it done with the delay it will continue the code.
I hope you enjoy my instructable
That's all that I know and I will probably make another one about this stuff and more advanced