SBaronda.com a little place I like to call home.


SK6812 with Arduino using NeoPixel Library

Sep. 20, 2020

I was having a hard time finding straight forward documentation/code on configuring SK6812 RBGW strips with an Arduino. The sites that I found typically had code errors or lacked documentation for getting it configured. Hopefully this will save someone else the trouble when trying to configure these RGBW strips on an Arduino.

Before we begin we need to learn about how to hookup the SK6812 to the Arduino. https://learn.sparkfun.com/tutorials/ws2812-breakout-hookup-guide/all has a wealth of advice. One thing that I wasn't sure on was if I needed the in-line resistor on the data signal. I opted to include the resistor as I don't think it'll harm the Arduino with the resistor being present, but may harm the Arduino without it being present.

As for installing the NeoPixel library you can find that information here: https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use.

The key thing is you need to specify your LED_COUNT correctly. I'm using a 30 LED strip and a 60 LED strip together, so my total LED count is 90. This is important as if you get this wrong you're strip could act funny.

Since I'm dealing with the SK6812, I have access to an extra white LED. You can set this via strip.Color(0, 0, 0, 255); // WHITE.

There is my sample program that I use to test strips with.

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define LED_COUNT 90
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_RGBW + NEO_KHZ800);

void setup() {
  strip.begin();

  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  colorSet(strip.Color(0, 255, 0, 0), 0); // Red
  delay(1000);

  colorSet(strip.Color(255, 0, 0, 0), 0); // Green
  delay(1000);

  colorSet(strip.Color(0, 0, 255, 0), 0); // Blue
  delay(1000);

  colorSet(strip.Color(0, 0, 0, 255), 0); // WHITE
  delay(2000);

  colorSet(strip.Color(0, 0, 0, 127), 0); // half WHITE
  delay(2000);
}

void colorSet(uint32_t c, uint8_t wait) { // From NeoPixel Library
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
  }
   strip.show();
   delay(wait);
}


comments powered by Disqus