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();
}