Guru Meditation Error when setting pinMode

Hello,
I am trying to implement a SparkFun TCA9534 because I ran out of pins. I am simply trying to turn the pins to output so I can control a relay. However, the esp32 errors with a Guru Meditation Error right at 'ourGPIO.pinMode(relayOutPin, GPIO_OUT); // relayOutPin'. The last line to be sent to the serial before the esp32 resets is 'Serial.println(".................before gpio..........................");'.

I am using a Sparkfun ESP32 IoT Redboard with a Spawrkfun Qwiic GPIO.

Here is my setup and loop.

#define ESP32
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include "MovingAverage.h"
#include "SparkFun_Qwiic_Ultrasonic_Arduino_Library.h"
#include "SparkFun_TCA9534.h"
#include <ESP32Servo.h>

#include "FS.h"
#include "SD.h"
#include "SPI.h"
#include <EasyBNO055_ESP.h>  //bno IMU
#define RC                   //use this when choosing what mode to be in and not signaled in. line 76
//#define DEBUG
//#define DEBUG_RC_IN
#define MinSpeed -255      // SETTING MAX AND MIN SPEED LIMITS // <-------needs to change
#define MaxSpeed 255       // SETTING MAX AND MIN SPEED LIMITS //
#define Min_Steering -255  // SETTING MAX AND MIN STEERING LIMITS //
#define Max_Steering 255   // SETTING MAX AND MIN STEERING LIMITS //
#define Min_Throttle -255  // SETTING MAX AND MIN Throttle LIMITS //
#define Max_Throttle 255   // SETTING MAX AND MIN Throttle LIMITS //
#define DeadBandHigh 1520
#define DeadBandLow 1480  // SETTING DEAD BAND LIMITS FOR RADIO NOISE //
#define rightSidePin 16   //out to motor controller
#define leftSidePin 17    //out to motor controller
#define DANGER_DIST 0     //ultrasonic distance for danger stop
#define CONCERN_DIST 500  //ultrasonic distance for concern
#define mode_All_STOP 3   //enumeration of modes
#define mode_RC 1
#define mode_RECORD 0
#define mode_PLAYBACK 2
#define OLED                       // to enable OLED screen
#define SLAVE_BROADCAST_ADDR 0x00  //default address for ultrasonic
#define SLAVE_ADDR 0x00            //SLAVE_ADDR 0xA0-0xAF for ultrasonic
#define NUMBER_OF_SENSORS 2
#define CHANNEL_1_PIN 27  // coming in from reciever
#define CHANNEL_2_PIN 35
#define spraySensitivity_PIN 34     //ARTEMIS PIN CHANGE per 012-002
#define steeringSensitivity_PIN 32  //ARTEMIS PIN CHANGE per 012-002
#define relayPinA 25                //ARTEMIS PIN CHANGE per 012-002
#define ModePin 33                  //ARTEMIS PIN CHANGE per 012-002
#define SCREEN_WIDTH 128            // OLED display width, in pixels
#define SCREEN_HEIGHT 32            // OLED display height, in pixels
#define OLED_RESET -1               // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C         ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
#define relayOutPin 5               //i2c breakoutboard gpio 5
#define headingConstant .1
#define LHDir_PIN 5  //
#define RHDir_PIN 4
//gpio LED PIN
#define WhitePin 0   //i2c breakoutboard gpio 0
#define BluePin 1    //i2c breakoutboard gpio 1
#define GreenPin 2   //i2c breakoutboard gpio 2
#define OrangePin 3  //i2c breakoutboard gpio 3
#define RedPin 4     //i2c breakoutboard gpio 4
//LED PIN
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

TCA9534 ourGPIO;

QwiicUltrasonic LHUltraSonic;
QwiicUltrasonic RHUltraSonic;
//QwiicUltrasonic CEUltraSonic;
#ifndef RC
mode = mode_RC;
#endif
#ifndef ESP32
OpenLog SD;
#endif
////////////////// Harware Interior TIMER INTERUPTs//////////////////////////
volatile int interruptCounter;  //for counting interrupt
int totalInterruptCounter;      //total interrupt counting
hw_timer_t* timer = NULL;       //H/W timer defining (Pointer to the Structure)
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR onTimer() {  //Defining Inerrupt function with IRAM_ATTR for faster access
  portENTER_CRITICAL_ISR(&timerMux);
  interruptCounter++;
  portEXIT_CRITICAL_ISR(&timerMux);
}
////////////////// Harware Interior TIMER INTERUPTs//////////////////////////

