Neopixel with Arduino UNO

arduino uno neopixel WS2812 adafruit

Install Neopixel library:

arduino-cli lib install "Adafruit NeoPixel"

The signals were captured with the Saleae Logic Analyser.

Download Saleae Analyser File

Zoomed out signals:

WS2818 signal captured with 10 pixels

Magnified signal at a closer look:

WS2818 signal captured with 10 pixels

Code

Download code
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 60
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(
    NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// 10 pixels * 200 ms = 2 seconds to display 10 pixels
#define DELAYVAL 200

void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  Serial.println("Start Neopixel!");

  pixels.begin();
  pixels.show();
  pixels.setBrightness(50);
}

void loop() {
  pixels.clear();

  Serial.print("Pixel #1 at ");
  Serial.print(String(millis()/1000));
  Serial.println("s");

  for (int i = 0; i < 10; i++) {
    pixels.setPixelColor(i, pixels.Color(0, 150, 0));
    // TODO show all pixels at one go after the for loop without a delay
    pixels.show();
    delay(DELAYVAL);
  }

  Serial.print("Pixel #10 at ");
  Serial.print(String(millis()/1000));
  Serial.println("s");

  delay(2000);
}

Makefile

BOARD?=arduino:avr:uno
PORT?=/dev/cu.usbmodem14*
BUILD=build

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) --output-dir $(BUILD) ./

flash:
	arduino-cli upload --fqbn $(BOARD) --port $(PORT) --input-dir $(BUILD)

clean:
	rm -r build

Serial console

Serial output from the firmware.

Neopixel with Arduino UNO serial console

Prototype

A photo of the actual setup.

Neopixel with Arduino UNO prototype

Schematic

Wire up the hardware accordingly

Neopixel with Arduino UNO schematic

References