Ws2812B and ZeRGBa

Hello, I’m new to coding and even newer to Blynk. I’ve hit a snag on a sketch I’m working on. I’m trying to use a NodeMCU and Blynk/ZeRGBa to control a 300 LED WS2812B, but when I run the sketch, the strip doesn’t turn on. Associated information also doesn’t make it to my serial monitor.

I’m running a separate power supply for the strip, and the code is currently based off several examples I’ve found online. I know the strip (Pin D2), connections and power supply are fine, because when I upload the NeoPixel strandtest example, everything works. Additionally, I attached a test LED to pin D1 and added a Button Widget (V0) for it, but it’s the only part that works when I run my sketch. The only things in the Blynk project are the button for the test LED (V0) and ZeRGBA (V1, merge mode). I’ve included my code below. Any help would be IMMENSELY appreciated!

#include <ESP8266WiFi.h>
    #include <SPI.h>
    #include <BlynkSimpleEsp8266.h>
    #include <Adafruit_NeoPixel.h>
    
    #define BLYNK_PRINT Serial
    #define LED_Pin D2
    #define Led_Count 300
    
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(Led_Count, LED_Pin, NEO_GRB + NEO_KHZ800);
    
    char auth[] = "myauthenticationtoken";
    char ssid[] = "myssid";
    char pass[] = "mypassword";
    
    void setup() 
    {  
    Serial.begin(9600);
    Blynk.begin(auth, ssid, pass);
    strip.begin();
    strip.setBrightness(50);
    }
    
    BLYNK_WRITE(V1)
    {
    int R = param[0].asInt();
    int G = param[1].asInt();
    int B = param[2].asInt();
    Serial.println(R);
    Serial.println(G);
    Serial.println(B);
    for(int i=0;i<Led_Count;i++)
      {
      strip.setPixelColor(i, strip.Color(R,G,B));
      strip.show();
      }
    }
    
    void loop()
    {
      Blynk.run();
    }

The standard Neopixel Strandtest example uses:

#define LED_PIN    6

Did you change this to D2 for your tests, or to 4 (the GOIO number for pin D2)?

Pete.

For the strand test I changed it to D2 and updated the LED count to 300, and everything worked.

Is the syntax of this correct?

Pete.

Move your strip.show() to after your for loop.

I’ve got a Wemos D1 mini with 121 pixels working just fine with Blynk. I’ll post my code tomorrow.

I moved strip.show(); as you suggested but I’m still having the same results.

Never mind, I reloaded the sketch, and everything seems to be working now! I think I may need to find a way to step up my logic level from 3.3V to 5V though. It seems to stutter a bit with all the LEDs. Thank you for the assistance!

Put a 1k resistor between your output pin and the first led on the data line.

Sorted all my issues out.

Oh and in the zergba widget change the setting to send on release.

I have ZeRGBa set up for send on release, so no worries there. I think I resolved my stutter issues with a 100uF capacitor parallel with the +/- wires on the strip, but I’ll throw in the resistor too. Thanks for all the advice, and I’d still love to get some inspiration from your code if you find the time!

Really sorry I’ve been busy with work. I will post my code tomorrow. And I also put a capacitor on my strip power supply.

I will post details and code tomorrow. :angel:

1 Like

Please do yourself a favor and buy a proper level shifter (best bidirectional because they are commonly better quality).

I have a lot of experience with WS2812B LEDs and the hardware additions you made (cap but also a resistor is a good idea to reduce noise on boot etc.) were good.
But dont forget that these digitial LEDs are 5V logic, so 3.3V is on the low side for the HIGH threshold.

A level shifter will make it bullet proof :wink:

Another thing:
I would suggest to use the FastLED library.

Delete:

#include <SPI.h>
#include <Adafruit_NeoPixel.h>

and add:

#include <FastLED.h>

then replace your BLYNK_WRITE(V1) with this

BLYNK_WRITE(V1)
{
  int R = param[0].asInt();
  int G = param[1].asInt();
  int B = param[2].asInt();
  Serial.println(R);
  Serial.println(G);
  Serial.println(B);
  for (int i = 0 ; i < Led_Count; i++ )
  {
    strip[i].setRGB(R, G, B);
  }
  LEDS.show();
}
2 Likes

Just realised I’ve changed my code over to use the NeoMatrix library instead of NeoPixel (although technically it still uses the NeoPixel library anyway).

I can post that code though if you would like?

Edit - I used FastLED library in the past (and it worked really well) but switched back to Neopixel/Neomatrix (because of my application, needed a grid type layout - hence the matrix :wink:)

Sure, I’d love the inspiration! Right now I’m struggling to figure out how to have conditional “modes” on my strip that I can choose from my Blynk Project.

Thanks for the tips! May I ask what makes FastLED preferable over the NeoPixel Library?

In a nutshell it uses less ram, less flash, is visibly faster, better optimized math algorithms (faster) and possibilities for RGB<->HSV color transitions. (to name a few…)

Maybe not everything is needed for a simple blynk project, but as I have written android apps it really makes a huge difference.

A bit googleing would have given you more detailed answers:

https://forum.arduino.cc/index.php?topic=356405.0

Cheers!

3 Likes