Servo leftSideServo;  // create servo object to control a servo
Servo rightSideServo;
MovingAverage<long, 16> LHFilter;
MovingAverage<long, 16> RHFilter;
MovingAverage<long, 16> CEFilter;

uint8_t distance_H = 0;  //ultrasonic
uint8_t distance_L = 0;  //ultrasonic
uint16_t distance = 0;   //ultrasonic
volatile unsigned long pulseInTimeBegin1 = micros();
volatile unsigned long pulseInTimeBegin2 = micros();
volatile unsigned long pulseInTimeBeginRelay1 = micros();
volatile unsigned long pulseInTimeBeginMode = micros();
volatile unsigned long pulseInTimeBeginModeSensitivity = micros();
volatile unsigned long pulseInTimeBeginSteeringSensitivity = micros();

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars], messageFromPC[numChars] = { 0 }, logMessage[numChars];
int integerFromPC = 0, anchor1 = 1780, anchor2 = 1781;
float floatFromPC = 0.0, anchorDistance1, anchorDistance2;
bool newData = false, mode_Flag = false;
int pos = 0;           // variable to store the servo position
int incomingByte = 0;  // for incoming serial data
float trop1;
float trop2, LHMIX, RHMIX;
int mode = 1;  //mode is record or playback
float LHPWM, RHPWM, ThetaPath;
volatile long LHdur = 1500, RHdur = 1500;
long LHdur1 = 1500, RHdur1 = 1500;
long Relaydur1 = 2000;
long SprayDuration;
long Spray_Sensitivity_dur1 = 1500;
volatile long Steering_Sensitivity_dur = 1500;
long Steering_Sensitivity_dur1 = 1500;
long Mode_dur = 1000;
int startTime;
int startTime_Playback;
long currentFilePosition = 0;
long RTime, dt;
//int HeadingCurrent = 0;
//int ultraSonic[] = { 0x22, 0x23 }; //used to check if ultra was connected or not
bool DangerFlag = false;
bool RelayFlag = false;
bool EndOfFile = false;
bool SprayOutput = false;
bool recordFirstTime = false;
bool LHDIR = false;
bool RHDIR = false;
float data[12]; //fitness  //fitness is the root mean squared of how well the robot followed the path.
float errorTotal1 = 0, errorTotal2 = 0;
float errorAnchor1 = 0, errorAnchor2 = 0;
EasyBNO055_ESP bno;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////SETUP////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {

  //bno.start(); //starts up BNO IMU // without one hooked up this freezes the code
  Wire.begin();
  Serial.begin(115200);
  Serial1.begin(38400, SERIAL_8N1, 13, 14);  // Rx = 13, Tx = 14 will work for ESP32
  Serial.println("serial setup");
  delay(1000);

  ledcSetup(1, 12000, 8);          // 12 kHz PWM, 8-bit resolution, these pins control the speed to the motor controller
  ledcSetup(2, 12000, 8);          // 12 kHz PWM, 8-bit resolution
  ledcAttachPin(rightSidePin, 1);  //new for 14-001 have to set up fast pins for analog out
  ledcAttachPin(leftSidePin, 2);
  pinMode(LHDir_PIN, OUTPUT);  //new for 14-001 have to set up direction pins
  pinMode(RHDir_PIN, OUTPUT);

#ifdef ESP32

  ESP32PWM::allocateTimer(0);
  ESP32PWM::allocateTimer(1);
  ESP32PWM::allocateTimer(2);
  ESP32PWM::allocateTimer(3);
  // leftSideServo.setPeriodHertz(50); // standard 50 hz servo i don't think we need the servo code anymore
  //leftSideServo.attach(rightSidePin, 1000, 2000); // attaches the servo on pin 18 to the servo object
  //rightSideServo.setPeriodHertz(50); // standard 50 hz servo
  //rightSideServo.attach(rightSidePin, 1000, 2000); // attaches the servo on pin 18 to the servo object
  if (!SD.begin()) {
    Serial.println("Card Mount Failed");
  } else {
    Serial.println("Card Mounted baby!");
  }
