Hi Guys! Of course it cannot log when the card is not present...
But after startup, I insert a SD card. Then something is happening... I really dont know what...
To be more spesific, It seams to arduino freezes...
I want to start logging when "Card detection" is high. When SD card is present...
*********************** Code **********************************************************************************
#include <math.h>
#include <Wire.h>
#include <SD.h>
const int ThermistorValue = 10000; // 10kohm resistor
const int chipSelect = 10; //
const int CD = 9; // Card Detect
int ledPin = 8;
int CDState = 0;
void setup() {
Serial.begin(9600);
pinMode(CD, INPUT);
pinMode(ledPin, OUTPUT);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {Serial.println("Card failed, or not present");}
}
void loop() {
CDState = digitalRead(CD);
int Temp = Thermister(analogRead(0));
if(CDState==1){
digitalWrite(ledPin, LOW);
String dataString = String(Temp);
File dataFile = SD.open("datalog3.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
}
else
{
digitalWrite(ledPin, HIGH);
Serial.println("Initializing SD card...");
}
delay(1000);
}
double Thermister(int RawADC) {
double k;
double c;
k = log(((10240000/RawADC) - ThermistorValue));
k = 1 / (0.001129148 + (0.000234125 * k) + (0.0000000876741 * k * k * k));
c = k - 273.15;
return c;
}
*********************** Code **********************************************************************************