Arduino: NeoPixels (WS2812) Made Easy - Indexed Pixels

by BoianM in Circuits > Arduino

11341 Views, 41 Favorites, 0 Comments

Arduino: NeoPixels (WS2812) Made Easy - Indexed Pixels

Arduino: NeoPixels (WS2812) made easy - Indexed pixels in Visuino

Nothing can uplift the Holiday spirit like colorful flashing LEDs :-)

Arduino with some NeoPixels from Adafruit or similar type of WS2812 based smart pixels are perfect for this, and with the help of Visuino an easy to use and powerful graphical development environment for Arduino, it has never been easier to program :-)

Components

DSC02331.JPG
  1. One Arduino board (I used Mega because I had one available, but ONO, Mini or Nano will be perfectly fine)
  2. Some NeoPixels from Adafruit or similar WS2812 based (I used 12 pixels ring from Adafruit )

Connecting the NeoPixels

DSC02334.JPG
DSC02341.JPG
DSC02350.JPG
  1. If you have not yet done so, soldier wires to the Power(Red wire), Ground(Black wire), and "Data Input" (White wire) connection points on the NeoPixels ring (Picture 1)
  2. Connect the other end of the Power wire (Red wire) to the 5V Power pin of the Arduino board. Connect the other end of the Ground wire (Black wire) to one of the the Ground pins of the Arduino board (Picture 2)
  3. Connect the Data wire (White wire) to Digital Pin 2 of the Arduino board (Picture 3)

Start Visuino, and Add NeoPixels Component

ComponentNeoPixels.png
ComponentNeoPixelsConnect.png
ComponentNeoPixelsIntensity.png

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/ .

Please be aware that there are some critical bugs in Arduino IDE 1.6.6. Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino
  2. Type "neo" in the Filter box of the Component Toolbox then select the "NeoPixels" component (Picture 1), and drop it in the design area
  3. Connect the "Out" pin of the component to the "Digital" input pin of the Digital[ 2 ] channel of the Arduino Component as shown in Picture 2
  4. Set the value of the Brightness property of the component to 0.07 so the pixels will not be too bright (Picture 3)

In Visuino: Add Color Pixel Element to the Component

ComponentNeoPixelsToolBox.png
AddColorPixel1.png
AddColorPixel2.png
ColorPixelCountPixels.png

We need to add a "Color Pixel" element and specify how many pixels the element will control. The color pixel has index and color pins, and we can use them to assign colors to a pixel by index.

  1. Click on the "Tools" icon in the NeoPixels component or Double Click on the component to open the Elements Editor(Picture 1)
  2. Double click on the "Color Pixel" item (Picture 2) to add one of them (Picture 3)
  3. Set the value of CountPixels property of the "Color Pixel" element to 12, since we have a ring of 12 pixels that we want to control. If you use different number of NeoPixels, enter the number in this property (Picture 4)

In Visuino: Add and Connect Unsigned Sine Generator

ComponentInsignedSineGenerator.png
ComponentUnsignedSineGeneratorConnect.png
ComponentUnsignedSineGeneratorSet.png

We will use an Unsigned Sine generator to select a pixel to assign color to.

  1. Type "sine" in the Filter box of the Component Toolbox then select the "Sine Unsigned Generator" component (Picture 1), and drop it in the design area
  2. Connect the "Out" pin of the SineUnsignedGenerator1 component to the "Index" input pin of the "Color Pixel1" of the NeoPixel1 component as shown in Picture 2
  3. Set the values of the Amplitude and Offset properties of the component to 6, which is half of the number of pixels that we want to control - 12. If you use different number of pixels, divide the number by 2 and enter it here
  4. Set the value of the Frequency property of the component to 0.8 (Picture 3)

In Visuino: Add and Connect Analog to Color, 3 Analog Generators for the Red, Green and Blue

ComponentAnalogToColor.png
ComponentAnalogToColorConnect.png
ComponentRandom1.png
ComponentAnalogSineGenerator.png
ComponentAnalogSineGeneratorConnect.png

We will generate partially random color from Red Green and Blue components to set the selected pixel.

  1. Type "to co" in the Filter box of the Component Toolbox then select the "Analog To Color" component (Picture 1), and drop it in the design area
  2. Connect the "Out" pin of the AnalogToColor1 component to the "Color" input pin of the "Color Pixel1" of the NeoPixel1 component as shown in Picture 2
  3. Type "rando" in the Filter box of the Component Toolbox then select the "Random Analog Generator" component (Picture 3), and drop two of them in the design area
  4. Type "sine" in the Filter box of the Component Toolbox then select the "Sine Analog Generator" component (Picture 4), and drop it in the design area
  5. Connect the components as shown in Picture 5

Generate, Compile, and Upload the Arduino Code

GenerateCtopped.png
ArduinoIDE.png
  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

And Play...

OpenWireDiagram.png
DSC02357.JPG
DSC02362.JPG
DSC02366.JPG

Congratulations!

The project is completed. You should see the NeoPixels changing colors.

On Picture 1 you can see the complete Visuino diagram.

Enjoy the colorful lights :-)

Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino : https://www.visuino.com