#endif
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
  Serial.println(".................before gpio..........................");
  ourGPIO.pinMode(relayOutPin, GPIO_OUT); // relayOutPin
  Serial.println(".................AFTER first gpio..........................");
  pinMode(relayPinA, INPUT);
  pinMode(CHANNEL_1_PIN, INPUT);
  pinMode(CHANNEL_2_PIN, INPUT);
  pinMode(ModePin, INPUT);
  pinMode(spraySensitivity_PIN, INPUT);
  pinMode(steeringSensitivity_PIN, INPUT);
  attachInterrupt(digitalPinToInterrupt(ModePin), ModePin_interupt, CHANGE);
  attachInterrupt(digitalPinToInterrupt(relayPinA), SprayPin_Interupt, CHANGE);
  attachInterrupt(digitalPinToInterrupt(CHANNEL_1_PIN), Channel_1_PinInterupt, CHANGE);
  attachInterrupt(digitalPinToInterrupt(CHANNEL_2_PIN), Channel_2_PinInterupt, CHANGE);
  attachInterrupt(digitalPinToInterrupt(spraySensitivity_PIN), spraySensitivity, CHANGE);
  attachInterrupt(digitalPinToInterrupt(steeringSensitivity_PIN), steeringSensitivity, CHANGE);
  startTime = millis();
  Serial.println(".................AFTER attaching pins..........................");
  //LED PINS
  ourGPIO.pinMode(WhitePin, GPIO_OUT);   // WHITE
  ourGPIO.pinMode(BluePin, GPIO_OUT);    // BLUE
  ourGPIO.pinMode(GreenPin, GPIO_OUT);   // GREEN
  ourGPIO.pinMode(OrangePin, GPIO_OUT);  // ORANGE
  ourGPIO.pinMode(RedPin, GPIO_OUT);     // RED
  //LED PINS
  Serial.println(".................AFTER LED..........................");
  ////////////////////////// INTERIOR HARDWARE TIMER ////////////////////////////////////////////////

  timer = timerBegin(0, 80, true);              // timer 0, prescalar: 80, UP counting
  timerAttachInterrupt(timer, &onTimer, true);  // Attach interrupt
  timerAlarmWrite(timer, 100000, true);         // Match value= 1000000 for 1 sec. delay.
  timerAlarmEnable(timer);                      // Enable Timer with interrupt (Alarm Enable)
  ////////////////////////// INTERIOR HARDWARE TIMER ////////////////////////////////////////////////
  Serial.println(".................AFTER Timer..........................");
  //while (LHUltraSonic.begin(ultraSonic[0]) == false) {

  // Serial.print(" Ultrasonic sensor not connected, check your wiring and I2C address!");
  // Serial.println(ultraSonic[0]);
  //}

  //while (RHUltraSonic.begin(ultraSonic[1]) == false) {
  //Serial.print(" Ultrasonic sensor not connected, check your wiring and I2C address!");
  //Serial.println(ultraSonic[1]);
  //}
}

Blockquote

void loop() {
  //Serial.println(bno.orientationZ);
  GetLocalReadings();  //get UWB readings, for all modes
  Serial.print(".........................................................................");
  ourGPIO.digitalWrite(WhitePin, LOW);
  ourGPIO.digitalWrite(BluePin, LOW);
  ourGPIO.digitalWrite(GreenPin, LOW);
  ourGPIO.digitalWrite(OrangePin, LOW);
  ourGPIO.digitalWrite(RedPin, LOW);
  //all LEDs off

  if (mode == mode_RC) {  //mode RC
    Spray();
    ourGPIO.digitalWrite(GreenPin, HIGH);  //green on!
    currentFilePosition = 0;               //resetting the file to the start
    EndOfFile = false;
    MIXRC();  //get RC PWM, for RC and REC only
    SprayDuration = Relaydur1;
    startTime_Playback = millis();
    startTime = millis();
    recordFirstTime = true;
    data[0] = 0;
  }
  if (mode == mode_RECORD) {  //mode record
    while (1) {
      ourGPIO.digitalWrite(BluePin, HIGH);
      //delay(1000);
      ourGPIO.digitalWrite(BluePin, LOW);
    }
    if (recordFirstTime) {
      if (SD.remove("/log.txt")) {
        Serial.println("File deleted");
      } else {
        Serial.println("Delete failed");
      }
    }

    recordFirstTime = false;

    Spray();
    currentFilePosition = 0;  //resetting the file to the start
    MIXRC();                  //get RC PWM, for RC and REC only
    EndOfFile = false;
    SprayDuration = Relaydur1;
    startTime_Playback = millis();
    data[0] = 0;
  }

  if (mode == mode_PLAYBACK) {  //mode playback
    while (1) {
      ourGPIO.digitalWrite(WhitePin, HIGH);
      //delay(1000);
      ourGPIO.digitalWrite(WhitePin, LOW);
    }
    startTime = millis();
    dt = millis() - startTime_Playback;

    if ((dt > data[0]) && (mode != mode_All_STOP)) {
      readFile(SD, "/log.txt");                                                  // checks times and read next file line to get new instructions
      ThetaPath = data[6];                                                       // setting the current heading to thetapath
      SprayOutput = data[3];                                                     // setting spray trigger to what came in from playback file
      errorAnchor1 = (data[4] - anchorDistance1) * (data[4] - anchorDistance1);  //finding error squared between recorded anchor and current anchor
      errorAnchor2 = (data[5] - anchorDistance2) * (data[5] - anchorDistance2);  //finding error squared between recorded anchor and current anchor
      errorTotal1 = errorTotal1 + errorAnchor1;
      errorTotal2 = errorTotal2 + errorAnchor2;

      LHMIX = data[1] - (bno.orientationZ - ThetaPath) * headingConstant;  // setting LH drive to what came in from file, accounts for heading error
      RHMIX = data[2] + (bno.orientationZ - ThetaPath) * headingConstant;  // setting RH drive to what came in from file, accounts for heading error
    }
    if (EndOfFile) {
      Serial.print("end of file");
      AllStop_FXN();
      currentFilePosition = 0;
    }
  }

  ////////////////////// HARWARE INTERIOR TIMER FOR RECORDING SAMPLING////////////////
  if (interruptCounter > 0) {
    portENTER_CRITICAL(&timerMux);
    interruptCounter--;
    portEXIT_CRITICAL(&timerMux);
    if (mode == mode_RECORD) {
      recordPath(SD);
    }
    totalInterruptCounter++;  //counting total interrupt
  }
  ////////////////////// HARWARE INTERIOR TIMER FOR RECORDING SAMPLING////////////////

  //localEnvironmentCheck(); //check local sensors

  checkMode();
  Output();

#ifdef DEBUG
  debugDisplay();
#endif
#ifdef OLED
  display.clearDisplay();
  OLED_display();
#endif
#ifdef DEBUG_RC_IN
  debugRC_IN();
#endif
}

