[SOLVED] Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled

Hello !

I am trying to run a simple code using this library, but I can’t, because I added WiFi to it and it crashes like crazy.

This is the code:

#include <Arduino.h>
#include <SmartMatrix3.h>
#include <WiFi.h>

#define COLOR_DEPTH 24                  // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
const uint8_t kMatrixWidth = 64;        // known working: 32, 64, 96, 128
const uint8_t kMatrixHeight = 32;       // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 36;       // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 4;       // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_64COL_MOD8SCAN_L540_2727;   // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE);      // see http://docs.pixelmatix.com/SmartMatrix for options
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);
const uint8_t kIndexedLayerOptions = (SM_INDEXED_OPTIONS_NONE);

SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
SMARTMATRIX_ALLOCATE_INDEXED_LAYER(indexedLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kIndexedLayerOptions);

const int defaultBrightness = (100*255)/100;        // full (100%) brightness
const int Brightness_15 = (15*255)/100;       // dim: 15% brightness
const int defaultScrollOffset = 6;
const rgb24 defaultBackgroundColor = {0x40, 0, 0};

#define WHITE   rgb24(0xFF,0xFF,0xFF)
#define BLACK   rgb24(0x00,0x00,0x00)
#define CYAN    rgb24(0x00,0xFF,0xFF)
#define RED     rgb24(0xFF,0x00,0x00)

#define DEMO_INTRO              1
#define DEMO_BRIGHTNESS         1

void triangles() {
  backgroundLayer.setBrightness(Brightness_15);
  backgroundLayer.drawTriangle(41,5,41,25,58,15,WHITE);
  backgroundLayer.fillTriangle(41,5,41,25,58,15,WHITE);
  // backgroundLayer.swapBuffers();
}


char* IPAddr;
const char* ssid = "ssid";
const char* password = "password";

void setup() {
  Serial.begin(115200);
  delay(500);
  WiFi.begin(ssid, password);
  delay(500);
  int k = 0;
  while (WiFi.status() != WL_CONNECTED && k<20) {
    k++;
    delay(1000);
    Serial.println((String)"Attempt " + k + " - Connecting to WiFi..");
  }

  delay(1000);

  matrix.addLayer(&backgroundLayer); 
  matrix.addLayer(&scrollingLayer); 
  matrix.addLayer(&indexedLayer); 
  matrix.begin();

  matrix.setBrightness(defaultBrightness);

  scrollingLayer.setOffsetFromTop(defaultScrollOffset);

  backgroundLayer.enableColorCorrection(true);
  backgroundLayer.fillScreen(defaultBackgroundColor);
  backgroundLayer.swapBuffers();  

  if(WiFi.status() == WL_CONNECTED) {
    String IP = WiFi.localIP().toString();
    IP.toCharArray(IPAddr,IP.length());
    Serial.println((String)"Connected to " + ssid + " with IP addres: " + IPAddr);
    scrollingLayer.setColor(CYAN);
    scrollingLayer.setFont(font5x7);
    // scrollingLayer.setCursor(1,1);
    scrollingLayer.start(IPAddr,1);
    delay(50);    
  } else {
      Serial.println("Couldn't connect to WiFi Network. Restarting in 5 seconds...");
      scrollingLayer.setColor(RED);
      scrollingLayer.setFont(font5x7);
      // scrollingLayer.setCursor(1,1);
      scrollingLayer.start("Error 1 - Restarting in 5 sec!",1);
      
      delay(5000);
      ESP.restart();
  }
  
  triangles();
}




void loop() {
//   // unsigned long currentMillis;
//   backgroundLayer.fillScreen(BLACK);
//   backgroundLayer.swapBuffers();

//   #if (DEMO_INTRO == 1)
//     // "SmartMatrix Demo"
//     // backgroundLayer.fillScreen(BLACK);
//     scrollingLayer.setColor(WHITE);
//     scrollingLayer.setMode(wrapForward);
//     scrollingLayer.setSpeed(40);
//     scrollingLayer.setFont(font6x10);
//     scrollingLayer.start("SmartMatrix Demo", 1);

//     delay(5000);
// #endif

//   triangles();

}

This is what I get on the Serial Monitor:

Attempt 1 - Connecting to WiFi..

