ESP32 and FastLED Library

Hello Pete

First let me apologize because what I am about to ask is not a Blynk related issue. But since you have experience with the ESP range of controllers and already have seen what I am trying to achieve, I would like some advice and assistance. I am stuck at the moment trying to get my code to compile for the ESP32 board that I am transitioning to from the Arduino Mega. My program compiles and runs on the Mega but does not compile for the ESP32. This is the error message that is produced:

In file included from C:\Users\Hp Zbook 15\Desktop\Light Control Project\BedSideLightControlExampleV1_7_AddingWS2812LEDControl\BedSideLightControlExampleV1_7_AddingWS2812LEDControl.ino:25:0:

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.003.002

 #    pragma message "FastLED version 3.003.002"

                     ^

In file included from C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:65:0,

                 from C:\Users\Hp Zbook 15\Desktop\Light Control Project\BedSideLightControlExampleV1_7_AddingWS2812LEDControl\BedSideLightControlExampleV1_7_AddingWS2812LEDControl.ino:25:

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/fastspi.h:130:23: note: #pragma message: No hardware SPI pins defined.  All SPI access will default to bitbanged output

 #      pragma message "No hardware SPI pins defined.  All SPI access will default to bitbanged output"

                       ^

In file included from C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:48:0,

                 from C:\Users\Hp Zbook 15\Desktop\Light Control Project\BedSideLightControlExampleV1_7_AddingWS2812LEDControl\BedSideLightControlExampleV1_7_AddingWS2812LEDControl.ino:25:

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/fastpin.h: In instantiation of 'class FastPin<24u>':

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/platforms/esp/32/clockless_rmt_esp32.h:178:23:   required from 'class ClocklessController<24, 60, 150, 90, (EOrder)66u, 0, false, 5>'

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/chipsets.h:582:7:   required from 'class WS2812Controller800Khz<24u, (EOrder)66u>'

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:103:52:   required from 'class WS2812<24u, (EOrder)66u>'

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:302:39:   required from 'static CLEDController& CFastLED::addLeds(CRGB*, int, int) [with CHIPSET = WS2812; unsigned char DATA_PIN = 24u; EOrder RGB_ORDER = (EOrder)66u]'

C:\Users\Hp Zbook 15\Desktop\Light Control Project\BedSideLightControlExampleV1_7_AddingWS2812LEDControl\BedSideLightControlExampleV1_7_AddingWS2812LEDControl.ino:201:56:   required from here

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/fastpin.h:207:2: error: static assertion failed: Invalid pin specified

  static_assert(validpin(), "Invalid pin specified");

  ^

Multiple libraries were found for "BlynkSimpleEsp32.h"
 Used: C:\Users\Hp
Multiple libraries were found for "LedControl.h"
 Used: C:\Users\Hp
Multiple libraries were found for "FastLED.h"
 Used: C:\Users\Hp
Multiple libraries were found for "WiFi.h"
 Used: C:\Users\Hp
 Not used: C:\Program
exit status 1
Error compiling for board ESP32 Dev Module.

The line being referred to by C:\Users\Hp Zbook 15\Desktop\Light Control Project\BedSideLightControlExampleV1_7_AddingWS2812LEDControl\BedSideLightControlExampleV1_7_AddingWS2812LEDControl.ino:201:56: required from here
is actually this line in my program FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
Strange thing is that the “Blink” example code on github,here., which uses the same line of code, compiles successfully

Here’s my variable declaration, setup and loop programming code:

//#define BLYNK_PRINT Serial 
//#include <Blynk.h>
#include <FastLED.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define DATA_PIN     24
#define NUM_LEDS    30
#define NUM_LEDS1   14
#define NUM_LEDS2   15
CRGB leds[NUM_LEDS];

char auth[] = "XXXXXXXXXXXXXXXXXXXX";

String Lamp1="XXXXXXX";
String Lamp2="XXXXXXX";

byte PBIncLight1=18;              //2
byte PBDecLight1=19;              //4
byte PBIncLight2=20;              //A0
byte PBDecLight2=21;              //A1
byte PBHardNormLight1=22;         //A2
byte PBHardNormLight2=23;         //A3

