-
Notifications
You must be signed in to change notification settings - Fork 227
Description
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
- on a SD card.
- 1st PROGRAMMER: CASIMIRO M DEFIGUEIREDO || 2nd PROGRAMMER: MEGAN ROBARDS
- DATE: 03/28/2023
- VERSION 1.0
- NOTICE_______
-
- AMPMETERS have a small variance from 0mA to 185mA (Assume all Read values below 200mA is 0)
*HARDWARE____
- 3x Ampmeter
- 3x Voltmeter
- 1x Gryoscope
- 1x Arduino Nano
- 1x Arduino Nano Breakout board
- 1x Arduino Uno Balloon sheild.
*CONNECTION__
-
- Each Ampmeter requires 5v to Vcc and GND connection
-
- Each Voltmeter requires GND connection
*------------------------ PINOUTS -----------------------------------------------------
- Each Voltmeter requires GND connection
- PIN | CONNECTION
*-------|--------------------- - A0 | Ampmeter(1) Sig
- A1 | Voltmeter(1) Sig
*-------|--------------------- - A2 | Ampmeter(2) Sig
- A3 | Voltmeter(2) Sig
*-------|--------------------- - A4 | Gyroscope X-axis sig
- A5 | Gyroscope Z-axis sig
*-------|--------------------- - A6 | Ampmeter(3) Sig
- A7 | Voltmeter(3) Sig
*/
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// 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;
}
}
};
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GLOBAL_VARIABLE_&_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
- VERSION | 1.0
- DATE | 03/28/23
- DESCRIPTION
- This function reads the amp sensor connected to "pin" and returns the value after calculating the data.
- INPUTS
-
- pin | byte | pin for the ampmeter signal
- RETURNS
-
- float | Amps
*/
float AmpSensor(byte pin){
- float | Amps
//Variables
float Voltage = 0.000;
float Amperage = 0.000;
float RawValue = analogRead(pin);
//MATH
//Serial.print("READ VALUE: "); Serial.println(RawValue, 3);
Voltage = ((RawValue * 5.000) / 1024.000);
//Serial.print("Voltage: "); Serial.println(Voltage, 3);
Amperage = abs((Voltage - ACSoffset) / mVperAmp) - ACSerror;
if(Amperage < 0)
Amperage = 0;
//return
return Amperage;
}
/* Function NAME | VoltSensor
- VERSION | 1.0
- DATE | 03/28/23
- DESCRIPTION
- This function reads the volt sensor connected to "pin" and returns the value after calculating the data.
- INPUTS
-
- pin | byte | pin for the voltmeter signal
- RETURNS
-
- float | Amps
*/
float VoltSensor(byte pin){
- float | Amps
//Variables
float Voltage_out = 0.000;
float Voltage_in = 0.000;
int RawValue = analogRead(pin);
//MATH
Voltage_in = (RawValue * 5.000) / 1024.000;
Voltage_out = Voltage_in / (Resistor_2 / (Resistor_1 + Resistor_2));
//return
return Voltage_out;
}