How to solve Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled

Hi. I'm not native, sorry for the bad english. I'm using an NodeMCU esp32-s, and I keep getting this error when I try to connect the code. Some things are in spanish.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Arduino.h>
#include <MQ135.h>
#include "DHT.h"
#include <WiFi.h>
#include "ThingSpeak.h"


// Configuración del LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);  // Dirección I2C y tamaño del LCD (16 columnas y 2 filas)
int screen = 0;  

//Configuración WiFi y ThingSpeak
const char* ssid = "...";
const char* password = "...";
unsigned long channelID = ....;
const char* WriteAPIKey = "...";
   
WiFiClient Client;

// Temporizadores para cambios de pantalla y actualizaciones de ThingSpeak
unsigned long previousMillis = 0;    // Para gestionar los cambios de pantalla
const long interval1 = 60000;         // Intervalo de 1 minuto (60,000 ms)
 

// Pines de sensores
//#define PIN_MQ135 A0 // MQ135 Analog Input Pin
#define DHTPIN 25    // DHT Digital Input Pin
#define DHTTYPE DHT11  // DHT 11

//MQ135 mq135_sensor(PIN_MQ135);
DHT dht(DHTPIN, DHTTYPE);

// Variables para temperatura y humedad
float t = 0.0, h = 0.0, hic = 0.0;

const int PIN_R1 = 33;    // LED Rojo RGB1
const int PIN_Y1 = 23;    // LED Amarillo/Azul RGB1
const int PIN_G1 = 32;    // LED Verde RGB1
const int PIN_R2 = 19;    // LED Rojo RGB2
const int PIN_Y2 = 5;     // LED Amarillo/Azul RGB2
const int PIN_G2 = 18;    // LED Verde RGB2

const int freq = 500;    // Frecuencia PWM ajustada a 500 Hz
const int LED_CHANNEL_R1 = 0;
const int LED_CHANNEL_Y1 = 1;
const int LED_CHANNEL_G1 = 2;
const int LED_CHANNEL_R2 = 3;
const int LED_CHANNEL_Y2 = 4;
const int LED_CHANNEL_G2 = 5;
const int resol = 8;     // Resolución de 8 bits

const int buzzer = 17;
void setup() {
  // Inicializar LEDs y buzzer
  pinMode(PIN_R1, OUTPUT);
  pinMode(PIN_Y1, OUTPUT);
  pinMode(PIN_G1, OUTPUT);
  pinMode(PIN_R2, OUTPUT);
  pinMode(PIN_Y2, OUTPUT);
  pinMode(PIN_G2, OUTPUT);
  pinMode(buzzer, OUTPUT);
  // Configurar PWM para cada canal
  ledcSetup(LED_CHANNEL_R1, freq, resol);
  ledcSetup(LED_CHANNEL_Y1, freq, resol);
  ledcSetup(LED_CHANNEL_G1, freq, resol);
  ledcSetup(LED_CHANNEL_R2, freq, resol);
  ledcSetup(LED_CHANNEL_Y2, freq, resol);
  ledcSetup(LED_CHANNEL_G2, freq, resol);

  // Asignar los pines al canal PWM correspondiente
  ledcAttachPin(PIN_R1, LED_CHANNEL_R1);
  ledcAttachPin(PIN_Y1, LED_CHANNEL_Y1);
  ledcAttachPin(PIN_G1, LED_CHANNEL_G1);
  ledcAttachPin(PIN_R2, LED_CHANNEL_R2);
  ledcAttachPin(PIN_Y2, LED_CHANNEL_Y2);
  ledcAttachPin(PIN_G2, LED_CHANNEL_G2);
  
  
  
  // Inicializar comunicación Serial
  Serial.begin(115200);

 // Conexión Wi-Fi
  WiFi.begin(ssid, password);
  Serial.println("Conectando a WiFi...");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi conectado.");

  // Inicializar ThingSpeak
  ThingSpeak.begin(Client);

  // Inicializar sensores
  dht.begin();
  
  // Inicializar LCD
  lcd.begin();          // Usar lcd.init() en lugar de lcd.begin() para algunas librerías
  lcd.setCursor(0, 0);
    lcd.print("Monitoreo");
    lcd.setCursor(0, 1);
    lcd.print("Ambiental");
   delay(2000);
}

