NeoPixels freeze while Blynk sends heartbeat

Hi All,
I am using Blynk with a Cactus Micro Rev2 board (ATMEGA 32U4 with integrated ESP8266) to control a fast changing animation on a NeoPixels strip.
Once every ~10 sec the animation freezes for 1-1.5 sec, followed by a debug string

[46266] <[06|00|0F|00|00]
[46841] >[00|00|0F|00|C8]

So I understand the packet sending process is blocking the sketch.

Does anyone know how to reduce or eliminate this block?
Thanks very much!

Here’s my sketch:

// ------------------ Blynk definitions
#define BLYNK_PRINT Serial               // Comment this out to disable prints and save space
#define BLYNK_DEBUG

#include <BlynkSimpleShieldEsp8266.h>
#define wifi_pin 13                        // ESP8266 Enable pin

#include <SimpleTimer.h>
SimpleTimer timer;         

char auth[] = "";
// ------------------  ESP 8266 definitions

char ssid[] = "";
char pass[] = "";

#define EspSerial Serial1                  // Hardware Serial on Mega, Leonardo, Micro...
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);

// ------------------ NeoPixel definitions
#include <Adafruit_NeoPixel.h>
#define NEO_PIN                10          // Which pin on the Arduino is connected to the NeoPixels?
#define MAXPIXELS              150         // How many NeoPixels are attached to the Arduino?

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(MAXPIXELS, NEO_PIN, NEO_GRB + NEO_KHZ800);

#define LED_train_length       8
int frame = 1;                              // Global frame number of current animation
uint32_t anim_color;
// ------------------ End of definitions
void setup()
{
  pixels.begin(); // This initializes the NeoPixel library.
  
  // WiFi init
  pinMode (wifi_pin, OUTPUT);
  digitalWrite (wifi_pin, HIGH);
  
  // Set console baud rate
  #if defined(BLYNK_PRINT)
	Serial.begin(9600);
  #endif
 
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
  while (Blynk.connect() == false) {
    // Wait until connected
	}
	
	// Internal settings
	int fps = 60;
	timer.setInterval(1000/fps,propagate_train);

 }

void loop()
{
	timer.run();
	Blynk.run();
}

BLYNK_CONNECTED(){
    //Sync all states when reconnected
    Blynk.syncAll();
}

void blank_strip(){illuminate_strip(0);}

void illuminate_strip(uint32_t color){
  for(int LED=0; LED<MAXPIXELS; LED++){
	pixels.setPixelColor(LED,color);
  }
pixels_show();
}

BLYNK_WRITE(V1)
{ // Change current animation color
	anim_color = pixels.Color(param[0].asInt(),param[1].asInt(),param[2].asInt());
}

void propagate_train() // Propagate an LED train by one pixel
{
	if (frame>MAXPIXELS){// Initialise train
		for(int LED=0;LED<LED_train_length; LED++){
			pixels.setPixelColor(LED,anim_color);
		}
		frame = 1;
	}
	
	// Illuminate next LED and blank last one	
	pixels.setPixelColor(frame+LED_train_length-1,anim_color);
	pixels.setPixelColor(frame-1,0);
	pixels_show();
	frame++;
}

void pixels_show(){ // Stabilize Blynk connection by calling run() before and after each pixels transmission
  Blynk.run();
  pixels.show();
  Blynk.run();
}

I’ve found two similar issues to this one:
http://community.blynk.cc/t/neopixel-ledcount-causes-blynk-to-fail/7987

http://community.blynk.cc/t/blynk-and-neopixels-on-esp8266/1414

So I understand that running video rate, large (>100 LEDs) strips combined with Blynk on the same board is futile, considering that NeoPixels library messes with millis() etc. I will soon try driving the NeoPixels with a separate board from the board with the Blynk sketch, using I2C communication between the two Arduinos.

I understand the the NeoPixels disables interrupts before each color change.
> You might have noticed that millis() and micros() lose time in NeoPixel sketches (the timekeeping interrupt stops whenever we write to the strip), that’s usually the extent of it.

Can anyone here say if the Blynk library uses any interrupts?

Tx,
Yuval

Incorrect. I run over 1000 LED’s via Blynk.
Throw away the absolutely rubbish NeoPixel library and use the FastLED library.

Here is a link to my own project:

3 Likes

I figured I’d make little remark for your project @Jamin, you can calculate really easily how much power you need.

Each pixel can do a maximum of about 60mA (3x 20mA, for each color). Multiply that by the amount of leds, divide by 1000 and there you have the maximum power you need for the project.

In your example with 100 leds, this comes to 6A if you have all leds on at the same time, full brightness, just saying, be careful with the power your using, a bit more is always better than barely enough. :slight_smile:

1 Like