Buttons+gps+interrupts problem
-
Hello I have a problem while using gps module(M003) interrupts and buttons on Core 2
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)
For interrupt i use hall sensor connected to pin 21
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.
Here is my code :#include <M5Core2.h> #include <TinyGPS++.h> #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() > 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("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)>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(); }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login