Code Monkey home page Code Monkey logo

particle-neopixel's Introduction

Particle-NeoPixel

A library for manipulating NeoPixel RGB LEDs for the:

Particle Core, Photon, P1, Electron, Argon, Boron, Xenon and RedBear Duo

Implementation based on Adafruit's NeoPixel Library.

Supported Pixel Types

  • 800 KHz WS2812, WS2812B, WS2813 and 400kHz bitstream and WS2811
  • 800 KHz bitstream SK6812RGBW (NeoPixel RGBW pixel strips) (use 'SK6812RGBW' as PIXEL_TYPE)

The most common kinds are WS2812/WS2813 (6-pin part), WS2812B (4-pin part) and SK6812RGBW (3 colors + white).

Also supports these less common pixels

  • Radio Shack Tri-Color LED Strip with TM1803 controller 400kHz bitstream.
  • TM1829 pixels, many details here.
  • Some functions from the MessageTorch library have been added.
  • SK6812MINI "NeoPixel Mini" (use 'WS2812B' as PIXEL_TYPE)

Usage

Set up the hardware:

  • A NeoPixel digital RGB LED (get at adafruit.com)
  • or a Radio Shack Tri-Color LED Strip (get at radioshack.com)
  • A power supply or breakout board to supply NeoPixel's with 5V

Flash the rainbow example. With the Particle CLI do particle flash <my_device> examples/a-rainbow

Adapt it to your needs while keeping this general structure:

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup() {
  strip.begin();
  strip.show();
}
void loop() {
  // change your pixel colors and call strip.show() again
}

Documentation

Adafruit_NeoPixel

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_COUNT 10
#define PIXEL_PIN D2
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

Creates an object to interact wth a NeoPixel strip.

PIXEL_COUNT is the number of pixels in strip.

Note: for some stripes like those with the TM1829, you need to count the number of segments, i.e. the number of controllers in your stripe, not the number of individual LEDs!

PIXEL_PIN is the pin number where your NeoPixel are connected (A0-A7, D0-D7, etc). If omitted, D2 is used.

On Photon, Electron, P1, Core and Duo, any pin can be used for Neopixel.

On the Argon, Boron and Xenon, only these pins can be used for Neopixel:

  • D2, D3, A4, A5
  • D4, D6, D7, D8
  • A0, A1, A2, A3

In addition on the Argon/Boron/Xenon, only one pin per group can be used at a time. So it's OK to have one Adafruit_NeoPixel instance on pin D2 and another one on pin A2, but it's not possible to have one on pin A0 and another one on pin A1.

PIXEL_TYPE is the type of LED, one of WS2811, WS2812, WS2812B, WS2812B2, WS2813, TM1803, TM1829, SK6812RGBW. If omitted, WS2812B is used.

Note: For legacy 50us reset pulse timing on WS2812/WS2812B or WS2812B2, select WS2812B_FAST or WS2812B2_FAST respectively. Otherwise, 300us timing will be used.

Note: RGB order is automatically applied to WS2811, WS2812/WS2812B/WS2812B2/WS2813/TM1803 is GRB order.

begin

strip.begin();

Sets up the pin used for the NeoPixel strip.

setPixelColor

setColor

strip.setPixelColor(num, red, green, blue);
strip.setPixelColor(num, red, green, blue, white);
strip.setPixelColor(num, color);
strip.setColor(num, red, green, blue);
strip.setColor(num, red, green, blue, white);

Set the color of LED number num (0 to PIXEL_COUNT-1). red, green, blue, white are between 0 and 255. White is only used for RGBW type pixels. color is a color returned from Color.

The brightness set with setBrightness will modify the color before it is applied to the LED.

show

strip.show();

Displays the colors on the NeoPixel strip that were set with setPixelColor and other calls that change the color of LEDs.

This function takes some time to run (more time the more LEDs you have) and disables interrupts while running.

clear

strip.clear();

Set all LED color to off. Will take effect on next show().

setBrightness

strip.setBrightness(brightness);

Make the LED less bright. brightness is from 0 (off) to 255 (max brightness) and defaults to 255.

This factor is not linear: 128 is not visibly half as bright as 255 but almost as bright.

getBrightness

