Translating .TXT file data from sparkfun 9DOF Sensor Stick

Hi all,

I am a beginner to this, so please bare with me. I have been reading other posts regarding what I am going to ask, but I just can’t simply seem to get it clear(the reason why I am asking this question).

I NEED DESPERATE HELP WITH TRANSLATING THE DATA I GET WRITTEN ONTO MY micro-SD card while running the attached 9DOF SENSOR STICK all stacked up on my ARDUINO UNO. The most critical part is the ACCELEROMETER measurements. I am trying to calculate the g-force a driver experiences while riding a go-kart, so I believe I need the acceleration data written on the sd card from the test run. MY QUESTIONS: So which set of numbers includes ACCELEROMETER DATA?(I believe it’s the first 3 numbers) and, What are the units of the ACCELEROMETER data that is being printed? (I happen to think its in m/s^2) :? :pray:

below is my .TXT file:

http://i124.photobucket.com/albums/p34/ … ot%204.png

Thank you

David G.

PLEASE TAKE IT EASY ON ME, I am REALLY NEW at this stuff.

I even had to look up how to post a picture. :doh:

HERE IS THE CODE I USED…

I FIGURED EVERYTHING OUT EXCEPT FOR, WHAT MEASUREMENT(UNITS) IS THE ACCELEROMETER DATA IN? AND ALSO THE GYROSCOPE DATA?

PLEASE HELP,

DAVID

#include <SPI.h>
#include <SD.h>

const int chipSelect = 8;
double sensorvalues[9];
#include <Wire.h>


//// Code for Sensor Stick ////
///////////////////////////////
union XYZBuffer {struct {short x,y,z;} value; byte buff[6];};
void changeEndian(union XYZBuffer*xyz){for(int i=0;i<6;i+=2){byte t=xyz->buff[i];xyz->buff[i]=xyz->buff[i+1];xyz->buff[i+1]=t;}}
void readXYZ(int device,union XYZBuffer*xyz){Wire.requestFrom(device,6);long start=millis();while(!Wire.available()&&(millis()-start)<100);if(millis()-start<100){for(int i=0;i<6;i++)xyz->buff[i]=Wire.read();}}
void setupAccel(int device){Wire.beginTransmission(device);Wire.write(0x00);Wire.endTransmission();Wire.requestFrom(device,1);while(!Wire.available());byte ch=Wire.read();Wire.beginTransmission(device);Wire.write(0x2d);Wire.write(0x08);Wire.endTransmission();Wire.beginTransmission(device);Wire.write(0x38);Wire.write(0x84);Wire.endTransmission();}
void readAccel(int device,union XYZBuffer*xyz){Wire.beginTransmission(device);Wire.write(0x32);Wire.endTransmission();readXYZ(device,xyz);}
void setupCompass(int device){Wire.beginTransmission(device);Wire.write(10);Wire.endTransmission();Wire.requestFrom(device,2);while(!Wire.available());char ch=Wire.read();Serial.print(ch);ch=Wire.read();Serial.println(ch);Wire.beginTransmission(device);Wire.write(0x00);Wire.write(0x70);
Wire.endTransmission();Wire.beginTransmission(device);Wire.write(0x01);Wire.write(0xA0);Wire.endTransmission();Wire.beginTransmission(device);Wire.write(0x02);Wire.write(0x00);Wire.endTransmission();delay(6);}
void readCompass(int device,union XYZBuffer*xyz){readXYZ(device,xyz);changeEndian(xyz);Wire.beginTransmission(device);Wire.write(0x03);Wire.endTransmission();}
void setupGyro(int device){Wire.beginTransmission(device);Wire.write(0x00);Wire.endTransmission();Wire.requestFrom(device,1);while(!Wire.available());byte ch=Wire.read();}
void readGyro(int device,union XYZBuffer*xyz){Wire.beginTransmission(device);Wire.write(0x1d);Wire.endTransmission();readXYZ(device,xyz);changeEndian(xyz);}
void output(union XYZBuffer xyz){Serial.print(xyz.value.x);Serial.print(",");Serial.print(xyz.value.y);Serial.print(",");Serial.print(xyz.value.z);}
///////////////////////////////
///////////////////////////////

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  // set up the sensor
  Wire.begin();
  setupCompass(0x1e);
  setupAccel(0x53);
  setupGyro(0x68);

}
void loop()
{
  union XYZBuffer compass,gyro,accel;

    readAccel(0x53,&accel);
    readGyro(0x68,&gyro);
    readCompass(0x1e,&compass);
    sensorvalues[0] = accel.value.x;
    sensorvalues[1] = accel.value.y;
    sensorvalues[2] = accel.value.z;
    sensorvalues[3] = gyro.value.x;
    sensorvalues[4] = gyro.value.y;
    sensorvalues[5] = gyro.value.z;
    sensorvalues[6] = compass.value.x;
    sensorvalues[7] = compass.value.y;
    sensorvalues[8] = compass.value.z;
    Write_Values();
    delay(100);

}


void Write_Values(){

  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int i = 0; i< 9; i++) {
    int sensor = sensorvalues[i];
    dataString += String(sensor);
    if (i < 8) {
      dataString += ",";
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}

The data sheet for the sensor gives the units of the measurement, and a conversion factor which you should multiply or divide to get g values (for the accelerometer). Familiarize yourself with it!

To test the conversion, set the sensor still on the table. It will be reporting 1 g in the vertical direction.

From the begining of the loop function:

sensorvalues[0] = accel.value.x;
    sensorvalues[1] = accel.value.y;
    sensorvalues[2] = accel.value.z;
    sensorvalues[3] = gyro.value.x;
    sensorvalues[4] = gyro.value.y;
    sensorvalues[5] = gyro.value.z;
    sensorvalues[6] = compass.value.x;
    sensorvalues[7] = compass.value.y;
    sensorvalues[8] = compass.value.z;

Seems pretty clear to me.

[EDIT] Missed the part about the units. What jremmington said!.

P.S. Full capitalized words or sentences are interpeted by many people on the internet as shouting. Please do not do that. There is no need to put emphasis on what you wrote. Monitors these days are have sharp enough quality to read it.