sparkfun / OpenLog

Open Source Hardware Datalogger
https://www.sparkfun.com/products/9530
Other
553 stars 216 forks source link

OpenLog SD sparkfun. Code presenting on serial monitor but nothing writes to the SD card. #252

Open megamind56 opened 1 year ago

megamind56 commented 1 year ago

New to openLog SD. I am building a payload that has three generators each hooked up to a current and voltage sensor. Everything displays perfect on the serial monitor but when I take my 16 GB micro SD card out of the OpenLog it has nothing on it. The LEDs on the openlog work so I'm thinking something is wrong with my code. PLEASE HELP!

/* This program is Designed for High-Atmosphere Bolloon. This program reads data from three generators(motors) and Gyroscope store it temparaley before saving the data to a .txt

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // INCLUDES_&_DEFINE //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Ampmeters pins

define Amp1 A0

define Amp2 A2

define Amp3 A6

//Voltmeter pins

define Volt1 A1

define Volt2 A3

define Volt3 A7

//Gyroscope pins

define Gyro_X A4

define Gyro_Z A5

//SENSOR VALUES

define mVperAmp 0.180

define ACSoffset 2.500

define ACSerror 0.150

define Resistor_1 30000.000

define Resistor_2 7500.000

//Change Values

define NumGens 3

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // CLASS & STRUCT //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

class mData {

protected: float amp; float volt;

public: mData(){ amp = 0.000; volt = 0.000; }

float AMP(){ return amp; } void AMP(float a){ amp = a; } float VOLT(){ return volt; } void VOLT(float v){ volt = v; } float Watt(){ return amp * volt; } };

class Time {

private: int Hours; int Min; int Sec; int mill;

public: Time() { Hours = 0; Min = 0; Sec = 0; mill = 0;
} int HOUR() { return Hours;
} int MINUTES() { return Min; } int SECOUNDS() { return Sec; } int MILLISECONDS() { return mill;
} void ReadTime(){ long temp = millis(); Sec = temp / 1000; Min = temp / 60000; Hours = temp/ 3600000;
while(temp >= 1000) { temp -= 1000;
} mill = temp; while(Sec >= 60) { Sec -= 60;
} while(Min >= 60) { Min -= 60; } }

};

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // GLOBALVARIABLE&_FUNCTIONS //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//FUNCTIONS float AmpSensor(byte); // float VoltSensor(byte);

//GLOBALS //Data handling mData Data[NumGens]; mData High = mData(); Time time = Time();

// Accelerometer X
int accelX; float accelXVolt; float accelXG;

// Accelerometer Z int accelZ; float accelZVolt; float accelZG;

//ports byte Ammeters[] = {Amp1, Amp2, Amp3}; byte Voltmeters[] = {Volt1, Volt2, Volt3};

// unsigned int SampleSet = 1;

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // MAIN_PROGRAM //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

void setup() { Serial.begin(9600);

for(byte i = 0; i < 1; i++) Data[i] = mData();

}

void loop() { Serial.print(" Sample Set: "); Serial.print(SampleSet); Serial.println(" "); for (byte s = 0; s < 10; s++) {

Serial.print("-------------------------NEW SAMPLE "); Serial.print(s); Serial.println("-----------------------------");
//READ Generators
for (int i = 0; i < NumGens; i++) {
  //Serial.print("aPort: ");
  //Serial.println(Ammeters[i]);
  //Serial.print("vPort: ");
  //Serial.println(Voltmeters[i]);
  //Ammeter
  Data[i].AMP(AmpSensor(Ammeters[i]));
  //Voltmeter
  Data[i].VOLT(VoltSensor(Voltmeters[i]));
  if (Data[i].VOLT() > High.VOLT())
    High.VOLT(Data[i].VOLT());
  if (Data[i].AMP() > High.AMP())
    High.AMP(Data[i].AMP());
  Serial.print("**HIGHEST VOLT**  ");
  Serial.println(High.VOLT(), 3);
  Serial.print("**HIGHESt AMP **  ");
  Serial.println(High.AMP(), 3);
}

//Read Accelarometer
accelX = analogRead(A4);
accelXVolt = accelX * (5.0 / 1023);
accelXG = (accelXVolt - (3.3 / 2)) / (0.330);

accelZ = analogRead(A5);
accelZVolt = accelZ * (5.0 / 1023);
accelZG = (accelZVolt - (3.3 / 2)) / (0.330);

//Read Time
time.ReadTime();

//Print Time
Serial.print("--------------------");
Serial.print("Time (Hr:Min:Sec.MS): ");
Serial.print(time.HOUR());
Serial.print(":");
Serial.print(time.MINUTES());
Serial.print(":");
Serial.print(time.SECOUNDS());
Serial.print(".");
Serial.println(time.MILLISECONDS());

//Print Data
for (byte i = 0; i < NumGens; i++) {
  Serial.print("* Motor ");
  Serial.print(i + 1);
  Serial.println(" *");
  delay(10);
  Serial.print("Volt: ");
  Serial.println(Data[i].VOLT(), 3);
  delay(10);
  Serial.print("Amp: ");
  Serial.println(Data[i].AMP(), 3);
  delay(10);
  Serial.print("Watt: ");
  Serial.println(Data[i].Watt(), 3);
  delay(10);
}
Serial.print("Accel X-axis: ");
Serial.println(accelXG, 3);
Serial.print("Accel Z-axis: ");
Serial.println(accelZG, 3);

delay(1000);

} Serial.println(); SampleSet++; delay(14000); }

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // FUNCTIONS //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/* Function NAME | AmpSensor

/* Function NAME | VoltSensor