ESP32 RTC Software debugging HELP!

I am working on a calendar project using an old Vorne 2000c canned display. basically, all the display does is call up messages and can display real-time data. all through an 8-bit data port on the back. right now I am having an issue trying to figure out how to use the internal rtc on my esp32 wrover. I am simply trying to create a way where I can program the internal rtc using 3 buttons and a switch. the switch is on when I want to program the calendar. two buttons control the change, one to add whatever digits to the data and one to subtract. The final button switches between all the things that can change so minutes hours days months years. I am using a switch case for the button presses but I keep getting this rebooting error on my serial monitor, can anyone help me troubleshoot what could be wrong with my code? I also have a rtc module that is separate from the esp32 if that would work better.
later on, my plan is to have kinda a finite state machine based on the input from the rtc and have each combination be an 8-bit number that calls a message, the messages are formatted like this "Jan Sun, ^^, ^:^^ AM" the ^ are where real-time data goes which is also pulsed through the 8-bit port on the back first 4 buts are the number and next 3 are the location up to 8 digits of real-time data can be shown. is there a better approach to what I would like to do if so I am open to feed back!

#include <ESP32Time.h>

ESP32Time rtc(3600);  // offset in seconds GMT+1

//input and outputs
const int addButton = 11;     //button to add one 
const int subButton = 10;     //Button to subract one
const int progButton = 9;    //Button to switch between what to program
const int progSwitch = 13;
const int pulse = 5;         //Pin for the pulse signal 
const int var = 6;           //Pin for the Var Data signal 
//const int vorneMOut[] = {7, 8, 9, 10, 11, 12, 13, 14}; //binary output for vorne display
//const int vorneDOut[] = {11, 12, 13, 14};             //binary output for data
//const int vorneLOut[] = {8, 9, 10};                //binary output for location of each data


int addButtonState = HIGH;
int subButtonState = HIGH;
int progButtonState = HIGH;
int progButtonCounter = 0;
int previousProgButtonState = HIGH; 
int fieldValues[] = { 0, 0, 0, 1, 1, 2000}; //initial values for seconds, minute, hour, day#, month, year 
const int currentOption = progButtonCounter;      //keeps track of what option is being selected


//4 bit arrays for each digit 
int min1Array[4] = {0}; 
int min2Array[4] = {0};

int hour1Array[4] = {0};
int hour2Array[4] = {0};

int day1Array[4] = {0};
int day2Array[4] = {0};

int year1Array[4] = {0};
int year2Array[4] = {0};
int year3Array[4] = {0};
int year4Array[4] = {0};


//time values
const unsigned long intervalTime = 1000; // time that the binary number is being sent 
const unsigned long pulseTime = 900; // Time that the pulse pin is being pulsed need to be at least 10ms


void setup() {


  Serial.begin(9600);  // Initialize Serial Monitor

rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);


 // Set pin modes
  //for (int i = 0; i < 8; i++) {
 //   pinMode(vorneMOut[i], OUTPUT);
 // }
// for (int i = 0; i < 4; i++) {
//    pinMode(vorneDOut[i], OUTPUT);
 // }
 //for (int i = 0; i < 3; i++) {
//    pinMode(vorneLOut[i], OUTPUT);
 // }
  pinMode(pulse, OUTPUT);
  pinMode(var, OUTPUT);
  pinMode(addButton, INPUT_PULLUP);
  pinMode(subButton, INPUT_PULLUP);
  pinMode(progButton, INPUT_PULLUP);
  pinMode(progSwitch, INPUT_PULLUP);


}