The error.

Rebooting...
ets Jul 29 2019 12:21:46

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:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
serial setup
Card Mounted baby!
.................before gpio..........................
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400d2fa3  PS      : 0x00060a30  A0      : 0x800d3133  A1      : 0x3ffc5c90  
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000002  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x800d60ac  A9      : 0x3ffc5c70  
A10     : 0x3ffbdd8c  A11     : 0x3f40585f  A12     : 0x00000002  A13     : 0xffffffff  
A14     : 0x3ffbd9ec  A15     : 0x00000000  SAR     : 0x0000001b  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000040  LBEG    : 0x40087e11  LEND    : 0x40087e21  LCOUNT  : 0xffffffff  


Backtrace: 0x400d2fa0:0x3ffc5c90 0x400d3130:0x3ffc5cb0 0x400d3f87:0x3ffc5cd0 0x400d3fe1:0x3ffc5cf0 0x400d1ed5:0x3ffc5d10 0x400d9266:0x3ffc5d40




ELF file SHA256: 24388e1c5d2c3857

Any help would be appreciated.
Thank you.

Run the ESP exception decoder to get a readable stack dump.

Apologies for the late response, have been dealing with uni.
Here is the stack dump from the decoder.

PC: 0x400d327b:  is in TwoWire::beginTransmission(unsigned short) (C:\Users\iashesh\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\libraries\Wire\src\Wire.cpp:410).
EXCVADDR: 0x00000040

Decoding stack results
0x400d3278:  is in TwoWire::beginTransmission(unsigned short) (C:\Users\iashesh\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\libraries\Wire\src\Wire.cpp:409).
0x400d3408:  is in TwoWire::beginTransmission(unsigned char) (C:\Users\iashesh\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\libraries\Wire\src\Wire.cpp:637).
0x400d425f:  is in TCA9534::writeRegister(unsigned char, unsigned char) (C:\Users\iashesh\Documents\Arduino\libraries\SparkFun_Qwiic_GPIO_TCA9534_Arduino_Library\src\SparkFun_TCA9534.cpp:135).
0x400d42b9:  is in TCA9534::pinMode(unsigned char, bool) (C:\Users\iashesh\Documents\Arduino\libraries\SparkFun_Qwiic_GPIO_TCA9534_Arduino_Library\src\SparkFun_TCA9534.cpp:42).
0x400d1eed: setup() at C:\Users\iashesh\Desktop\Project Skunk\Code\skunk_014-003\skunk_014-003.ino:187
0x400d9b3a: loopTask(void*) at C:\Users\iashesh\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32\main.cpp:42

You should call ourGPIO.begin() with appropriate parameters before trying to use the TCA9534. You are trying to call member functions before the class is initialized - as you found this does not end well.

Thank you so much, can't belive it was such a simple addition.