Unable to read data from a sensor instantiated as a subclass.

Hello Arduino Community,

I am having a problem communicating with an IMU that I am trying to implement in my current project. I am making a bicycle computer that will continuously log data from a variety of sensors over I2C while I ride, and then upload the data to a mobile app via bluetooth at the end of the ride.

/*
 * Main project development file for the 2018 Bike computer project. Creates an object for each sensor that 
 * gives input to the bicycle comptuer. Runs polling functions to import realtime data from all sensors, and
 * makes calculations to format the raw data values into useful statistics as well as react to certain physical
 * conditions. Data is stored in a timestamped text file which awaits upload to a cell phone via bluetooth.
 * 
 * Created by Walker H. Nelson, February 24, 2018
 * Released into the public domain
 */

//All libraries that are necessary for operation are included here
#include <Bike.h>
#include <Wire.h>
#include "SparkFun_BNO080_Arduino_Library.h"
#include <StaticThreadController.h>
#include <Thread.h>
#include <ThreadController.h>


//Create Bike and Sensor Objects
//BNO080 bob;                                     //IMU named Bob (passed into myBike)
Bike myBike("Walker's Bike");               //Bike named Walker's Bike



//Create Thread & Thread Controller Objects
Thread sensThread = Thread();                   //Thread for reading all of the different sensors
Thread logThread = Thread();
Thread ltCtrl = Thread();                       //Thread for controlling the lights and blinkers
ThreadController live = ThreadController();


void setup() {
  // Define Pins & Such
  //Outputs
  pinMode(5,OUTPUT);                //Red LED
  pinMode(9,OUTPUT);                //RGB -- Green
  pinMode(10,OUTPUT);               //RGB -- Blue
  pinMode(11,OUTPUT);               //RGB -- Red
  //Inputs
  pinMode(12,INPUT);                //Right Blinker
  pinMode(13,INPUT);                //Left Blinker


  //Start Serial Connection with the Computer
  Serial.begin(9600);
  Serial.println();
  Serial.println("Welcome to" + myBike.myBikeName);


  //Start I2C Communication with different sensors
  Wire.begin();
  Wire.setClock(400000);
  myBike.myIMU.begin();
  myBike.myIMU.enableRotationVector(100);
  myBike.myIMU.enableAccelerometer(100);


  //Startup Function
  //myBike.beginSensors();


  //Setup Threads & add to controller
  //Enabling sensor thread and adding callback functions
  sensThread.enabled = true;
  sensThread.onRun(sensThreadCallback);
  sensThread.setInterval(100);
  //Enabling logging/printing functions and adding callback functions
  logThread.enabled = true;
  logThread.onRun(logThreadCallback);
  logThread.setInterval(1000);
  //Enabling light-control thread and setting callback functions
  ltCtrl.enabled = false;
  ltCtrl.onRun(ltCtrlCallback);
  ltCtrl.setInterval(100);
  //Adding Threads to their "mode" controller
  live.add(&sensThread);
  live.add(&logThread);
  live.add(&ltCtrl);

}

void loop() {
  //Check the mode of the bicycle computer & start threads based on that
  switch(myBike.checkMode()){
    case 0:
    //if(live.shouldRun())
    live.run();
    break;
    case 1:

    break;
    case 2:

    break;
    }

  //Logging Loop

  //Standby Loop
    //Stop logging all data w/ exception of timestamps
    //Check computer mode

} 

//Uploading Function
    //Probably doesn't have to be a loop. Maybe just a function.
    //Gives file with today's data to cell-phone
    //Receives trip-wide averages from cell-phone


//Workaround to use functions from the myBike object as pseudo-callbacks for String.onRun methods
//Calls the sensor polling function from myBike object
void sensThreadCallback(){
  myBike.pollData();
}
//Calls the light control function from myBike object
void logThreadCallback(){
  myBike.calculate();
  myBike.logData();
}
//Calls the data logging control function from myBike object
void ltCtrlCallback(){
  myBike.myBlinker();
  myBike.myBrakes();
  myBike.myHeadlights();
}

To simplify the main code I have written a library I am calling Bike.h that contains functions for reading sensor data, logging it to an SD, controlling the blinkers etc... The constructor method for the Bike class uses the sensor classes (defined right before the Bike class in the main code) as parameters, and all of the code meant to communicate with these sensors is written into methods of the Bike class (see the Bike.pollData() function in Bike.cpp).

//This function gets all of the data from the different sensors 
void Bike::pollData(){
 //IMU
 //Retrieves quaternions from IMU (dimensionless)
    q0 = Bike::myIMU.getQuatReal();
 q1 = myIMU.getQuatI();
    q2 = myIMU.getQuatJ();
 q3 = myIMU.getQuatK();
    //Get Accelerometer Data from IMU (m/s^2)
    a_x = myIMU.getAccelX();
    a_y = myIMU.getAccelY();
    a_z = myIMU.getAccelZ();
 //Serial Debugging for IMU
 Serial.print(myIMU.getQuatReal(),2);
 Serial.print(" ");
 Serial.print(q1,2);
 Serial.print(" ");
 Serial.print(q2,2);
 Serial.print(" ");
 Serial.print(q3,2);
 Serial.print(" ");
 Serial.println("Data Polled");
 //Atmospheric Sensor
}

I believe I am instantiating all of the objects properly but when I read data from my IMU (Sparkfun BNO080) I am getting only zeros back every time I poll. I have had the IMU working in other sketches so I can verify that it is working properly. The library I have written also compiles properly and the Bike class methods will run on my board to the desired effect with the exception of getting good data from the IMU. I am thinking it must have something to do with the way I am passing the IMU object into the Bike object but I'm not sure what it could be; I have tried changing where/how this is done several times but can't change the outcome. Any help would be appreciated with troubleshooting this problem, thanks a bunch everyone.

Also the board I am using is an Adafruit Feather M0 Bluefruit LE

~Walker

Main_Bike_Computer.ino (3.61 KB)

You've not post ALL of your code or any of your serial output. So, it would appear that you just wanted to vent.

Hopefully, venting was enough.