void BlynkComms();
byte counter1=0;                               //Used to control the execution of the brightness display on the app and LED bar graph
byte RGBColourReset=0;                         //Used to control the execution of normalising the LED colours
byte r1=255,g1=255,b1=255;                     //Stores RGB command from Blynk app and writes it to the LED strip1
byte r2=255,g2=255,b2=255;                     //Stores RGB command from Blynk app and writes it to the LED strip2
byte r=255,g=255,b=255;
byte ResetRGB1=0;                              //For ZeRGB widget 1
byte ResetRGB2=0;                              //For ZeRGB widget 2
void ChangeLEDColour1();                       //Subroutine responsible for changing the RGB LED strip1 colour
void ChangeLEDColour2();                       //Subroutine responsible for changing the RGB LED strip2 colour
void ChangeLEDColour();                         //This changes the colour of the whole strip
byte BrightnessSlider1=0;                       //Blynk slider widget used to select the brightness setting of LED strip 1
byte BrightnessSlider2=0;                       //Blynk slider widget used to select the brightness setting of LED strip 2
byte ConfigureBrightnessDisplay1=0;             //Controls the updating of the brightness display widget 1 so blynk app is not flooded
byte ConfigureBrightnessDisplay2=0;             //Controls the updating of the brightness display widget 1 so blynk app is not flooded
byte AppReconnected=0;                          //Controls when the reconnection subroutine should start occuring from
void CheckBrightnessSetting1();                 //Checks the brightness setting j and is used to update the app when the slider changes brightness and when app disconnects and reconnects it updates the app
void CheckBrightnessSetting2();                 //Checks the brightness setting j and is used to update the app when the slider changes brightness and when app disconnects and reconnects it updates the app
byte LED1BrightnessPin=10;
byte LED2BrightnessPin=11;
byte BrightnessR1=0, BrightnessG1=0, BrightnessB1=0;        //To set the brighness of the LED strip 1 whilst still allowing the ZeRGB to be set by variables r1, g1 and b1
byte BrightnessR2=0, BrightnessG2=0, BrightnessB2=0;        //To set the brighness of the LED strip 2 whilst still allowing the ZeRGB to be set by variables r2, g2 and b2
byte BrightnessR=0, BrightnessG=0, BrightnessB=0;
void LEDNormalisationButton1();                               //Reset the colour of the RGB LED strip 1 to white
void LEDNormalisationButton2();                               //Reset the colour of the RGB LED strip 2 to white
byte PresetLightColour=0;                       
byte PresetLightBrightness=0;                   
byte PresetLightSelection=0;   
void PresetLightSettings();
void DeactivatePreset();

//To control selection of the preset light settings
byte PartyMode=1;
byte RainbowMode=1;
byte RomanceMode=1;         //Brightness must be adjustable, allow it to be set at a standard value of i when the widget when it is first toggled
byte ReadingMode=1;         //Brightness must be adjustable, allow it to be set at a standard value of i when the widget when it is first toggled
byte MovieMode=1;           //Brightness must be adjustable, allow it to be set at a standard value of i when the widget when it is first toggled
byte FireTorchMode=1;
byte FadeMode=1;
byte LightningMode=1;
byte FadeOnOffMode=1;       //Allow colour to be adjusted
byte LightningCounter=0;
byte LightningCounterValue=5;
void CheckLightSettings();  //Checks if any of the preset modes are active and deactivates it before a second preset mode is activated
void UpdateLightSettings(); //Updates the state of the app widgets upon app hardware reconnection
void NormalisePresets();    //To update the state of a preset light condition push button of the app if the light settings was normalised whilst the app was offline 
byte x=0;                   //Used to indicate which was the last preset light condition selected even after that light condition was deselcted. Works with NormalisePresets()

//The initialisations from the orignal WS2812..V1_4 which are needed for some of the preset light settings
CRGBPalette16 currentPalette;
TBlendType    currentBlending;


#include "LedControl.h"
#define MAX_LED 26 // Number of LEDs in bar graph array (10 * 2) but first 10 on rows 1 and 2 and second 10 on rows 3 and 4
#define MAX_BRIGHTNESS 15 // 0-15 LED brightness
#define LED_TIMEOUT 6000 // Time out after which LED bar turns off
boolean isSleeping1=false; //LED bar graph 1          
boolean isSleeping2=false; //LED bar graph 2           
unsigned long lastOn1 = 0; // Last time LED Bar graph 1 was turned ON
unsigned long lastOn2 = 0; // Last time LED Bar graph 2 was turned ON

/*
 pin 9 is connected to the DataIn 
 pin 8 is connected to the CLK 
 pin 7 is connected to LOAD 
*/
LedControl lc=LedControl(29,28,27,1);   //Originally was 9,8,7,1

void HardwarePushbuttons();
void DisplayLEDBarGraphs();
void DisplayToSerialMonitor();
void MainFunction();

int i=0; //Startoff LED bar graph 1 on OFF (No LEDs ON)
int j=16; //Startoff LED bar graph 2 on OFF (No LEDs ON)
byte k1=0, k2=0, k3=0,k4=0, k5=0, k6=0;
int n=0;                                
int o=0;
int p=0;

BlynkTimer timer1;

//To allow the system to connect to another recognized WiFi network if the one is disabled
byte BlynkCounter=0;
void CheckBlynkConnection();
byte BlynkRunCounter=0;
byte SwitchLED=0;
int WifiConnected=0;