void loop() {
 if (digitalRead(progSwitch) == HIGH)
  { // Prog switch is turned on to program
    if (progButtonState != previousProgButtonState)
    {
      if (digitalRead(progButton) == LOW)
      {
        progButtonCounter++;
        Serial.print("Button pressed! Counter: ");
        Serial.println(progButtonCounter);
      }
      previousProgButtonState = progButtonState; // Update the previous button state
    }

    if (progButtonCounter >= 5){
      progButtonCounter = 0;
      Serial.println("Counter reset to zero");

    }

    switch (progButtonCounter) {

    case 0: //changing the minute 
  addButtonState = digitalRead(addButton);  // Read the state of the button

  if (addButtonState == HIGH) {  // Button is pressed
    Serial.println("addButton pressed!");
    fieldValues[1] += 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    if (fieldValues[1] == 60)
    fieldValues[1] = 0;
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

  }
  subButtonState = digitalRead(subButton); // Read the state of the button
  if (subButtonState == HIGH){
  Serial.println("subButton pressed!");
    fieldValues[1] -= 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    if (fieldValues[1] == -1)
    fieldValues[1] = 59;
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    }
    
      break;
    case 1: //changing the hour
     addButtonState = digitalRead(addButton);  // Read the state of the button

  if (addButtonState == HIGH) {  // Button is pressed
    Serial.println("addButton pressed!");
    fieldValues[2] += 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    if (fieldValues[2] == 25)
    fieldValues[2] = 0;
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

  }
  subButtonState = digitalRead(subButton); // Read the state of the button
  if (subButtonState == HIGH){
  Serial.println("subButton pressed!");
    fieldValues[2] -= 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    if (fieldValues[2] == -1)
    fieldValues[2] = 24;
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    } 
    break;
case 2: //changing the day
       addButtonState = digitalRead(addButton);  // Read the state of the button

  if (addButtonState == HIGH) {  // Button is pressed
    Serial.println("addButton pressed!");
    fieldValues[3] += 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    if (fieldValues[3] == 32)
    fieldValues[3] = 1;
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

  }
    subButtonState = digitalRead(subButton); // Read the state of the button
  if (subButtonState == HIGH){
  Serial.println("subButton pressed!");
    fieldValues[3] -= 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    if (fieldValues[3] == 0)
    fieldValues[3] = 31;
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    } 

      break;
    case 3: //change the month
      addButtonState = digitalRead(addButton);  // Read the state of the button

  if (addButtonState == HIGH) {  // Button is pressed
    Serial.println("addButton pressed!");
    fieldValues[4] += 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    if (fieldValues[4] == 13)
    fieldValues[4] = 1;
rtc.setTime(fieldValues[4], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));


  }
    subButtonState = digitalRead(subButton); // Read the state of the button
  if (subButtonState == HIGH){
  Serial.println("subButton pressed!");
    fieldValues[4] -= 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    if (fieldValues[4] == 0)
    fieldValues[4] = 12;
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

    } 

      break;
    case 4: //changing the year
  addButtonState = digitalRead(addButton);  // Read the state of the button

  if (addButtonState == HIGH) {  // Button is pressed
    Serial.println("addButton pressed!");
    fieldValues[5] += 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));

  }
    subButtonState = digitalRead(subButton); // Read the state of the button
  if (subButtonState == HIGH){
  Serial.println("subButton pressed!");
    fieldValues[5] -= 1;
    delay(200);  // Add a small delay to debounce the button
rtc.setTime(fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3], fieldValues[4], fieldValues[5]);
       Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S %p"));
    } 
 
      break;
  
    

    }
  }

}



here is the error i keep getting

Rebooting...
��'������WAdbc5\� ��Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x40081265 PS : 0x00060530 A0 : 0x800d0d95 A1 : 0x3ffb1f60
A2 : 0x0000000b A3 : 0x00000005 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x00000001 A7 : 0x00000000 A8 : 0x3f400504 A9 : 0x00000000
A10 : 0xbb333301 A11 : 0x0000005c A12 : 0x00000000 A13 : 0x00002ad1
A14 : 0xffffffff A15 : 0x3ffbefb4 SAR : 0x0000001a EXCCAUSE: 0x0000001c
EXCVADDR: 0xbb333301 LBEG : 0x4008867c LEND : 0x400886c4 LCOUNT : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x40081265:0x3ffb1f60 0x400d0d92:0x3ffb1f80 0x400d2bde:0x3ffb1fb0 0x4008b439:0x3ffb1fd0

Rebooting...

Here is another version of a code using the rtc module ds3231i am able to be in the programming mode but then when i click the buttons i get the same error.

#include <Wire.h> // Library for I2C communication
#include <RTClib.h> // Library for RTC module

const int switchPin = 13;      // Pin for the switch
const int cycleButtonPin = 9; // Pin for cycling through settings
const int incButtonPin = 10;   // Pin for incrementing value
const int decButtonPin = 11;   // Pin for decrementing value

RTC_DS3231 rtc; // Create an instance of the RTC module

bool programmingMode = false; // Flag to indicate programming mode

enum Setting {
  MONTH,
  DAY,
  HOUR,
  MINUTE,
  YEAR
};

