Help a noob out? Logging data from 10DOF to SD data logger on UNO

Hardware:

  • Arduino Uno
  • Adafruit Data Logger SD shield
  • 10DOF sensor

I'm still learning how to code so I suspect the mistake I am making is trivial... I am trying to set up a program so that I can log all of the data (temperature, pressure, altitude, gyro, magnetic force) on the 10DOF sensor... Can anyone tell me what is wrong with my code and give me some guidace? I do no see any data being recorded on my SD card.

#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library
 
 
#include "Wire.h"    // imports the wire library for talking over I2C 
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_BMP085.h>
#include <Adafruit_BMP085_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_10DOF.h>
Adafruit_10DOF mySensor;  // create sensor object called mySensor

 /* Assign a unique ID to the sensors */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_BMP085_Unified       bmp   = Adafruit_BMP085_Unified(18001);
Adafruit_L3GD20_Unified       gyro  = Adafruit_L3GD20_Unified(20);
Adafruit_10DOF                dof   = Adafruit_10DOF();


int chipSelect = 10; //chipSelect pin for the SD card Reader
File mySensorData; //Data object you will write your sesnor data to
 
void setup(){
Serial.begin(115200); //turn on serial monitor
mySensor.begin();   //initialize pressure sensor mySensor Initialise the sensors
accel.begin();
mag.begin();
bmp.begin();
gyro.begin();

pinMode(10, OUTPUT); //Must declare 10 an output and reserve it
SD.begin(4); //Initialize the SD card reader

  sensor_t sensor;
  
  accel.getSensor(&sensor);
  Serial.println(F("----------- ACCELEROMETER ----------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" m/s^2"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" m/s^2"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" m/s^2"));
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));

  gyro.getSensor(&sensor);
  Serial.println(F("------------- GYROSCOPE -----------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" rad/s"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" rad/s"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" rad/s"));
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));
  
  mag.getSensor(&sensor);
  Serial.println(F("----------- MAGNETOMETER -----------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" uT"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" uT"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" uT"));  
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));

  bmp.getSensor(&sensor);
  Serial.println(F("-------- PRESSURE/ALTITUDE ---------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" hPa"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" hPa"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" hPa"));  
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));
  
  delay(500);
}
 
void loop() {

 /* Get a new sensor event */
  sensors_event_t event;

mySensorData = SD.open("TPData.txt", FILE_WRITE);
if (mySensorData) {
  /* Display the results (acceleration is measured in m/s^2) */
  accel.getEvent(&event);
  mySensorData.print(F("ACCEL "));
  mySensorData.print("X: "); mySensorData.print(event.acceleration.x); mySensorData.print("  ");
  mySensorData.print("Y: "); mySensorData.print(event.acceleration.y); mySensorData.print("  ");
  mySensorData.print("Z: "); mySensorData.print(event.acceleration.z); mySensorData.print("  ");mySensorData.println("m/s^2 ");

  /* Display the results (magnetic vector values are in micro-Tesla (uT)) */
  mag.getEvent(&event);
  mySensorData.print(F("MAG   "));
  mySensorData.print("X: "); mySensorData.print(event.magnetic.x); mySensorData.print("  ");
  mySensorData.print("Y: "); mySensorData.print(event.magnetic.y); mySensorData.print("  ");
  mySensorData.print("Z: "); mySensorData.print(event.magnetic.z); mySensorData.print("  ");mySensorData.println("uT");

  /* Display the results (gyrocope values in rad/s) */
  gyro.getEvent(&event);
  mySensorData.print(F("GYRO  "));
  mySensorData.print("X: "); mySensorData.print(event.gyro.x); mySensorData.print("  ");
  mySensorData.print("Y: "); mySensorData.print(event.gyro.y); mySensorData.print("  ");
  mySensorData.print("Z: "); mySensorData.print(event.gyro.z); mySensorData.print("  ");mySensorData.println("rad/s ");  

  /* Display the pressure sensor results (barometric pressure is measure in hPa) */
  bmp.getEvent(&event);
  if (event.pressure)
  {
    /* Display atmospheric pressure in hPa */
    mySensorData.print(F("PRESS "));
    mySensorData.print(event.pressure);
    mySensorData.print(F(" hPa, "));
    /* Display ambient temperature in C */
    float temperature;
    bmp.getTemperature(&temperature);
    mySensorData.print(temperature);
    mySensorData.print(F(" C, "));
    /* Then convert the atmospheric pressure, SLP and temp to altitude    */
    /* Update this next line with the current SLP for better results      */
    float seaLevelPressure = 1011;
    mySensorData.print(bmp.pressureToAltitude(seaLevelPressure,
                                        event.pressure,
                                        temperature)); 
    mySensorData.println(F(" m"));
  }
  
  mySensorData.println(F(""));  


mySensorData.println("");
delay(1000); //Pause between readings.



mySensorData.close();                                  //close the file
}
}

--I'm 95% certain that my problem has nothing to do with the hardware because I ran someone else's code to record temperature & pressure on the BMP180 and everything worked perfectly.

Is the SD card write protected? Is the initialization done correctly?

//SD.begin(4); 
SD.begin(chipSelect);//SD.begin(10);//Initialize the SD card reader

Chip select is correctly set as 10, but you need to call it in SD.begin.