I am trying to get a switch press to trigger an interrupt using an ESP32 processor. The NO switch is pulled HIGH when idle, and LOW when pressed. I’m running Win 10 and IDE 1.8.10. I can duplicate the error with this code:
#include <TFT_eSPI.h> // https://github.com/Bodmer/TFT_eSPI Hardware-specific library
#include <rom/gpio.h>
//#include <Rotary.h> // https://github.com/buxtronix/arduino/blob/master/libraries/Rotary/examples/interrupt/interrupt.ino
#define DISPLAYWIDTH 320
#define DISPLAYHEIGHT 240
#define MSGSWITCH1 22 // The message NO pushbutton switches
#define MSGSWITCH2 17
#define MSGSWITCH3 16
#define TFT_MISO 19 // From ESP32 TFT User_Setup.h
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 15 // Chip select control pin
#define TFT_DC 2 // Data Command control pin
#define TFT_RST 4 // Reset pin (could connect to RST pin)
char contestExchanges[5][31] = { // Exchange Message for Contest or common info:
" ", // DO NOT CHANGE. 30 spaces to create 1-based array and used for erasing messages
"ABCDEFGHIJKLMNOPQRST", // General CQ. Change as needed
};
TFT_eSPI tft = TFT_eSPI();
void ReadMessageSwitch1()
{
SendMessage(1);
}
void MyDelay(unsigned long millisWait)
{
unsigned long now = millis();
while (millis() - now < millisWait)
; // Twiddle thumbs...
}
void SendMessage(int messageSwitch)
{
char *msg = &contestExchanges[1][0];
int letterCount = 0;
int rowCount = 0;
tft.fillRect(0, 0, DISPLAYWIDTH, DISPLAYWIDTH,0); // Erase screen
tft.setCursor(0, 20);
Serial.print("In SendLetters(), msg = ");
Serial.println(msg);
// MyDelay(500L);
while (*msg != '\0') {
tft.print(*msg++);
}
}
void setup()
{
Serial.begin(115200);
pinMode(MSGSWITCH1, INPUT_PULLUP); // Message switches
attachInterrupt(digitalPinToInterrupt(MSGSWITCH1), ReadMessageSwitch1, CHANGE); // Message to send
tft.setTextColor(TFT_WHITE, TFT_BLACK);
}
void loop() {
}
If I run the code as above, it appears that the interrupt fires properly and uses SendMessage() to display the message. It repeats the message 4 times. I figured this might be a bounce problem, so I tried adding MyDelay() to the code (commented out right now). Uncommenting MyDelay() causes me to get a “panicked guru” error message and a register dump. I was hoping to avoid a hardware debounce. I know a Serial.print() object in interrupt routines is a bad idea, but removing them doesn’t change the results. Any ideas?