Setting currentSetting = MONTH;

int incrementSpeed = 1; // Initial increment speed for holding the increment button
int decrementSpeed = 1; // Initial decrement speed for holding the decrement button
const int maxSpeed = 10; // Maximum speed cap for incrementing or decrementing

int getDaysInMonth(int month, int year);

void setup() {
  Serial.begin(9600); // Initialize serial communication for debugging

  pinMode(switchPin, INPUT_PULLUP);       // Set switch pin as input with pull-up resistor
  pinMode(cycleButtonPin, INPUT_PULLUP);  // Set cycle button pin as input with pull-up resistor
  pinMode(incButtonPin, INPUT_PULLUP);    // Set increment button pin as input with pull-up resistor
  pinMode(decButtonPin, INPUT_PULLUP);    // Set decrement button pin as input with pull-up resistor

  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
}

void cycleSetting() {
  currentSetting = static_cast<Setting>((static_cast<int>(currentSetting) + 1) % 5);

  switch (currentSetting) {
    case MONTH:
      Serial.println("Setting: Month");
      break;
    case DAY:
      Serial.println("Setting: Day");
      break;
    case HOUR:
      Serial.println("Setting: Hour");
      break;
    case MINUTE:
      Serial.println("Setting: Minute");
      break;
    case YEAR:
      Serial.println("Setting: Year");
      break;
  }
}

void incrementMonth() {
  DateTime now = rtc.now();
  int month = now.month();
  
  month++;
  if (month > 12) {
    month = 1;
  }
  
  rtc.adjust(DateTime(now.year(), month, now.day(), now.hour(), now.minute(), now.second()));
}

void decrementMonth() {
  DateTime now = rtc.now();
  int month = now.month();
  
  month--;
  if (month < 1) {
    month = 12;
  }
  
  rtc.adjust(DateTime(now.year(), month, now.day(), now.hour(), now.minute(), now.second()));
}

void incrementDay() {
  DateTime now = rtc.now();
  int month = now.month();
  int year = now.year();
  int day = now.day();
  
  int daysInMonth = getDaysInMonth(month, year);

  day++;
  if (day > daysInMonth) {
    day = 1;
    month++;
    if (month > 12) {
      month = 1;
      year++;
    }
  }

  rtc.adjust(DateTime(year, month, day, now.hour(), now.minute(), now.second()));
}

void decrementDay() {
  DateTime now = rtc.now();
  int month = now.month();
  int year = now.year();
  int day = now.day();

  day--;
  if (day < 1) {
    month--;
    if (month < 1) {
      month = 12;
      year--;
    }
    int daysInMonth = getDaysInMonth(month, year);
    day = daysInMonth;
  }

  rtc.adjust(DateTime(year, month, day, now.hour(), now.minute(), now.second()));
}

void incrementHour() {
  DateTime now = rtc.now();
  int hour = now.hour();
  
  hour++;
  if (hour > 12) {
    hour = 0;
  }
  
  rtc.adjust(DateTime(now.year(), now.month(), now.day(), hour, now.minute(), now.second()));
}

void decrementHour() {
  DateTime now = rtc.now();
  int hour = now.hour();
  
  hour--;
  if (hour < 0) {
    hour = 12;
  }
  
  rtc.adjust(DateTime(now.year(), now.month(), now.day(), hour, now.minute(), now.second()));
}

void incrementMinute() {
  DateTime now = rtc.now();
  int minute = now.minute();
  
  minute++;
  if (minute >= 60) {
    minute = 0;
  }
  
  rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), minute, now.second()));
}

void decrementMinute() {
  DateTime now = rtc.now();
  int minute = now.minute();
  
  minute--;
  if (minute < 0) {
    minute = 59;
  }
  
  rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), minute, now.second()));
}

void incrementYear() {
  DateTime now = rtc.now();
  int year = now.year();
  
  year++;
  if (year > 9999) {
    year = 0;
  }
  
  rtc.adjust(DateTime(year, now.month(), now.day(), now.hour(), now.minute(), now.second()));
}

void decrementYear() {
  DateTime now = rtc.now();
  int year = now.year();
  
  year--;
  if (year < 0) {
    year = 9999;
  }
  
  rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second()));
}

void accelerateIncrement() {
  if (incrementSpeed < maxSpeed) {
    incrementSpeed++;
  }
}