void loop() {
  unsigned long currentMillis = millis();
  // La lectura de la temperatura o humedad toma aproximadamente 250 milisegundos.
  // Las lecturas pueden demorarse 2 segundos debido a la lentitud del sensor.
  h = dht.readHumidity(); // Humedad
  t = dht.readTemperature(); // Temperatura en Celsius (default)
  hic = dht.computeHeatIndex(t, h, false); // Computa la sensación térmica en Celsius (isFahreheit = false)
  
  // Verificar si hay errores en la lectura de los sensores
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Falla en el sensor DHT11!"));
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Falla");
    lcd.setCursor(0, 1);
    lcd.print("Sensor DHT11");
    return; // Salir del loop para evitar ejecutar el resto del código
  }
   // Leer el sensor MQ135
  //float mq135_value = mq135_sensor.getPPM(); // Obtener el valor de CO2 en PPM
  // Nota: La función getPPM() puede variar según la librería MQ135 que estés usando

  // Gestión de la pantalla LCD cada minuto
  if (currentMillis - previousMillis >= interval1) {
    previousMillis = currentMillis;  // Actualiza el temporizador
    screen++;  // Pasa a la siguiente pantalla

    // Volver al principio cuando se muestran todas las pantallas
    if (screen > 3) { // Aumenté a 3 para incluir la calidad del aire
      screen = 0;
    }
  }

    ThingSpeak.setField(1, t);
    ThingSpeak.setField(2, h);
    ThingSpeak.setField(3, hic);
    //ThingSpeak.setField(4, mq135_value);
    ThingSpeak.writeFields(channelID, WriteAPIKey);

  // Control de LEDs y Buzzer basado en temperatura y sensación térmica
  if (t > 38 || hic > 45) { // Valores críticos
    ledcWrite(LED_CHANNEL_R1, 255);  // Valor PWM máximo (8 bits = 255)
    ledcWrite(LED_CHANNEL_Y1, 0);    // Apagar el LED Amarillo/Azul
    ledcWrite(LED_CHANNEL_G1, 0);    // Apagar el LED Verde
    digitalWrite(buzzer, HIGH);
    delay(5000);  // Mantener encendido 1 segundo
  
  } 
  else if (t > 26 || hic > 40) { // Valores anómalos
    ledcWrite(PIN_R1, 255);  
    ledcWrite(PIN_Y1, 0);  // Encender LED Amarillo con brillo máximo
    ledcWrite(PIN_G1, 255);
    digitalWrite(buzzer, LOW); // Apagar buzzer
  } 
  else { // Valores normales
    ledcWrite(PIN_R1, 0); 
    ledcWrite(PIN_Y1, 0);
    ledcWrite(PIN_G1, 255);  // Encender LED Verde con brillo máximo
  }

  /* Control de LEDs basado en calidad del aire (MQ135)
  if (mq135_value > 1000) { // Calidad del aire peligrosa
    ledcWrite(LED_CHANNEL_R2, 255);
    ledcWrite(LED_CHANNEL_Y2, 0);
    ledcWrite(LED_CHANNEL_G2, 0);
    digitalWrite(buzzer, HIGH);
  } else if (mq135_value > 700) { // Calidad del aire deficiente
    ledcWrite(LED_CHANNEL_R2, 0);
    ledcWrite(LED_CHANNEL_Y2, 255);
    ledcWrite(LED_CHANNEL_G2, 0);
  } else { // Calidad del aire buena
    ledcWrite(LED_CHANNEL_R2, 0);
    ledcWrite(LED_CHANNEL_Y2, 0);
    ledcWrite(LED_CHANNEL_G2, 255);
  }
 */
  // Mostrar información en el LCD según la pantalla actual
  lcd.clear();
  switch (screen) {
    case 0:
      // Mostrar temperatura
      lcd.setCursor(0, 0);
      lcd.print("Temperatura:");
      lcd.setCursor(0, 1);
      lcd.print(t);
      lcd.print("°C");
      break;
    
    case 1:
      // Mostrar humedad
      lcd.setCursor(0, 0);
      lcd.print("Humedad:");
      lcd.setCursor(0, 1);
      lcd.print(h);
      lcd.print(" %");
      break;
    
    case 2:
      // Mostrar sensación térmica
      lcd.setCursor(0, 0);
      lcd.print("Sens Termica:");
      lcd.setCursor(0, 1);
      lcd.print(hic);
      lcd.print("°C");
      break;
    
    /*case 3:
      // Mostrar calidad del aire (MQ135)
      lcd.setCursor(0, 0);
      lcd.print("Calidad Aire:");
      lcd.setCursor(0, 1);
      lcd.print(mq135_value);
      lcd.print(" PPM");
      break;
      */
  }

  // Imprimir valores en el Serial Monitor
  Serial.print(F("Humedad: "));
  Serial.print(h);
  Serial.print(F("%  Temperatura: "));
  Serial.print(t);
  Serial.print(F("°C  Sens. Termica: "));
  Serial.print(hic);
  Serial.print(F("°C  Calidad Aire: "));
  //Serial.print(mq135_value);
  //Serial.println(F(" PPM"));
  ThingSpeak.setField(1, t);
  ThingSpeak.setField(2,h);
  ThingSpeak.setField(3,hic);
  // Pequeño retardo para estabilidad
  delay(100); // 100 ms para evitar lecturas demasiado rápidas
}