//*HOME*
char ssid0[] = "XXXXXXXXXXXX";
char pass0[] = "XXXXXXXXXXX";
//*PHONE 1 MOBILE HOT SPOT*
char ssid1[] = "XXXXXXXXXXX";
char pass1[] = "XXXXXXXXXXXX";
//PHONE 2 MOBILE HOT SPOT
//char ssid2[] = "XXXXXXXXXX";
//char pass2[] = "XXXXXXXXXX";
char server[] = "blynk-cloud.com";  // URL for Blynk Cloud Server
int port = 8080;


// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(12, 13); // RX, TX

// Your ESP8266 baud rate:
//#define ESP8266_BAUD 9600

//ESP8266 wifi(&EspSerial);

void setup() {


  Serial.begin(9600);
  Serial.println(F("Establishing connections..."));
   
  //EspSerial.begin(ESP8266_BAUD);
  delay(10);
  //For Blynk communication
  Blynk.begin(auth, ssid1, pass1);
  //SetupBlynkConnection();
  
  
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,MAX_BRIGHTNESS);
  /* and clear the display */
  lc.clearDisplay(0);

  pinMode(PBIncLight1, INPUT_PULLUP);  //Button press to increase lamp1 light
  pinMode(PBDecLight1, INPUT_PULLUP);  //Button press to decrease lamp1 light
  pinMode(PBIncLight2, INPUT_PULLUP); //Button press to increase lamp2 light
  pinMode(PBDecLight2, INPUT_PULLUP); //Button press to decrease lamp2 light  
  pinMode(PBHardNormLight1,INPUT_PULLUP);                             //Hardware normalises the LED strip 1 to white
  pinMode(PBHardNormLight2,INPUT_PULLUP);                             //Hardware normalises the LED strip 2 to white
  //**Just for testing purposes:**
  pinMode(6, OUTPUT);
  pinMode(5,INPUT_PULLUP);
  
  
  FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
  
  Serial.println (F("Light Control System Version 1_7 (ESP32)"));
  Blynk.virtualWrite(V0, Lamp1);
  Blynk.virtualWrite(V5, Lamp2);
  CheckLightSettings();                                            //To normalise all the app widgets before starting the program
  DeactivatePreset();                     
 
  Blynk.notify("Light control app paired and ready");
  AppReconnected=1;
  delay(200);
  timer1.setInterval(300L, MainFunction);
  
}

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

I have tested and successfully compiled the Blink example code

It might be worth upgrading to the latest FastLED library, and also making sure that you are running the latest ESP32 core.

Other than that, I have very little experience of using the FastLED library and no experience of WS2812 LEDs, so I’ve made this PM public in the hope that others can chip-in.

Pete.

Okay thanks Pete. I have the ESP32 Espressif systems V1.0.4 which is the latest and I have the FastLED V3.3 which is also the latest. I fear that the error might not even be the line of code
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS); since this line of code works with the Blink example. I have searched through google with the error messages produced and have come up short. The entire program works smoothly on the Arduino Mega. This is difficulty I was afraid I would experience switching from Arduino to the ESP boards.
Thanks for opening the topic, any help from the community would be greatly appreciated as I have no idea where to go from here.

Your compiler says:

That’s version 3.3.2, which isn’t the latest, and which is why I suggested installing the latest version:

Pete.

Thanks Pete,I updated the FastLED version after reading your previous message and tried compiling the code and it still has does not compile.
The error message reads:

Arduino: 1.8.10 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"

In file included from C:\Users\Hp Zbook 15\Desktop\Light Control Project\BedSideLightControlExampleV1_7_AddingWS2812LEDControl\BedSideLightControlExampleV1_7_AddingWS2812LEDControl.ino:25:0:

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.003.003

 #    pragma message "FastLED version 3.003.003"

                     ^

In file included from C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:65:0,

                 from C:\Users\Hp Zbook 15\Desktop\Light Control Project\BedSideLightControlExampleV1_7_AddingWS2812LEDControl\BedSideLightControlExampleV1_7_AddingWS2812LEDControl.ino:25:

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/fastspi.h:130:23: note: #pragma message: No hardware SPI pins defined.  All SPI access will default to bitbanged output

 #      pragma message "No hardware SPI pins defined.  All SPI access will default to bitbanged output"

                       ^

In file included from C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:48:0,

                 from C:\Users\Hp Zbook 15\Desktop\Light Control Project\BedSideLightControlExampleV1_7_AddingWS2812LEDControl\BedSideLightControlExampleV1_7_AddingWS2812LEDControl.ino:25:

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/fastpin.h: In instantiation of 'class FastPin<24u>':

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/platforms/esp/32/clockless_rmt_esp32.h:186:23:   required from 'class ClocklessController<24, 60, 150, 90, (EOrder)66u, 0, false, 5>'

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/chipsets.h:582:7:   required from 'class WS2812Controller800Khz<24u, (EOrder)66u>'

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:103:52:   required from 'class WS2812<24u, (EOrder)66u>'

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/FastLED.h:302:39:   required from 'static CLEDController& CFastLED::addLeds(CRGB*, int, int) [with CHIPSET = WS2812; unsigned char DATA_PIN = 24u; EOrder RGB_ORDER = (EOrder)66u]'