Starting SmartMatrix Mallocs
Heap/32-bit Memory Available: 279744 bytes total, 113792 bytes largest free block
8-bit/DMA Memory Available  : 226188 bytes total, 113792 bytes largest free block
SmartMatrix Layers Allocated from Heap:
Heap/32-bit Memory Available: 265940 bytes total, 113792 bytes largest free block
Starting SmartMatrix DMA Mallocs
sizeof framestruct: 00004000
DMA Memory Available before ptr1 alloc: 179168 bytes total, 113792 bytes largest free block
matrixUpdateFrames[0] pointer: 3FFCBC0C
DMA Memory Available before ptr2 alloc: 177460 bytes total, 113792 bytes largest free block
matrixUpdateFrames[1] pointer: 3FFCFC1C
Frame Structs Allocated from Heap:
Heap/32-bit Memory Available: 232724 bytes total, 113792 bytes largest free block
8-bit/DMA Memory Available  : 179168 bytes total, 113792 bytes largest free block
Allocating refresh buffer:
lsbMsbTransitionBit of 0 requires 24576 RAM, 113792 available, leaving 89216 free: 
Raised lsbMsbTransitionBit to 0/7 to fit in RAM
lsbMsbTransitionBit of 0 gives 76 Hz refresh, 120 requested: 
lsbMsbTransitionBit of 1 gives 152 Hz refresh, 120 requested: 
Raised lsbMsbTransitionBit to 1/7 to meet minimum refresh rate
Descriptors for lsbMsbTransitionBit 1/7 with 8 rows require 12288 bytes of DMA RAM
SmartMatrix Mallocs Complete
Heap/32-bit Memory Available: 220404 bytes total, 113792 bytes largest free block
8-bit/DMA Memory Available  : 166848 bytes total, 113792 bytes largest free block
Setting up parallel I2S bus at I2S1

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400014fd  PS      : 0x00060430  A0      : 0x800d1dfc  A1      : 0x3ffb1f10  
A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3ffb1ee0  
A10     : 0x3ffb80c0  A11     : 0x3ffbbf54  A12     : 0x00000000  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x00000004  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  

ELF file SHA256: 0000000000000000000000000000000000000000000000000000000000000000

Backtrace: 0x400014fd:0x3ffb1f10 0x400d1df9:0x3ffb1f20 0x400d28fd:0x3ffb1f40 0x400d5683:0x3ffb1fb0 0x4008ef39:0x3ffb1fd0

Rebooting...
Decoding stack results
0x400d1dfd: Print::printNumber(unsigned long, unsigned char) at /home/george/Arduino/hardware/espressif/esp32/cores/esp32/Print.cpp line 246
0x400d292d: loopTask(void*) at /home/george/Arduino/hardware/espressif/esp32/cores/esp32/main.cpp line 20
0x400d56bf: _fseeko_r at ../../../.././newlib/libc/stdio/fseeko.c line 146

What’s happening ?

Another problem I have is with backgroundLayer.drawString(15,5,RED,(char*)space); where space is unsigned int.

This ends up in Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Also, if I do the following: char x[1] = {23}; and backgroundLayer.drawString(5,5,GREEN,x); it displays nothing.

  //unsigned int space = 23;
  char x[1] = {23};
  backgroundLayer.setBrightness(Brightness_15);
  backgroundLayer.fillScreen(BLACK);
  backgroundLayer.setFont(font8x13);  

  if(space == 0) {
//  backgroundLayer.drawString(15,5,RED,(char*)space);
    backgroundLayer.drawString(15,5,RED,x);
  } else if(space < 9) {
    backgroundLayer.drawString(15,5,GREEN,x);
  } else if (space > 9) {
    backgroundLayer.drawString(5,5,GREEN,x);
  }  
  // backgroundLayer.drawTriangle(41,6,41,26,58,16,WHITE);
  // backgroundLayer.fillTriangle(41,6,41,26,58,16,WHITE);
  backgroundLayer.swapBuffers();

You might need to leave some extra RAM for the WiFi library (or other libraries) to use. You can pass the number of bytes you need left free as an argument to matrix.begin(), check out the AnimatedGIFs example.

I don’t know what to tell you, the code expects char*, maybe you should copy your int buffer to a char buffer before trying to use the string.

I’ve fixed it by doing this:

  unsigned int space
  char x[5];
  sprintf(x,"%d",space);
  backgroundLayer.drawString(15,5,GREEN,x);