void accelerateDecrement() {
  if (decrementSpeed < maxSpeed) {
    decrementSpeed++;
  }
}

void resetSpeed() {
  incrementSpeed = 1;
  decrementSpeed = 1;
}


int getDaysInMonth(int month, int year) {
  if (month == 2) {
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
      return 29; // Leap year
    } else {
      return 28; // Non-leap year
    }
  } else if (month == 4 || month == 6 || month == 9 || month == 11) {
    return 30;
  } else {
    return 31;
  }
}


void loop() {
  if (digitalRead(switchPin) == LOW) {
    programmingMode = true;
    Serial.println("Programming mode enabled");
  } else {
    programmingMode = false;
  }

  if (programmingMode) {
    // Code for programming mode
    if (digitalRead(cycleButtonPin) == LOW) {
      cycleSetting();
      // Add logic for incrementing/decrementing values based on current setting
      switch (currentSetting) {
        case MONTH:
          if (digitalRead(incButtonPin) == LOW) {
            incrementMonth();
          }
          if (digitalRead(decButtonPin) == LOW) {
            decrementMonth();
          }
          break;
        case DAY:
          if (digitalRead(incButtonPin) == LOW) {
            incrementDay();
          }
          if (digitalRead(decButtonPin) == LOW) {
            decrementDay();
          }
          break;
        case HOUR:
          if (digitalRead(incButtonPin) == LOW) {
            incrementHour();
          }
          if (digitalRead(decButtonPin) == LOW) {
            decrementHour();
          }
          break;
        case MINUTE:
          if (digitalRead(incButtonPin) == LOW) {
            incrementMinute();
          }
          if (digitalRead(decButtonPin) == LOW) {
            decrementMinute();
          }
          break;
        case YEAR:
          if (digitalRead(incButtonPin) == LOW) {
            if (incrementSpeed < maxSpeed) {
              incrementYear();
              accelerateIncrement();
            }
          } else {
            resetSpeed();
          }
          if (digitalRead(decButtonPin) == LOW) {
            if (decrementSpeed < maxSpeed) {
              decrementYear();
              accelerateDecrement();
            }
          } else {
            resetSpeed();
          }
          break;
        // Add cases for other settings here
      }
    }
  } else {
    // Code for normal display mode
    // Add your logic for displaying the calendar using the Vorne display
  }
delay(20000);
  DateTime now = rtc.now();
  Serial.print("Current Date and Time: ");
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
}

here is the error:

01:28:53.331 -> PC : 0x40088548 PS : 0x00060034 A0 : 0x8008b114 A1 : 0x3ffb1e60
01:28:53.427 -> A2 : 0x3ffb0058 A3 : 0x3f40d43c A4 : 0x3ffb006c A5 : 0x3ffbeb80
01:28:53.523 -> A6 : 0x3ffbebc8 A7 : 0x00000001 A8 : 0x00000018 A9 : 0x0000ff00
01:28:53.620 -> A10 : 0x00ff0000 A11 : 0xff000000 A12 : 0x8008bca3 A13 : 0x3ffbeb50
01:28:53.716 -> A14 : 0x00000008 A15 : 0x00000001 SAR : 0x0000001d EXCCAUSE: 0x00000006
01:28:53.812 -> EXCVADDR: 0x00000000 LBEG : 0x40088c19 LEND : 0x40088c29 LCOUNT : 0xffffffff
01:28:53.876 ->
01:28:53.909 -> ELF file SHA256: 0000000000000000
01:28:53.940 ->
01:28:53.940 -> Backtrace: 0x40088548:0x3ffb1e60 0x4008b111:0x3ffb1e80 0x4008ccbc:0x3ffb1ea0 0x4008cc72:0x3ffb1ec0 0x400d156d:0x00000000
01:28:54.068 ->
01:28:54.068 -> Core 0 register dump:
01:28:54.100 -> PC : 0x400edf62 PS : 0x00060b34 A0 : 0x800e326e A1 : 0x3ffbc130
01:28:54.164 -> A2 : 0x00000000 A3 : 0x00000001 A4

Install the esp exception decoder and feed it the exception data. This will give you the source lines associated with the Backtrace:. Hopefully this will give a clue as to where to start looking for the error. Do an internet search on esp exception decoder for details.

Your initial error

would indicate an attempt to use an invalid address to read memory. This could be an array bound problem or a bad pointer.

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