I am trying to collect temperature data from a HiLetgo MAX6675 Module and write it to a HiLetgo 3-01-0038 Micro SD Card Reader. I have duplicated the breadboard setup with second set of components with the same result. The temperature module works until I initialize the SD card reader, then the temperature module does not work. I get the same result if I remove all of the digitalWrite functions. In addition, the chip select pins do not appear to be working the way I thought they should.
#include "max6675.h" // max6675.h library
#include <SD.h>
#include <SPI.h>
int soPin = 12;// SO=Serial Out
int tempcsPin = 10;// CS = chip select CS pin for temp sensor
int sckPin = 13;// SCK = Serial Clock pin
int sdcsPin = 4; // CS pin for SD card
MAX6675 thermocouple(sckPin, tempcsPin, soPin);// create instance object of MAX6675
void setup() {
pinMode(sdcsPin, OUTPUT);
Serial.begin(9600); // initialize serial monitor with 9600 baud
digitalWrite(tempcsPin, HIGH); // This should be LOW but it still works HIGH??
Serial.print("1st Temp Reading = ");
Serial.println(thermocouple.readFahrenheit()); //1st temp reading
digitalWrite(tempcsPin, HIGH); // Take the chip select high to de-select
// SD Card Initialization
if (SD.begin(sdcsPin))
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
}
digitalWrite(sdcsPin, HIGH); // Take the chip select high to de-select
delay(5000);
digitalWrite(tempcsPin, LOW);
Serial.print("2nd Temp Reading = ");
Serial.println(thermocouple.readFahrenheit()); //2nd temp reading
digitalWrite(tempcsPin, HIGH);
// SD Card Initialization a second time works
digitalWrite(sdcsPin, HIGH); // This should be LOW but it still works HIGH??
if (SD.begin(sdcsPin))
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
}
}
void loop() {
// put your main code here, to run repeatedly:
}
This is the output from the serial monitor:
1st Temp Reading = 71.60
SD card is ready to use.
2nd Temp Reading = 32.00
SD card is ready to use.
Any help would be greatly appreciated!