Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m5.update+attachInterrupt causes bootloop #49

Open
kamilbar99 opened this issue Aug 5, 2021 · 0 comments
Open

m5.update+attachInterrupt causes bootloop #49

kamilbar99 opened this issue Aug 5, 2021 · 0 comments

Comments

@kamilbar99
Copy link

I'm creating gps +speed meter device and i want to use buttons to change things on display. When button is clicked device get into bootloop and only thing I can do is reset device. Is there any possibility that interrupts will work with buttons or should i measure speed without interrupts?
Here is my code:


#include <M5Core2.h>
#include <TinyGPS++.h>

#define PIN 21
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

// A sample NMEA stream.
const char *gpsStream =
  "$GPRMC,045103.000,A,3014.1984,N,09749.2872,W,0.67,161.46,030913,,,A*7C\r\n";

// The TinyGPS++ object
TinyGPSPlus gps;
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (Serial2.available() > 0)
      gps.encode(Serial2.read());
  } while (millis() - start < 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("Speed sensor: "));

  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)>100) // 100 millisec debounce
    {
    //calculate elapsed
    elapsed=millis()-start;

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

    }

}

void setup()
{
M5.begin(true,true,true,false);
Serial2.begin(9600, SERIAL_8N1, 13, 14);
attachInterrupt(digitalPinToInterrupt(PIN), speedCalc, FALLING);
start=millis();
}

void loop()
{
  M5.update();
  if(M5.BtnC.wasPressed())
  {
    M5.Lcd.print(F("Change"));
  }
smartDelay(1000);
displayInfo();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant