Logging 9axis IMU data to Micro SD card

tinyvino

  • Newbie
  • *
    • Posts: 3
    • View Profile
Hi All,

I'm not a complete arduino noob, but not far off, so forgive me if I'm making a stupid error here.

I have the TinyDuino 9axis IMU shield and Micro SD shield, and would like to log the data from the IMU to a Micro SD card.

The problem I'm having is that the 9axis IMU library seems to assume that data will be output on Serial.print. I need to output on dataFile.print to go to a MicroSD. I have tried modifying the library files a bit, but without too much success. I end up chasing my tail.

Basically, I want a combination between the Arduino 'Datalogger' example and the "TinyShield_9_Axis" example.

Thing is, these lines in "TinyShield_9_Axis" are just outputting on serial:

RTMath::display("Gyro:", (RTVector3&)imu->getGyro());                // gyro data
RTMath::display("Accel:", (RTVector3&)imu->getAccel());              // accel data
RTMath::display("Mag:", (RTVector3&)imu->getCompass());              // compass data

It seems when you trace these back to RTMath.cpp, they refer to

void RTMath::display(const char *label, RTVector3& vec)
{
   Serial.print(label);
   Serial.print(" x:"); Serial.print(vec.x());
   Serial.print(" y:"); Serial.print(vec.y());
   Serial.print(" z:"); Serial.print(vec.z());
}


I have tried modifying RTMath.cpp and changing Serial.print to dataFile.print, but of course it then requires SD.h which it doesn't see.

Can anyone help me here? I may well be going about this completely the wrong way.

Has anyone successfully written 9axis shield data to a MicroSD?

Many thanks
tinyvino
« Last Edit: November 05, 2015, 02:34:52 PM by tinyvino »


Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 357
    • View Profile
Hi- you can leave the library as it is. It's a bit tricky to figure out, but in your main loop you can have:

Code: [Select]


#include "I2Cdev.h"
#include "RTIMUSettings.h"
#include "RTIMU.h"
#include "RTFusionRTQF.h"
#include "CalLib.h"
#include <EEPROM.h>

RTIMU *imu;                                           // the IMU object
RTFusionRTQF fusion;                                  // the fusion object
RTIMUSettings settings;                               // the settings object

void setup()
{
  Wire.begin();
  imu = RTIMU::createIMU(&settings);
  imu->IMUInit();
  fusion.setGyroEnable(true);
  fusion.setAccelEnable(true);
  //fusion.setCompassEnable(true);
 
}

int currentXdata=0;
int currentYdata=0;

void loop()
{
  if (imu->IMURead()) {                                // get the latest data if ready yet
    fusion.newIMUData(imu->getGyro(), imu->getAccel(), imu->getCompass(), imu->getTimestamp());
    currentXdata=fusion.getFusionPose().x()* RTMATH_RAD_TO_DEGREE;
    currentYdata=fusion.getFusionPose().y()* RTMATH_RAD_TO_DEGREE;
  }
  //do stuff with currentXdata and currentYdata
}



You might want the data as floats etc, but this should get you closer to accessing the data in a way that you can easily save to the SD card using the standard libraries.


 

SMF spam blocked by CleanTalk