C:\Users\Hp Zbook 15\Desktop\Light Control Project\BedSideLightControlExampleV1_7_AddingWS2812LEDControl\BedSideLightControlExampleV1_7_AddingWS2812LEDControl.ino:201:56:   required from here

C:\Users\Hp Zbook 15\Documents\Arduino\libraries\FastLED/fastpin.h:207:2: error: static assertion failed: Invalid pin specified

  static_assert(validpin(), "Invalid pin specified");

  ^

Multiple libraries were found for "FastLED.h"
 Used: C:\Users\Hp
Multiple libraries were found for "WiFi.h"
 Used: C:\Users\Hp
 Not used: C:\Program
Multiple libraries were found for "BlynkSimpleEsp32.h"
 Used: C:\Users\Hp
Multiple libraries were found for "LedControl.h"
 Used: C:\Users\Hp
exit status 1
Error compiling for board ESP32 Dev Module.


I would like to add that when i comment out the line qouted above the program compiles. This is strange. Why does the Blink example compile with this line of code but here it does not compile :face_with_raised_eyebrow:

I did a bit of googling and it seems that the FastLED library doesn’t like pin numbers higher than 19.

Pete.

1 Like

Thanks Pete!
These controllers are very fussy. I did not even think to consider the pin number. I found a guide on the pin numbers to use for the ESP32 on the Blynk forum here, and just assumed since the safe pin numbers range from 18 to 33 that they all would be appropriate. Now that it finally compiled successfully I can finally program the controller and functionally test my project. Thanks a lot Pete!

1 Like

Hello Blynk Community

Trying to get my program to work on the ESP32 has been a complete nightmare.
After the program compiled I began functional testing and was immediately met with a error message on the serial monitor on start up:

Light Control System Version 1_7 (ESP32)
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x401403fa  PS      : 0x00060630  A0      : 0x800d191b  A1      : 0x3ffb1f10  
A2      : 0x3ffc1400  A3      : 0x00000000  A4      : 0x3ffc1308  A5      : 0x00000b97  
A6      : 0x00060420  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffb1ef0  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00000b97  A13     : 0x00004340  
A14     : 0x00000000  A15     : 0x00000002  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x401407f8  LEND    : 0x40140801  LCOUNT  : 0x0000000f  

Backtrace: 0x401403fa:0x3ffb1f10 0x400d1918:0x3ffb1f30 0x400d1f95:0x3ffb1f50 0x400d3d69:0x3ffb1f90 0x400d6541:0x3ffb1fb0 0x40088f49:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Establishing connections...
Light Control System Version 1_7 (ESP32)
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x401403fa  PS      : 0x00060630  A0      : 0x800d191b  A1      : 0x3ffb1f10  
A2      : 0x3ffc1400  A3      : 0x00000000  A4      : 0x3ffc1308  A5      : 0x00000b32  
A6      : 0x00060420  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffb1ef0  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00000b32  A13     : 0x00004380  
A14     : 0x00000000  A15     : 0x00000002  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x401407f8  LEND    : 0x40140801  LCOUNT  : 0x0000000f  

Backtrace: 0x401403fa:0x3ffb1f10 0x400d1918:0x3ffb1f30 0x400d1f95:0x3ffb1f50 0x400d3d69:0x3ffb1f90 0x400d6541:0x3ffb1fb0 0x40088f49:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8

I tried looking through a few ESP32 support forums the last few days to see if someone experienced similar problems but after struggling to understand the comments/suggestions people had offered I eventually gave up and then tried to run my program in smaller chunks to see where the problem lay. I started with this program which worked perfectly:

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  You’ll need:
   - Blynk App (download from AppStore or Google Play)
   - ESP32 board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
byte SwitchLED=0;
void SwitchLEDState();


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).

char auth[] = "XXXXXXXXXXXXX";

// Your WiFi credentials.
// Set password to "" for open networks.
//*HOME*
char ssid0[] = "XXXXXXXXXXX";
char pass0[] = "XXXXXXXXXXX";

void setup()
{
  // Debug console
  Serial.begin(115200);
  Serial.println("Establishing connections...");
  Blynk.begin(auth, ssid0, pass0);
  Serial.println("ESP32 Blynk test code: Switching on Button widget with another button widget");
  Blynk.notify("Test program ready");
  
} 


void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}


//__________________________Test code__________________________________________________________________________________
void SwitchLEDState(){

  if(SwitchLED==1){

    Blynk.virtualWrite(V7,1); //Switch LEDOn
    Serial.println("LED On");
    
  }
  else if(SwitchLED==0){

    Blynk.virtualWrite(V7,0);   //SwitchLEDoff
    Serial.println("LED Off");
  }
  
}

