Hello forum, this is my first post on a forum in quite some time. Usually Google helps me through all of my problems but this one has me whooped, and I am too new to Arduino to properly troubleshoot by myself. My issues is as follows:
Arduino Mega 2560
Adafruit GPS v3 Breakout
MPU 9250 9DoF
If I run my IMU, I can get YPR data. If I run my GPS, I can get lat/lon/alt data. I cannot however run them both at the same time. I have to either power off my IMU or disconnect the TX from the GPS. I have ruled out power consumption by using external power supplies, and the code works with whatever device is currently connected. As soon as I connect the serial from the GPS with the IMU running, the YPR starts to jump all over the place, and after about 10 seconds or so, shuts the program down and everything stops scrolling on the serial monitor. I have tried multiple serial ports, and even AltSoftSerial, so excuse the excessive serial.begins!
I am assuming I have some kind of memory issue, and I am overloading it with both the IMU and GPS
Example outputs (steady) with IMU running:
Pose: roll:-0.54 pitch:-0.45 yaw:63.85
Connect GPS:
Pose: roll:-0.50 pitch:-0.43 yaw:64.12
Pose: roll:-0.52 pitch:-0.41 yaw:63.87
Pose: roll:-8.09 pitch:-8.14 yaw:66.01
Pose: roll:-6.17 pitch:-6.21 yaw:65.65
Pose: roll:-4.88 pitch:-4.83 yaw:65.43
*stopped scrolling and TX light on Arduino stops flashing
Code:
#include <Wire.h>
#include "I2Cdev.h"
#include "RTIMUSettings.h"
#include "RTIMU.h"
#include "RTFusionRTQF.h"
#include "CalLib.h"
#include <EEPROM.h>
#include <TinyGPS.h>
#include "AltSoftSerial.h"
TinyGPS gps;
void getgps(TinyGPS &gps);
RTIMU *imu; // the IMU object
RTFusionRTQF fusion; // the fusion object
RTIMUSettings settings; // the settings object
// DISPLAY_INTERVAL sets the rate at which results are displayed
#define DISPLAY_INTERVAL 150 // interval between pose displays
// SERIAL_PORT_SPEED defines the speed to use for the debug serial port
#define SERIAL_PORT_SPEED 115200
AltSoftSerial altSerial;
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
unsigned long lastDisplay;
unsigned long lastRate;
int sampleCount;
void setup()
{
int errcode;
Serial.begin(SERIAL_PORT_SPEED);
Serial2.begin(9600);
Serial3.begin(4800);
altSerial.begin(9600);
Wire.begin();
imu = RTIMU::createIMU(&settings); // create the imu object
Serial.print("ArduinoIMU starting using device "); Serial.println(imu->IMUName());
if ((errcode = imu->IMUInit()) < 0) {
Serial.print("Failed to init IMU: "); Serial.println(errcode);
}
if (imu->getCalibrationValid())
Serial.println("Using compass calibration");
else
Serial.println("No valid compass calibration data");
lastDisplay = lastRate = millis();
sampleCount = 0;
// Slerp power controls the fusion and can be between 0 and 1
// 0 means that only gyros are used, 1 means that only accels/compass are used
// In-between gives the fusion mix.
fusion.setSlerpPower(0.02);
// use of sensors in the fusion algorithm can be controlled here
// change any of these to false to disable that sensor
fusion.setGyroEnable(true);
fusion.setAccelEnable(true);
fusion.setCompassEnable(true);
}
void loop()
{
unsigned long now = millis();
unsigned long delta;
int loopCount = 1;
while (imu->IMURead()) { // get the latest data if ready yet
// this flushes remaining data in case we are falling behind
if (++loopCount >= 10)
continue;
fusion.newIMUData(imu->getGyro(), imu->getAccel(), imu->getCompass(), imu->getTimestamp());
sampleCount++;
if ((delta = now - lastRate) >= 1000)
{
Serial.print("Sample rate: "); Serial.print(sampleCount);
if (imu->IMUGyroBiasValid())
Serial.println(", gyro bias valid");
else
Serial.println(", calculating gyro bias");
sampleCount = 0;
lastRate = now;
}
if ((now - lastDisplay) >= DISPLAY_INTERVAL)
{
lastDisplay = now;
// RTMath::display("Gyro:", (RTVector3&)imu->getGyro()); // gyro data
// RTMath::display("Accel:", (RTVector3&)imu->getAccel()); // accel data
// RTMath::display("Mag:", (RTVector3&)imu->getCompass()); // compass data
RTMath::displayRollPitchYaw("Pose:", (RTVector3&)fusion.getFusionPose()); // fused output
Serial.println();
}
}
// if (Serial1.available())
// {
// int c = Serial1.read();
// Serial2.write(c);
// }
}