I just want to know why is this error, any help is well received.

Your problem may be here, in this very big dealys.

How far does the code get? What output do you see? What is in the exception trace? What is the result of running the ESP Exception Decoder on the exception?

try using lower case c in your var name "client", Client is used in the lib..

good luck.. ~q

It's the correct way to suspend a task on FreeRTOS. But I don' t know whether the S3 uses RTOS and how the default task (without TaskCreate...) behaves.

OMG thank you, I didn't see that delay(5000), it was a mistake when I typed. I'm gonna try to change it and see what happens.

Only gets to "wifi connected". In the lcd display , only prints "m", It doesn't even get to print the whole word, like Monitoring. And then it crashes. I'll send to you the exception trace, but the ESP Exception Decoder doesn't work in my arduino IDE, or at least I don't know how to make it work.
Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d3578: f2e502ad 000000ff 32004136
Core 1 register dump:
PC : 0x400d357d PS : 0x00060530 A0 : 0x8014f420 A1 : 0x3ffb21f0
A2 : 0x3ffc3ba4 A3 : 0x0000004d A4 : 0x00000060 A5 : 0x00000001
A6 : 0x00060120 A7 : 0x00000001 A8 : 0x800d357d A9 : 0x3ffb21d0
A10 : 0x3ffc3ba4 A11 : 0x000004d0 A12 : 0x000004d1 A13 : 0x3ffb20e0
A14 : 0x00000003 A15 : 0x00060023 SAR : 0x0000001c EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x40084af9 LEND : 0x40084b01 LCOUNT : 0x00000027

Backtrace: 0x400d357a:0x3ffb21f0 0x4014f41d:0x3ffb2210 0x400d60d7:0x3ffb2230 0x400d60e9:0x3ffb2250 0x400d3218:0x3ffb2270 0x400d7e91:0x3ffb2290

I started commenting some parts of the code, and I'm sure the problem is the lcd display, but I don't know why

You didn't answer this question:

You need to run the exception decoder on your system. It needs the results of the compile/link to resolve the addresses.

I figured out. It was an tiny change. In the library (documents), I had to change the architecture in the JSON file, and other things. :warning: Compiler warnings · schackniss/esp32-lichtwecker Wiki · GitHub That´s were I found the steps about how to fix it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.