I want to log data reading from thermocouple to SD card. As thermocouple and SD both run on SPI connection I tried making one SS pin HIGH and other LOW but I am encounter an issue that when I include SD.begin(); the thermocouple stops giving out reading. Does anyone know how to fix this problem.
#include <SPI.h>
#include <SD.h>
#define cardSelect 4
#include "max6675.h"
File logFile;
char fileName[] = "00THERMO00.csv";
int thermoDO = 14;
int thermoCS = 16;
int thermoCLK = 15;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
void setup() {
Serial.begin(9600);
digitalWrite(thermoCS,HIGH);
digitalWrite(cardSelect,HIGH);
SD.begin(cardSelect);
while (SD.exists(fileName)) {
if (fileName[1] != '9') {
fileName[1]++;
}
else if (fileName[0] != '9') {
fileName[1] = '0';
fileName[0]++;
}
}
}
void loop() {
// basic readout test, just print the current temp
digitalWrite(thermoCS, LOW);
digitalWrite(cardSelect,HIGH);
Serial.print("C = ");
digitalRead(thermocouple.readCelsius());
Serial.println(thermocouple.readCelsius());
digitalWrite(thermoCS, HIGH);
digitalWrite(cardSelect,LOW);
File logFile = SD.open(fileName, FILE_WRITE);
logFile.print("C=");
logFile.println(thermocouple.readCelsius());
logFile.close();
// For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
delay(1000);
}