I'm currently trying to run the following code on an ESP32 board from HiLetgo with a MPU6050 gyroscope/accelerometer, and when I print the runtime it's normally around 1-2ms, but occasionally jumps to 124ms.
/* Get tilt angles on X and Y, and rotation angle on Z
* Angles are given in degrees, displays on SSD1306 OLED
*
* License: MIT
*/
#include <Wire.h>
#include <MPU6050_light.h>
MPU6050 mpu(Wire);
unsigned long timer = 0;
void setup() {
Serial.begin(9600); // Ensure serial monitor set to this value also
Wire.begin();
mpu.begin();
mpu.calcGyroOffsets();
}
int past_millis = 0;
void loop() {
mpu.update();
Serial.print(mpu.getAngleX());
Serial.print(",");
Serial.print(mpu.getAngleZ());
Serial.print(",");
Serial.print(millis() - past_millis);
Serial.println();
past_millis = millis();
}
(the third comma separated value is the runtime)
This kind of jumping didn't happen when I tried running the code on an R3 Uno, and I'm fairly certain this has something to do w/ the esp32 board I'm using, as when I unplug the SDA or SCL pins & the gyroscope continues running, then runtime drops down to abt 1 ms, but the jumps up to around 123ms in runtime still remain.
I'm wondering if there's a way I can fix this or not. Any workarounds would be appreciated too.