uint8_t brightness = strip.getBrightness();

Get the current brightness.

setColorScaled

strip.setColorScaled(num, red, green, blue, scaling);
strip.setColorScaled(num, red, green, blue, white, scaling);

Set the color of LED number num and scale that color non-linearly according to the scaling parameter (0 to 255).

setColorDimmed

strip.setColorDimmed(num, red, green, blue, brightness);
strip.setColorDimmed(num, red, green, blue, white, brightness);

Set the color of LED number num and dim that color linearly according to the brightness parameter (0 to 255). In this case 128 should look half as bright as 255.

Color

uint32_t color = strip.Color(red, green, blue);
uint32_t color = strip.Color(red, green, blue, white);

Make a color from component colors. Useful if you want to store colors in a variable or pass them as function arguments.

getPixelColor

uint32_t color = strip.getPixelColor();

Get the current color of an LED in the same format as Color.

setPin

strip.setPin(pinNumber);

Change the pin used for the NeoPixel strip.

updateLength

strip.updateLength(n);

Change the number of LEDs in the NeoPixel strip.

getPixels

uint8_t *pixels = strip.getPixels();

Get the raw color data for the LEDs.

getNumLeds

numPixels

uint16_t n = strip.getNumLeds();
uint16_t n = strip.numPixels();

Get the number of LEDs in the NeoPixel strip. numPixels is an alias for getNumLeds.

