<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Buttons+gps+interrupts problem]]></title><description><![CDATA[<p dir="auto">Hello I have a problem while using gps module(M003) interrupts and buttons on Core 2<br />
When i didn't use buttons everything was working but when i started to use buttons device is restarting with  Guru Meditation Error: Core  1 panic'ed (Coprocessor exception)<br />
For interrupt i use hall sensor connected to pin 21<br />
There is also a problem when it finally didn't get Coprocessor exception   click buton make interrupt stops working and i need to attach it again(as on button A). When i'm using M5.update() device resets after geting few falling signals from hall sensors and button click . I tried to use task pinned to core and move there button check but it didn't helped at all.<br />
Here is my code :</p>
<pre><code>#include &lt;M5Core2.h&gt;
#include &lt;TinyGPS++.h&gt;

#define PIN 21
const int buttonPin = 2;     
float start, finished;
float elapsed;
float circMetric=2.093; // wheel circumference (in meters)
float circImperial; // using 1 kilometer = 0.621371192 miles
float speedk, speedm;    // holds calculated speed vales in metric and imperial
unsigned long currentMillis;
const unsigned long period = 5000;  //milliseconds
unsigned long startMillis; 

// The TinyGPS++ object
TinyGPSPlus gps;


static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (Serial2.available() &gt; 0)
      gps.encode(Serial2.read());
  } while (millis() - start &lt; ms);
  M5.Lcd.clear();
}

void displayInfo()
{
  M5.Lcd.setCursor(0, 40, 4);
  M5.Lcd.print(F("Latitude:    ")); 
  if (gps.location.isValid())
  {
    M5.Lcd.print(gps.location.lat(), 6);
    
  }
  else
  {
    M5.Lcd.print(F("INVALID"));
  }
  
  M5.Lcd.println();
  M5.Lcd.print(F("Longitude:    ")); 
  if (gps.location.isValid())
  {
    M5.Lcd.print(gps.location.lng(), 6);   
  }
  else
  {
    M5.Lcd.print(F("INVALID"));
  }
  
  M5.Lcd.println();
  M5.Lcd.print(F("Altitude:    ")); 
  if (gps.altitude.isValid())
  {
    M5.Lcd.print(gps.altitude.meters());
  }
  else
  {
    M5.Lcd.print(F("INVALID"));
  }

  M5.Lcd.println();
  M5.Lcd.print(F("Satellites:    "));
  if (gps.satellites.isValid())
  {
    M5.Lcd.print(gps.satellites.value());
  }
  else
  {
    M5.Lcd.print(F("INVALID"));
  }

  M5.Lcd.println();
  M5.Lcd.print(F("Speed h: "));

  M5.Lcd.print(int(speedk));


  M5.Lcd.println();
  M5.Lcd.print(F("Speed: "));
  if (gps.speed.isValid())
  {
M5.Lcd.print(gps.speed.kmph());
  }
  
  else
  {
    M5.Lcd.print(F("INVALID"));
  }

}


void speedCalc()
{
  //Function called by the interrupt

  if((millis()-start)&gt;100) // 100 millisec debounce
    {
    //calculate elapsed
    elapsed=millis()-start;

    //reset start
    start=millis();
  
    //calculate speed in km/h
    speedk=(3600*circMetric)/elapsed; 

    //calculate speed in mph
   // speedm=(3600*circImperial)/elapsed; 
    }

}






void setup()
{ pinMode(PIN, INPUT);

  M5.begin(true, true, true, false, kMBusModeInput);
  Serial2.begin(9600, SERIAL_8N1, 13, 14);  
  M5.Lcd.setTextColor(GREEN, BLACK);
  attachInterrupt(digitalPinToInterrupt(PIN), speedCalc, FALLING);
  start=millis();

}

void loop()
{ 
   M5.Touch.update();
  M5.Buttons.update();
    displayInfo();

  
 gps.encode(Serial2.read());   

  if(M5.BtnB.wasPressed())
  {
    M5.Lcd.print(F("Change"));
    delay(100);
  }
    if(M5.BtnC.wasPressed())
  {
  
    
  }
  if(M5.BtnA.wasPressed())
  {
    M5.Lcd.print(("aaaa"));
    delay(1000);
  attachInterrupt(digitalPinToInterrupt(PIN), speedCalc, FALLING);
  }

M5.Lcd.clear();
    
  }</code></pre>
]]></description><link>https://community.m5stack.com/topic/3511/buttons-gps-interrupts-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 23:52:25 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/3511.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 10 Aug 2021 11:07:35 GMT</pubDate><ttl>60</ttl></channel></rss>