BLYNK_WRITE(V8){                       
    
    if(SwitchLED==1){
      
      SwitchLED=0;
      Serial.println("Push Button switched Off");
      
    }
    else if(SwitchLED==0){

      SwitchLED=1;
      Serial.println("Push Button switched On");
      
    }

    SwitchLEDState();
    
}
//____________________________________________________________________________________________________________________

I then tried the following program because I thought maybe there is some conflict with the ESP32 and the FastLED code but it too worked perfectly:


#include <FastLED.h>
#define LED_PIN     18
#define NUM_LEDS    30
#define BRIGHTNESS  255
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100

// This example shows several ways to set up and use 'palettes' of colors
// with FastLED.
//
// These compact palettes provide an easy way to re-colorize your
// animation on the fly, quickly, easily, and with low overhead.
//
// USING palettes is MUCH simpler in practice than in theory, so first just
// run this sketch, and watch the pretty lights as you then read through
// the code.  Although this sketch has eight (or more) different color schemes,
// the entire sketch compiles down to about 6.5K on AVR.
//
// FastLED provides a few pre-configured color palettes, and makes it
// extremely easy to make up your own color schemes with palettes.
//
// Some notes on the more abstract 'theory and practice' of
// FastLED compact palettes are at the bottom of this file.



CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;


void setup() {

    Serial.begin(115200);
    Serial.println("FastLED test code");
    delay( 3000 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );
    
    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;
}


void loop()
{
    ChangePalettePeriodically();
    
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    
    FillLEDsFromPaletteColors( startIndex);
    
    FastLED.show();
    FastLED.delay(1000 / UPDATES_PER_SECOND);
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
    uint8_t brightness = 255;
    
    for( int i = 0; i < NUM_LEDS; i++) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    }
}


// There are several different palettes of colors demonstrated here.
//
// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
//
// Additionally, you can manually define your own color palettes, or you can write
// code that creates color palettes on the fly.  All are shown here.

void ChangePalettePeriodically()
{
    uint8_t secondHand = (millis() / 1000) % 60;
    static uint8_t lastSecond = 99;
    
    if( lastSecond != secondHand) {
        lastSecond = secondHand;
        if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }
        if( secondHand == 10)  { currentPalette = RainbowStripeColors_p;   currentBlending = NOBLEND;  }
        if( secondHand == 15)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
        if( secondHand == 20)  { SetupPurpleAndGreenPalette();             currentBlending = LINEARBLEND; }
        if( secondHand == 25)  { SetupTotallyRandomPalette();              currentBlending = LINEARBLEND; }
        if( secondHand == 30)  { SetupBlackAndWhiteStripedPalette();       currentBlending = NOBLEND; }
        if( secondHand == 35)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }
        if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 45)  { currentPalette = PartyColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 50)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
        if( secondHand == 55)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
    }
}

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
    for( int i = 0; i < 16; i++) {
        currentPalette[i] = CHSV( random8(), 255, random8());
    }
}

// This function sets up a palette of black and white stripes,
// using code.  Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
void SetupBlackAndWhiteStripedPalette()
{
    // 'black out' all 16 palette entries...
    fill_solid( currentPalette, 16, CRGB::Black);
    // and set every fourth one to white.
    currentPalette[0] = CRGB::White;
    currentPalette[4] = CRGB::White;
    currentPalette[8] = CRGB::White;
    currentPalette[12] = CRGB::White;
    
}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
    CRGB purple = CHSV( HUE_PURPLE, 255, 255);
    CRGB green  = CHSV( HUE_GREEN, 255, 255);
    CRGB black  = CRGB::Black;
    
    currentPalette = CRGBPalette16(
                                   green,  green,  black,  black,
                                   purple, purple, black,  black,
                                   green,  green,  black,  black,
                                   purple, purple, black,  black );
}


// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM.  A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
    CRGB::Red,
    CRGB::Gray, // 'white' is too bright compared to red and blue
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Red,
    CRGB::Gray,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Blue,
    CRGB::Black,
    CRGB::Black
};



// Additional notes on FastLED compact palettes:
//
// Normally, in computer graphics, the palette (or "color lookup table")
// has 256 entries, each containing a specific 24-bit RGB color.  You can then
// index into the color palette using a simple 8-bit (one byte) value.
// A 256-entry color palette takes up 768 bytes of RAM, which on Arduino
// is quite possibly "too many" bytes.
//
// FastLED does offer traditional 256-element palettes, for setups that
// can afford the 768-byte cost in RAM.
//
// However, FastLED also offers a compact alternative.  FastLED offers
// palettes that store 16 distinct entries, but can be accessed AS IF
// they actually have 256 entries; this is accomplished by interpolating
// between the 16 explicit entries to create fifteen intermediate palette
// entries between each pair.
//
// So for example, if you set the first two explicit entries of a compact 
// palette to Green (0,255,0) and Blue (0,0,255), and then retrieved 
// the first sixteen entries from the virtual palette (of 256), you'd get
// Green, followed by a smooth gradient from green-to-blue, and then Blue.