Nuances

  • Make sure get the # of pixels, pin number, type of pixels correct
  • NeoPixels require 5V logic level inputs and the Spark Core and Photon only have 3.3V logic level digital outputs. Level shifting from 3.3V to 5V is necessary, the Particle Shield Shield has the TXB0108PWR 3.3V to 5V level shifter built in (but has been known to oscillate at 50MHz with wire length longer than 6"), alternatively you can wire up your own with a SN74HCT245N, or SN74HCT125N. These are rock solid.
  • To reduce NeoPixel burnout risk, add 1000 uF capacitor across pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input and minimize distance between device and first pixel. Avoid connecting on a live circuit. If you must, connect GND first.
  • Don't use getPixelColor() to move pixel data around when you are also using setBrightness(). When the brightness is set, all setPixelColor() calls will end up scaling colors to dim them before they are stored in memory. When using getPixelColor() the stored dimmed color is rescaled back up to the original color. However, due to some loss of precision with the math, it is not possible to recreate this color data perfectly. This is especially true with low brightness values. If you get and set color data repeatedly with a dimmed pixel, it will eventually continue to decrease in value until it is equal to zero.
  • When changing the brightness, always call setPixelColor() first with fresh un-dimmed color data, then call setBrightness(), and finally show().

References

License

Copyright 2014-2018 Technobly, Julien Vanier, Cullen Shane, Phil Burgess

Released under the LGPL license

particle-neopixel's People

Contributors

bradysalz avatar carldanley avatar chap avatar clay-to-n avatar cullenshane avatar harrisonhjones avatar joegoggins avatar monkbroc avatar mozzbozz avatar no1089 avatar rohlfingt avatar sethtroisi avatar sjunnesson avatar sknebel avatar technobly avatar wgbartley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

particle-neopixel's Issues

5V supply to the entire circuit

Cant I just use a 5v output power supply to power the SparkCore (into the VIN pin), and use the same 5v power supply to power the NeoPixels ?

expected identifier before numeric constant

Veryfing code using this library in Particle Build fails with this error:

neopixel/neopixel.h:60:18: error: expected identifier before numeric constant
 #define TM1829   0x04 // 800 KHz datastream ()
                  ^

there's a dozen of these errors, one for every chipset definition by the looks of it

Removing Copy Ctor?

This PR #31 removes the copy ctor to prevent errors when going out of scope as the object's pixels property gets freed. However, this breaks many of the examples.

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

Uses the copy ctor to initialize. I would recommend changing the examples to something like

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

Or undoing the latest PR and fixing the memory problems manually.

Particle P1 is not yet supported

The Photon P1 is currently unsupported. Compiling returns the error: "*** PLATFORM_ID not supported by this library. PLATFORM should be Core or Photon ***".

Adding the Photon's pinHI and pinLO definitions under a new tag does not help:

elif PLATFORM_ID == 8

...

This lets the code compile, but the P1 fails to send a proper signal to the NeoPixels strip.

Redbear Duo Platform ID in neopixel library

When trying to compile an app using the neopixel library onto a Redbear Duo (similar to Photon with BLE) I get an error regarding platform ID. Could you please look into adding the platform ID for the Redbear Duo to the library:
(PLATFORM_ID == 88)
Thanks

'PIN_MAP' was not declared in this scope

Veryfing code using this library in Particle Build fails with this error:

neopixel/neopixel.cpp:110:9: error: 'PIN_MAP' was not declared in this scope
         PIN_MAP[pin].gpio_peripheral->BSRR = PIN_MAP[pin].gpio_pin

'HAL_Pin_Map' was not declared in this scope;

I'm using an Argon on DeviceOS 5.0, and when I compile this library, I get the following error:

lib/neopixel/src/neopixel.cpp:67:30: error: 'HAL_Pin_Map' was not declared in this scope; did you mean 'Hal_Pin_Map'?

I fixed the issue by changing line 67 from
NRF5x_Pin_Info* PIN_MAP2 = HAL_Pin_Map();
to
NRF5x_Pin_Info* PIN_MAP2 = Hal_Pin_Map();

I believe the platform id isn't the issue so I'm thinking it's the Device OS version.

APA106 support

Hi guys,
Can you add support for the APA106 LEDs? the protocol is almost the same but with ws2812 selected in the library, it flickers a lot.

getPixelColor returning dimmed values

I've been playing around with the neopixel library and appear to have run into an odd result.

If the brightness is dimmed and I run "strip.getPixelColor(i)" the color returned appears to be the dimmed value. Which whilst logical is different from the Adafruit Neopixel Library.

The trouble comes in that if you re-use the color it is then redimmed (and I struggle to think of any use other than to reuse it!)

So lines such as:

strip.setPixelColor(i,strip.getPixelColor(i-1));

won't work to copy a pixels color to the next pixel.

This is different to how the Adafruit Library works which returns the pre-dimmed value so when it is reapplied the resulting displayed color is correct.

redefinition of 'STM32_Pin_Info* PIN_MAP'

Veryfing code using this library in Particle Build fails with this error:

neopixel/neopixel.cpp:57:19: error: redefinition of 'STM32_Pin_Info* PIN_MAP'
   STM32_Pin_Info* PIN_MAP = HAL_Pin_Map()

SK6812 RGBW support on Photon 2 / P2

First of all thank you for the library, and it is great that it already has support for other led types on the Photon 2/P2, but it would be really great for me if you could also support the SK6812.

Version of library web IDE does not support P1 module

I am trying to build an example for a Sparkfun Photon Redboard, which I believe uses a P1 module.

When trying to build with the v0.0.7 of the library included all via the online IDE, I get the error:

# error "**\* PLATFORM_ID not supported by this library. PLATFORM should be Core or Photon ***"```

PIN_MAP[pin] error

neopixel/neopixel.cpp:92:9: error: 'PIN_MAP' was not declared in this scope
PIN_MAP[pin].gpio_peripheral->BSRR = PIN_MAP[pin].gpio_pin; // HIGH

The NeoPixel library has worked flawlessly for me until today.

application.h missing

Getting this error after including
#include <neopixel.h>

In file included from \Documents\Arduino\Stm32Blink\Stm32Blink.ino:1:0:

\Documents\Arduino\libraries\SparkCore-NeoPixel/neopixel.h:56:25: fatal error: application.h: No such file or directory

#include "application.h"

                     ^

compilation terminated.

exit status 1
Error compiling for board Generic STM32F103C series.

RGBW support

Hey!

I'm wondering if you still plan to add RGBW neopixel support? It was being discussed on a particle forum for a bit..

I was thinking about taking a stab at it but don't really have the time atm, and won't bother if you're already doing it! Thanks!

GRBW support

Hello I was wondering if GRBW could be supported.
Most of Neopixel products from Adafruit are GRB and not RGB organised.
Adafruit Neopixel library supports : NEO_RGB, NEO_RGBW, NEO_GRB, NEO_GRBW.

Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.