Thank you, Z, for the quick response.
Took me a while to find my way around github but managed to download the needed libraries.
Now I am having trouble with a bunch of compile errors. I copied the code from your email and made some minor changes and commented some things out. Here is the code as it is now:
// filename: Homer_Creutz_code_edited_v00
// date: 20 Aug 2022
// edited by: Hrolf
/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2021 Homer Creutz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
/*
Use with any MPU: MPU6050, MPU6500, MPU9150, MPU9155, MPU9250
Attach the MPU to the I2C buss
Power MPU According to specs of the breakout board. Generic Breakout Version Powers with 5V and has a onboard Voltage regulator.
run the Sketch
*/
#include <Wire.h>
#include <I2Cdev.h>
#include "Simple_MPU6050.h"
#define MPU6050_DEFAULT_ADDRESS 0x68 // address pin low (GND), default for InvenSense evaluation board
Simple_MPU6050 mpu;
//***************************************************************************************
//****************** Print Functions **********************
//***************************************************************************************
//Gyro, Accel and Quaternion
void PrintAllValues(int16_t *gyro, int16_t *accel, int32_t *quat, uint16_t SpamDelay = 100)
// made this void instead of int, Hrolf
{
Quaternion q;
VectorFloat gravity;
float ypr[3] = { 0, 0, 0 };
float xyz[3] = { 0, 0, 0 };
mpu.GetQuaternion(&q, quat);
mpu.GetGravity(&gravity, &q);
mpu.GetYawPitchRoll(ypr, &q, &gravity);
mpu.ConvertToDegrees(ypr, xyz);
Serial.print(F("Yaw ")); Serial.print(xyz[0]); Serial.print(F(", "));
Serial.print(F("Pitch ")); Serial.print(xyz[1]); Serial.print(F(", "));
Serial.print(F("Roll ")); Serial.print(xyz[2]); Serial.print(F(", "));
Serial.print(F("ax ")); Serial.print(accel[0]); Serial.print(F(", "));
Serial.print(F("ay ")); Serial.print(accel[1]); Serial.print(F(", "));
Serial.print(F("az ")); Serial.print(accel[2]); Serial.print(F(", "));
Serial.print(F("gx ")); Serial.print(gyro[0]); Serial.print(F(", "));
Serial.print(F("gy ")); Serial.print(gyro[1]); Serial.print(F(", "));
Serial.print(F("gz ")); Serial.print(gyro[2]); Serial.print(F("\n"));
Serial.println();
return; // added by Hrolf
}
//***************************************************************************************
//****************** Callback Function **********************
//***************************************************************************************
// See mpu.on_FIFO(print_Values); in the Setup Loop
void print_Values (int16_t *gyro, int16_t *accel, int32_t *quat, uint32_t *timestamp)
{
uint8_t Spam_Delay = 100; // Built in Blink without delay timer preventing Serial.print SPAM
PrintAllValues(gyro, accel, quat, Spam_Delay);
}
//***************************************************************************************
//****************** Setup and Loop **********************
//***************************************************************************************
void setup()
{
uint8_t val;
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
//Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties
#ifdef __AVR__
Wire.setTimeout(3000); //timeout value in uSec
#endif
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
// initialize serial communication
Serial.begin(115200);
while (!Serial); // wait for Leonardo enumeration, others continue immediately
Serial.println(F("Start:"));
// Setup the MPU
mpu.Set_DMP_Output_Rate_Hz(10); // Set the DMP output rate from 200Hz to 5 Minutes.
//mpu.Set_DMP_Output_Rate_Seconds(10); // Set the DMP output rate in Seconds
//mpu.Set_DMP_Output_Rate_Minutes(5); // Set the DMP output rate in Minute
mpu.SetAddress(MPU6050_DEFAULT_ADDRESS); //Sets the address of the MPU.
mpu.CalibrateMPU(); // Calibrates the MPU.
mpu.load_DMP_Image(); // Loads the DMP image into the MPU and finish configuration.
mpu.on_FIFO(print_Values); // Set callback function that is triggered when FIFO Data is retrieved
// Setup is complete!
}
void loop()
{
static unsigned long FIFO_DelayTimer;
if ((millis() - FIFO_DelayTimer) >= (99))
{ // 99ms insted of 100ms to start polling the MPU 1ms prior to data arriving.
if ( mpu.dmp_read_fifo(false)) FIFO_DelayTimer = millis() ; // false = no interrupt pin attachment required and When data arrives in the FIFO Buffer reset the timer
}
// dmp_read_fifo(false) does the following
// Tests for Data in the FIFO Buffer
// when it finds data it runs the mpu.on_FIFO(print_Values)
// the print_Values function which we set run the PrintAllValues Function
// When data is captured dmp_read_fifo will return true.
// The print_Values function MUST have the following variables available to attach data
// void print_Values (int16_t *gyro, int16_t *accel, int32_t *quat, uint32_t *timestamp)
// Variables:
// int16_t *gyro for the gyro values to be passed to it (The * tells the function it will be a pointer to the value)
// int16_t *accel for the accel values to be passed to it
// int32_t *quat for the quaternion values to be passed to it
// uint32_t *timestamp which will be the micros()value at the time we retrieved the Newest value from the FIFO Buffer.
}
//I have the embedded DMP firmware set to add a quaternion packet to the FIFO buffer every 100ms this can be adjusted to as little as 5ms but everyone is used to 10ms using Jeff's MPU6050 library.
//mpu.Set_DMP_Output_Rate_Hz(10); // Set the DMP output rate from 200Hz to 5 Minutes.
//if you change this you will need to change the blink without delay routine to almost match
//
//static unsigned long FIFO_DelayTimer;
//if ((millis() - FIFO_DelayTimer) >= (99)) { // 99ms insted of 100ms to start polling the MPU 1ms prior to data arriving.
//if( mpu.dmp_read_fifo(false)) FIFO_DelayTimer= millis() ; // false = no interrupt pin attachment required and When data arrives in the FIFO Buffer reset the timer
//
//you could also just poll the buffer continuously but the i2c consumes a lot of time.
//
//also, note that the dmp_read_fifo function will clear the FIFO buffer and retrieve the next packet if it deems that emptying the buffer will take longer than waiting or if the buffer is likely corrupted and doesn't have a valid packet caused by overflow.
//
//once a packet is retrieved the following occurs:
//because you set this callback function here: mpu.on_FIFO(print_Values); // Set callback function that is triggered when FIFO Data is retrieved
//the print_Values callback function is run once a valid packet is retrieved.
//the callback function is required to have the following values
//void print_Values (int16_t *gyro, int16_t *accel, int32_t *quat, uint32_t *timestamp) {
// //*gyro pointer to the gyro[3] array with 3 values
// //*accel pointer to the accel[3] array with 3 values
// //*quat pointer to the quaterniun[4] array with 4 values
// // timestamp as to when the values were retrieved.
//
// //Put your code here
//}
and here are the compiler errors:
Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
C:\My Elegoo Dir\Homer_Creutz_code_edited_v00\Homer_Creutz_code_edited_v00.ino: In function 'void PrintAllValues(int16_t*, int16_t*, int32_t*, uint16_t)':
C:\My Elegoo Dir\Homer_Creutz_code_edited_v00\Homer_Creutz_code_edited_v00.ino:44:88: warning: unused parameter 'SpamDelay' [-Wunused-parameter]
void PrintAllValues(int16_t *gyro, int16_t *accel, int32_t *quat, uint16_t SpamDelay = 100)
^~~
C:\My Elegoo Dir\Homer_Creutz_code_edited_v00\Homer_Creutz_code_edited_v00.ino: In function 'void print_Values(int16_t*, int16_t*, int32_t*, uint32_t*)':
C:\My Elegoo Dir\Homer_Creutz_code_edited_v00\Homer_Creutz_code_edited_v00.ino:73:76: warning: unused parameter 'timestamp' [-Wunused-parameter]
void print_Values (int16_t *gyro, int16_t *accel, int32_t *quat, uint32_t *timestamp)
^~~~~~~~~
C:\My Elegoo Dir\Homer_Creutz_code_edited_v00\Homer_Creutz_code_edited_v00.ino: In function 'void setup()':
C:\My Elegoo Dir\Homer_Creutz_code_edited_v00\Homer_Creutz_code_edited_v00.ino:85:11: warning: unused variable 'val' [-Wunused-variable]
uint8_t val;
^~~
C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\Simple_MPU6050.cpp: In member function 'int8_t Simple_MPU6050::GetCurrentFIFOPacket(uint8_t*, uint8_t)':
C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\Simple_MPU6050.cpp:208:32: error: 'I2CDEVLIB_WIRE_BUFFER_LENGTH' was not declared in this scope
uint8_t Trash[I2CDEVLIB_WIRE_BUFFER_LENGTH];
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\Simple_MPU6050.h:31:0,
from C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\Simple_MPU6050.cpp:28:
C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\Simple_MPU6050.cpp:215:40: error: 'Trash' was not declared in this scope
FIFO_READ((uint8_t)RemoveBytes, Trash);
^
C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\MPU_ReadMacros.h:304:91: note: in definition of macro 'FIFO_READ'
#define FIFO_READ(PacketLength, Data) MPUi2cReadBytes(0x74, PacketLength, (uint8_t *)Data) // Read/Write command provides Read or Write operation for the FIFO.
^~~~
C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\Simple_MPU6050.cpp: In member function 'Simple_MPU6050& Simple_MPU6050::load_DMP_Image(int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, int8_t)':
C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\Simple_MPU6050.cpp:411:133: warning: unused parameter 'Calibrate' [-Wunused-parameter]
Simple_MPU6050 & Simple_MPU6050::load_DMP_Image(int16_t ax_, int16_t ay_, int16_t az_, int16_t gx_, int16_t gy_, int16_t gz_,int8_t Calibrate) {
^~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\Simple_MPU6050.cpp: In member function 'Simple_MPU6050& Simple_MPU6050::load_firmware(uint16_t, const uint8_t*)':
C:\Program Files (x86)\Arduino\libraries\Simple_MPU6050\Simple_MPU6050.cpp:536:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for ( x = 0; x < this_write; x++ ) firmware_chunk[x] = pgm_read_byte_near(pFirmware + x);
~~^~~~~~~~~~~~
Multiple libraries were found for "Wire.h"
Used: C:\Program
Multiple libraries were found for "I2Cdev.h"
Used: C:\My
Multiple libraries were found for "Simple_MPU6050.h"
Used: C:\Program
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.