Since the previous 2 programs worked, I had combined the first program with a simplified version of the second:

#include <Blynk.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <FastLED.h>
#define DATA_PIN    18
#define NUM_LEDS    30
CRGB leds[NUM_LEDS];
int SwitchLED=0;
void SwitchLEDState();


char auth[] = "XXXXXXXXXXXXXXXXXXX";


byte RGBColourReset=0;                         //Used to control the execution of normalising the LED colours
byte r1=0,g1=0,b1=0;                           //Stores RGB command from Blynk app and writes it to the LED strip1
void ChangeLEDColour();
byte PBIncLight1=19;              //2
byte PBDecLight1=20;              //4
byte PBIncLight2=21;              //A0
byte PBDecLight2=22;              //A1
byte PBHardNormLight1=23;         //A2
byte PBHardNormLight2=24;         //A3

//*HOME*
char ssid0[] = "XXXXXXXXXXXX";
char pass0[] = "XXXXXXXXXXXX";
//*PHONE 1 MOBILE HOT SPOT*
char ssid1[] = "XXXXXXXXXXXX";
char pass1[] = "XXXXXXXXXXXX";

void UpButtonPress1();
void DownButtonPress1();
void UpButtonPress2();
void DownButtonPress2();
void HardwarePushbuttons();
void DisplayLEDBarGraphs();
void DisplayToSerialMonitor();

int n=0;

BlynkTimer timer1;

void setup() {

  delay(1000);
  Serial.begin(115200);
  delay(1000);
  Serial.println ("Establishing connections...");

  //For Blynk communication
  Blynk.begin(auth, ssid0, pass0);

  
  pinMode(PBIncLight1, INPUT_PULLUP);  //Button press to increase lamp1 light
  pinMode(PBDecLight1, INPUT_PULLUP);  //Button press to decrease lamp1 light
  pinMode(PBIncLight2, INPUT_PULLUP); //Button press to increase lamp2 light
  pinMode(PBDecLight2, INPUT_PULLUP); //Button press to decrease lamp2 light  
  pinMode(PBHardNormLight1,INPUT_PULLUP);                             //Hardware normalises the LED strip 1 to white
  pinMode(PBHardNormLight2,INPUT_PULLUP);                             //Hardware normalises the LED strip 2 to white 
  
  FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
  
  Serial.println ("LED Bar graph test program including Blynk control (version 3_1)_ESP32");
  timer1.setInterval(300L, HardwarePushbuttons);
  
}

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


void HardwarePushbuttons(){
  
     
  //For lamp 1
  if(digitalRead(19)==LOW){

    UpButtonPress1();
      
   }
   else if(digitalRead(20)==LOW){
  
    DownButtonPress1();
      
   }
   //For lamp 2  
   if(digitalRead(21)==LOW){

    UpButtonPress2();
      
   }
   else if(digitalRead(22)==LOW){
  
    DownButtonPress2();
      
   }  
  
}

void UpButtonPress1(){
    
  Serial.println("UpButton1 was pressed"); 
  
}

void DownButtonPress1(){

  Serial.println("DownButton1 was pressed");
  
}

void UpButtonPress2(){

  Serial.println("UpButton2 was pressed");

}

void DownButtonPress2(){

  Serial.println("DownButton2 was pressed");
  
}


BLYNK_WRITE(V2){                       
    
    UpButtonPress1();
    
}

BLYNK_WRITE(V3){                       
    
    DownButtonPress1();
    
}

BLYNK_WRITE(V8){                       
    
    UpButtonPress2();
    
}

BLYNK_WRITE(V9){                       
    
    DownButtonPress2();
    
}


//ZeRGB widget 1
BLYNK_WRITE(V5){                       
    
    //Set RGB to be white
    r1=255;g1=255;b1=255;
    //Update the ZeRGB widget 
    ChangeLEDColour();
    
}


BLYNK_WRITE(V11) // zeRGBa LED strip 1 assigned 
{
    // get a RED channel value
    r1 = param[0].asInt();
    // get a GREEN channel value
    g1 = param[1].asInt();
    // get a BLUE channel value
    b1 = param[2].asInt();

    ChangeLEDColour();
    
}


void ChangeLEDColour(){

  //Change colour of the LEDs for strip 1
  for(n=NUM_LEDS;n<=NUM_LEDS;n++){
     leds[n]=CRGB(r1,g1,b1);                            
     FastLED.show();
  }


  //For debugging
  Serial.print("Red= ");
  Serial.println(r1); 
  Serial.print("Green= ");
  Serial.println(g1);
  Serial.print("Blue= ");
  Serial.println(b1);
  Serial.println(""); 
  
}


