Hi.
I am building a temperature datalogger based on 5 type k thermocouples. They are all both amplified and filtered. I am trying to log the data on my sd card using a 2GB Kingston sd. I am using Arduino Mega 2560 R3.
The problem is when i run my code it is only logging 3-7 dataseries. And then i crashes.
(I have no problems with reading data directly from the arduino and writing it to the com port without using my SD card).
Any one know what causes this problem when using my SD card.
This is my code: (note that i am only using 2 of the 5 thermocouples in this example)
#include <SD.h>
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 53;
//Defines Analog inputs
int sensorPin = A0;
int sensorPin2 = A1;
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...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(53, OUTPUT);
// 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.");
}
void loop()
{
File logFile = SD.open("LOG.csv", FILE_WRITE);
{
//Exhaust Temperature
int Thermo1 = analogRead(sensorPin);
//Intake Temperature
int Thermo2 = analogRead(sensorPin2);
//Create Data string for storing to SD card
if (logFile)
{
logFile.print(Thermo1);
logFile.print(",");
logFile.println(Thermo2);
logFile.close();
Serial.print(Thermo1);
Serial.print(",");
Serial.println(Thermo2);
}
else
{
Serial.println("Couldn't open log file");
}
delay(1000);
}
}
I hope you can help me ![]()