What Are NeoPixel LEDs?

Updated 23 November 2016

Adafruit NeoPixel matrixSo in case you haven’t heard yet, digital LEDs are the go-to solution for any project that uses RGB LEDs and you want to avoid the rat's nest that ensures when using multiple RGB LEDs, each colour requiring its own connection. Digitally addressable LEDs allow you to control large numbers of LEDs using digital communication to tiny onboard chips integrated into the LEDs which read these digital commands and do all the heavy lifting for you. The go to LED chip for these purposes has been the WS2812 which you might know most prominently as Adafruit’s NeoPixels. The WS2812B LEDs have been around for a few years now, and come in two different flavours, WS2812 and WS2812B. Both operate similarly, however, require slightly different timing according to the datasheet. There are also other chips which power NeoPixel branded LEDs that work in the exact same way, with the same code and are the drop-in replacement, however, the WS2812 line is the most common.

Adafruit provides a fantastic comparison between DotStars and NeoPixel LEDs so we won’t go into that too much, rather we’ll be taking a look at the key features of the NeoPixel LEDs and how to use them. If you're looking for information specifically on DotStars we've got a separate article for those here.

Why NeoPixel LEDs?

NeoPixel LEDs represent the first widely available DIY form of digital RGB LEDs with example code, libraries and supporting content to make them useable for makers everywhere. From just a single pin you can control a (theoretically) as many LEDs as you want, however, there are a few limitations. Namely that each LED consumes a few bytes of RAM, and because of the relatively low speed of data, once you use more than a few hundred LEDs, you may start to notice slight buffering time across the pixels. Because of the slow (400Hz) refresh/PWM cycle, NeoPixels can't be used reliably for POV (Persistance of Vision) displays, or anything that requires high FPS.

NeoPixels, however, are incredibly cheap, especially compared to DotStar LEDs. You can pick up a 10 pack of individual LEDs for less than $10, and they can be bought at wholesale prices for around 10 cents/unit. So let's take a look at how we actually use these things.

If you're looking for a great way to get started with NeoPixels, then this 1/4 circle 15 LED segment is going to be just the thing. You can even connect four of them up together to create a massive 60 LED circular display. It's important to note that whilst WS2812 chips are readily available, and used by manufacturers everywhere, NeoPixel and DotStar are Adafruit's brand name for their digital LEDs and they've put a huge amount of effort into creating the libraries and support for them.

1/4 circular NeoPixel segment

Using NeoPixel LEDs

Using NeoPixel LEDs is incredibly easy, no matter what platform you’re on thanks to Adafruit’s fantastic libraries for both Arduino and Raspberry Pi. If you go to the link we posted above to Adafruit’s site, they provide access to libraries for both the Raspberry Pi and Arduino which both use the same object orientated control, however with the syntax for Python vs. C (Arduino).

If you’ve used DotStars before, then you’ll be familiar with the basic functionality of the library. After initializing the NeoPixel object (you can have multiple objects, or daisy chain them), you set the colour of the LEDs using the .setPixelColor(n,R,G,B) and then use the .show() to display that colour on the targeted pixel. Everything else used to create pretty animations and effects is just manipulation of those two commands, so it’s incredibly easy to implement NeoPixel LEDs into your projects.

As we mentioned above, one of the best things about NeoPixel is that they only require one pin to drive them and you can daisy chain multiple strings. Any digital pin can be used, and the data output pin can be attached to another strip to daisy chain them.

  • Power (5V) DO NOT USE THE 5V OUTPUT OF YOUR BOARD! We’ll explain this further below
  • Ground
  • Data In
  • Data Out (for daisy chaining)

**Note that as most NeoPixels are 5V devices, whilst 3.3V may be enough to drive it, you should use a logic level converter if you’re using them with a 3.3V board such as Teensy or Raspberry Pi**

The data pin can be connected up to any digital pin on your board, you’ll just need to specify this pin when you initialise the object. Because NeoPixels use a very specific timing protocol that only operates at 800kHz, it doesn't matter what pin it is and doesn't require any specific hardware peripheral.

For more info on the specifics of using the libraries, check out Adafruit's NeoPixel Uber Guide.

Sample Code

As mentioned above, using the NeoPixels is incredibly easy. We've created a tutorial on using NeoPixels with Particle which covers the basics of using NeoPixels, and the code there is pretty much line for line compatible with Arduino, you will just need to adjust the library inclusion for the NeoPixel library and remove the application library. Here is a simple code showing an animation sequence with multiple colours. For an explanation of the code, check out the Particle tutorial linked above.

#include "application.h"
#include "neopixel/neopixel.h"

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_COUNT 24
#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B

#define PEACH 200,50,5
#define CYAN 10,150,70
#define PURPLE 180,3,180
#define BLUE 5,5,190
#define WHITE 150,150,150
#define GREEN 10,180,10

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int waitTime = 25;
int i;
void spin(int R, int G, int B);

void setup() {
  strip.begin();
  strip.show();
}

void loop() {
    spin (PEACH);
    spin (CYAN);
    spin (PURPLE);
    spin (BLUE);
    spin (WHITE);
    spin (GREEN);
}

void spin(int R, int G, int B) {
    for(i=0; i < PIXEL_COUNT; i++) {
        strip.setPixelColor(i, R,G,B);
        strip.show();
        delay(waitTime);
    }
    for(i=0; i < PIXEL_COUNT; i++) {
        strip.setPixelColor(i, 0,0,0);
        strip.show();
        delay(waitTime);
    }
}

It's important to note that any complexity in the code is coming from the animation sequence to turn the LED colours on in a specific order. The actual functions to use the LEDs are just .setPixelColor() and .show().

Powering RGB LEDs

You need to be careful when using RGB LEDs because they draw so much power. If you try to power more than a couple of the 5V pin of your microcontroller, you will most probably fry the board. Use a separate 5V power supply that can handle the total current draw. For more info on working with LEDs in general, take a look at our All About LEDs tutorial, however, we’ll give you a simple formula to work with. Given that each RGB LED at full brightness will draw around 60mA, take the number of LEDs (n) you’re using and put it into the equation:

Total Current (A) = n(total number of LEDs) x 0.06

A high-density LED strip can have 144 LEDs/m which would give a total current draw of 8.64 Amps! So make sure you can adequately power your LEDs.

Hopefully, this has given you some info on how to use the Adafruit NeoPixel digital LED strips in your projects, we can’t wait to see what awesome projects you make with them.

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.