//Executes when the hardware connects to the app  
BLYNK_CONNECTED(){
    
    Blynk.notify("Light system connected");
    //Serial.println("Light system Connected");
    
}


void SwitchLEDState(){

  if(SwitchLED==1){

    Blynk.virtualWrite(V8,255); //Switch LEDOn
    Serial.println("LED On");
    
  }
  else if(SwitchLED==0){

    Blynk.virtualWrite(V8,0);   //SwitchLEDoff
    Serial.println("LED Off");
  }
  
}

BLYNK_WRITE(V7){                       
    
    if(SwitchLED==1){
      
      SwitchLED=0;
      Serial.println("Push Button switched Off");
      
    }
    else if(SwitchLED==0){

      SwitchLED=1;
      Serial.println("Push Button switched On");
      
    }

    SwitchLEDState();
    
}

For some reason this program, although it compiles and a connection to Blynk is established, crashes whenever i toggle the ZeRGB widget to change the colour and it never switches the LED strip on. The controller reboots and starts the program over. When i toggle the pushbutton V7 then the pushbutton V8 does not switch On. The following is printed on the serial monitor:

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x40088c3a  PS      : 0x00060630  A0      : 0x800d2261  A1      : 0x3ffb1d50  
A2      : 0x0000007b  A3      : 0x00000000  A4      : 0xffffffff  A5      : 0x00000000  
A6      : 0x00000000  A7      : 0x00000004  A8      : 0x00000000  A9      : 0x00000000  
A10     : 0x00000000  A11     : 0x00060423  A12     : 0x00000050  A13     : 0x3ffc1410  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x000000bb  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  

Backtrace: 0x40088c3a:0x3ffb1d50 0x400d225e:0x3ffb1d90 0x400d2071:0x3ffb1db0 0x400d3915:0x3ffb1df0 0x400d1269:0x3ffb1e30 0x400d131e:0x3ffb1e50 0x400d157a:0x3ffb1e80 0x400d182d:0x3ffb1ee0 0x400d1a9b:0x3ffb1f50 0x400d1f1d:0x3ffb1f90 0x400d43c1:0x3ffb1fb0 0x40088f49:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Establishing connections...
LED Bar graph test program including Blynk control (version 3_1)_ESP32

I can’t understand what is it that is about toggling Blynk functions that is causing the project to crash. Please, anyone who has experience with the ESP32 please advice.

The error message I am experiencing is the briefly explained here but I am struggling to figure out where the issue is in my program. I also found this web page on the forum and am failing to find a way to apply the configuration settings using the arduino IDE here. In fact, I am having a tough time trying to figure out if the issue is related to Blynk, since toggling of the zeRGB widget results in crashes or if it is the FastLED library or is it something far more trivial (like assigning a different GPIO to be the data line for the FastLED code). If anyone has had success applying some sort of fault-finding strategy or methodology pin pointing issues/errors with the ESP32, please be so kind and share your advice :disappointed:

Have you tried changing the sequence of the included libraries in your sketch, maybe putting FastLED before Blynk?

Pete.

There is a simple but severe error in your code, creating the crash (out-of bound of array)

Change from

void ChangeLEDColour() {

  //Change colour of the LEDs for strip 1
  for (n = NUM_LEDS; n <= NUM_LEDS; n++) {
    leds[n] = CRGB(r1, g1, b1);
    FastLED.show();
  }
  ..
}

to

void ChangeLEDColour() {
  //Change colour of the LEDs for strip 1
for (int n = 0; n < NUM_LEDS; n++) {
    leds[n] = CRGB(r1, g1, b1);
    FastLED.show();
  }
   ...
}

Hope you re-study the code and find out why yourself.

Hello
@PeteKnight I have just tried this and the app still crashes when I toggle the zeRGB widget. When I press the virtual PB 7, the serial print statement prints LED On or Off statements but the Blynk.write code does not update the state of Virtual PB assigned to V8. So nothing has improved

@khoih Thanks, I do see the error with this statement. I had actually split my LED strip in 2 and when I picked chunks of code from the completed code that functions on the Mega, I copied the wrong chunk and even edited it incorrectly thereafter. So I copied the code that governs the second half of strip to the end. Thanks for pointing that out. However, the program is still crashing and rebooting when I toggle the zeRGB widget and the Blynk.virtualWrite() commands to the virtual push buttons still appear to have no effect :disappointed:

Your code seems to think that there is a virtual LED attached to V8, not a virtual push button.

Pete.

What makes you say this? The code is structured exactly the same as first example code referenced here

And this worked :confused:

This line of code…

Pete.

Whoops :sweat_smile:. Changed that to a 1 and it worked. Thanks Pete.
I am adding subtracting so many chunks of code to pinpoint where the error is I am making careless mistakes. The push button does switch on and off as expected but my main problem of the project rebooting still on going. I am also consulting other forums to see if anyone there has a better idea of what exactly is going on

