NeoPixel support on the P2 and Photon 2!

The P2 and Photon 2 now support WS2812, WS2812B, and WS2813 NeoPixels! All you need is Device OS 5.3.2 or later, and Particle-NeoPixel 1.0.3 and you can blink strings of LEDs to your heart’s content.

The RTL872x platform can only use the MOSI pin of SPI or SPI1 (also known as D2) for NeoPixels because it needs to use the DMA controller in the SPI interface to output the pixels fast enough.

6 Likes

@rickkas7
Is this using the modified Adafruit NeoPixel library? Thanks.

Sort of. It was originally forked from the Adafruit NeoPixel library in 2014, but since then the two have diverged, so there will likely be differences.

@rickkas7 Does this Device OS update also mean FastLED library is supported via the same mechanism?

1 Like

In theory, the same technique that was used to implement NeoPixels could be used to modify the FastLED library to work on the RTL872x, but as far as I know, no one is working on doing so at this time.

Understood - I have been using FastLED on Arduino and it is much easier to work with to create dynamic effects - more likely to have a cheap arduino device as a sidecar processor/driver to run an LED display than use a P2/Photon2.

Thanks @rickkas7 for updating this library!!! I had hopes to use a NeoPixel Strip with a Photon2/P2 and now it's possible!

One consideration is if you could also update the strandtest.cpp in the examples directory. This might save someone some headaches in the future. Looks like the other examples were updated but not this one.

I personally got hung-up on this a little bit. I just assumed all the updates were in the library itself and as long as I was using the latest library, it should work as desired. Oddly enough the original example from 5 years ago also used D2. From what I can tell you actually have to define the PIXEL_PIN as SPI1 instead of D2 even though it's the same physical PIN. Once I looked at github and saw the other two examples were updated but not the RGBW-StrandTest.cpp was not, I realized my mistake.

Updating the strand test example might save someone else from having similar issues. If you prefer, I can make a pull request to the github repo.

I updated this similar to the other examples and then it worked just fine.

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#if (PLATFORM_ID == 32)
// MOSI pin MO
#define PIXEL_PIN SPI1
// MOSI pin D2
// #define PIXEL_PIN SPI1
#else // #if (PLATFORM_ID == 32)
#define PIXEL_PIN D3
#endif
#define PIXEL_COUNT 24
#define PIXEL_TYPE WS2812B
#define BRIGHTNESS 50 // 0 - 255

Thanks for the video, Rick! Nice to know it works with Photon 2!

Questions:
1 - Do we need the resistor, or can we directly plug neopixel to the Photon2? (I did this for Photon and it worked well).
2 - Is the library able to be added to the repository that is searched with VS Code? It isn't appearing when I try to add it to the project. I think this would be the easiest way for my students to learn to use NeoPixel with Photon2. If not, is there a tutorial about adding local libraries to VS Code w/Particle extension for Photon2 you can point us to?

Thanks again!

The resistor is recommended, but it often works without it. Likewise, powering the the strip with 5V and having the data at 3.3V works sometimes, but not others. This is mostly dependent on the NeoPixels that you have procured, so if it works for one it will probably work for all.

Yes, the library is in VSCode as neopixel.

Thank you! My code didn't compile until I saw your comment about changing the reference to pin SPI1 instead of D2. Super helpful!

2 Likes