I received a reply today but I amĀ not sure how to apply it.Ā The function they quoted is based on the MPU6050 library by jrowberg (I was using the lib by Electronic Cats which is based on the jrowberg library)
The poster was helpful and even posted an example.Ā However I may need to recode the sketch to use the different library.Ā
It may take some work but If it works, hey why not.
The deciding issue will be if the jrowberg library is compatible with the ESP32.Ā I posted a reply and advise what the response is.
Here is the post:
"I am not using an interrupt but am confused when you mentioned "This can be spammed to get the packed when it becomes available""
without interrupts, you will need to manage overflow, and depending upon your sequence manage no data.
This is a simplified summery of what is going on:
do {
if ((fifoC = getFIFOCount()) > length) { // this gets the fifo count and checks to see if we have more than 1 packet
... clean up the extra data and or fix the overflow coruption
}
if (!fifoC) return 0; // Called too early no data or we timed out after FIFO Reset
// We (should) have 1 packet
} while (fifoC != length); // proof our assumption
getFIFOBytes(data, length); //Get 1 packet
return 1;
because we check for a packet here
if (!fifoC) return 0; // Called too early no data or we timed out after FIFO Reset
we return 0 (zero) allowing your code to do something else if you get zero from this function you can just ask it again and again until you get a 1(one) as a return and now you have 1 packet of data loaded ready to process.
I believe you will find this simple.
This function "GetCurrentFIFOPacket" is located in the MPU6050.cpp library you are referencing here.
The latest example code uses it. if you haven't downloaded all the updates and fixed that have occurred on this library you might want to do that first to avoid errors.
Added function to your code you provided above
//BEGIN MPU6050 Code
// Replace with this until you arrive at your code below.
if(mpu.GetCurrentFIFOPacket(fifoBuffer, packetSize) ){// gets the latest packet if available and runs your code else this will skips your code because there is nothing new to process.
// YOUR CODE
// display quaternion values x y z
mpu.dmpGetQuaternion(&q, fifoBuffer);
//USE THIS FOR LIVE ACCEL DATA DISPLAY
Serial.print("G-Force\t");
//Serial.print(q.w);
//Serial.print("\t");
Serial.print(q.x);
Serial.print("\t");
Serial.print(q.y);
Serial.print("\t");
Serial.println(q.z);
//calculate Max Accel X,Y,Z
if (abs(q.x) > abs(MaxGx))
{
MaxGx = q.x;
}
else
{
MaxGx = MaxGx;
}
if (abs(q.y) > abs(MaxGy))
{
MaxGy = q.y;
}
else
{
MaxGy = MaxGy;
}
if (abs(q.z) > abs(MaxGz))
{
MaxGz = q.z;
}
else
{
MaxGz = MaxGz;
}
//Display LIVE ACCEL G data on OLED
//oled.setCursor(0,5);
//oled.clearToEOL();
//oled.println("ACCEL X Y Z");
//oled.setCursor(0,6);
//oled.clearToEOL();
//oled.setCursor(20,6);
//oled.print(q.x,2);
//oled.setCursor(60,6);
//oled.print(q.y,2);
//oled.setCursor(95,6);
//oled.println(q.z,2);
//DISPLAY MAX G on OLED
oled.setCursor(0,5);
oled.println("MaxG X Y Z");
oled.setCursor(0,6);
oled.clearToEOL();
oled.setCursor(20,6);
oled.print(MaxGx);
oled.setCursor(60,6);
oled.print(MaxGy);
oled.setCursor(95,6);
oled.println(MaxGz);
oled.setCursor(0,7);
oled.println ("TEMP = " + String(tempF,1) + " F");
}
Your request was simpler than most so I provided an example