I think i managed to isolate the cause of the crash, it seems that this line of code leds[n]=CRGB(255,255,255); in the ChangeLEDColour() subroutine is causing the Guru meditation error. I am not sure why since this line of code functions perfectly on the arduino controllers.

I think you’ll find that as @khoih pointed-out, the issue is with the ‘for’ loop the increments ‘n’ variable.
We think that the value of ‘n’ is being taken out of the acceptable range of values, causing an invalid pointer which then causes the crash (apologies if I’m speaking out of turn in regards to @khoih’s take on this - that’s my interpretation of his tale on the issue).

If your unsure about what is happening to the value of ‘n’ then somply drop in a serial.print statement immediately after the ‘for’ statement.

Pete.

Hello @PeteKnight

okay so as stated earlier I have already made adjustments for the error that @khoih picked up. I isolated segments of my code and ran the program and initially narrowed down the issue to the for loop by replacing the

  //Change colour of the LEDs for strip 1
  for (n = NUM_LEDS; n <= NUM_LEDS; n++) {
    leds[n] = CRGB(r1, g1, b1);
    FastLED.show();
  }

with the following

  //Change colour of the LEDs for strip 1
  for (int n = 0; n <= NUM_LEDS; n++) {
    Serial.print("Value of n=");
    Serial.println(n);
  }
 

When the ran the program with this code, the ESP32 did not crash or reboot but produced the values of n from 0 to 30 on the serial monitor as expected

Value of leds n=0
Value of leds n=1
Value of leds n=2
Value of leds n=3
Value of leds n=4
Value of leds n=5
Value of leds n=6
Value of leds n=7
Value of leds n=8
Value of leds n=9
Value of leds n=10
Value of leds n=11
Value of leds n=12
Value of leds n=13
Value of leds n=14
Value of leds n=15
Value of leds n=16
Value of leds n=17
Value of leds n=18
Value of leds n=19
Value of leds n=20
Value of leds n=21
Value of leds n=22
Value of leds n=23
Value of leds n=24
Value of leds n=25
Value of leds n=26
Value of leds n=27
Value of leds n=28
Value of leds n=29
Value of leds n=30

This is far as i went before reading your response today. Now I ran the following combination of code:

 //Change colour of the LEDs for strip 1
  for(int n=0;n<=NUM_LEDS;n++){
     Serial.print("Value of leds n=");
     Serial.println(n);
     leds[n]=CRGB(r1,g1,b1);                            
     FastLED.show();
  }

And this was the output on the serial monitor

LED Bar graph test program including Blynk control (version 3_1)_ESP32
Value of leds n=0
Value of leds n=1
Value of leds n=2
Value of leds n=3
Value of leds n=4
Value of leds n=5
Value of leds n=6
Value of leds n=7
Value of leds n=8
Value of leds n=9
Value of leds n=10
Value of leds n=11
Value of leds n=12
Value of leds n=13
Value of leds n=14
Value of leds n=15
Value of leds n=16
Value of leds n=17
Value of leds n=18
Value of leds n=19
Value of leds n=20
Value of leds n=21
Value of leds n=22
Value of leds n=23
Value of leds n=24
Value of leds n=25
Value of leds n=26
Value of leds n=27
Value of leds n=28
Value of leds n=29
Value of leds n=30
Red= 255
Green= 255
Blue= 255

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d1a0c  PS      : 0x00060630  A0      : 0x800d21f4  A1      : 0x3ffb1f50  
A2      : 0x00000000  A3      : 0x3ffc13ff  A4      : 0x3ffc1394  A5      : 0x00000001  
A6      : 0x00000000  A7      : 0x3ffb0060  A8      : 0x800d1b4e  A9      : 0x3ffb1ef0  
A10     : 0x0000003f  A11     : 0x3ffb1ef0  A12     : 0x00000013  A13     : 0x3ffc1394  
A14     : 0x3ffb1ef0  A15     : 0x3ffb1ef0  SAR     : 0x00000020  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x0000003f  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  

Backtrace: 0x400d1a0c:0x3ffb1f50 0x400d21f1:0x3ffb1f90 0x400d4755:0x3ffb1fb0 0x40088f49:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

Strange. The entire for loop runs but when it completes, it causes the ESP32 to crash and reboot. Finally I started tinkering with the numbers and believe i found what the problem is. I replaced the NUM_LEDS with integers ranging from 10 all the way to 30. No crashes until 29 but as soon as i reach 30 the ESP32 runs the program and crashes for some reason! I am not sure why though. If i can understand this it will help me to figure out where the problem lies in my actual fully completed program. Since my complete program splits the for loop maximum count to 15 so it is operating fine on the complete program. I will add more chunks and continue to try to figure out why my main program is crashing. Thanks @PeteKnight and @khoih