Read temperature from Max31855 saving on SD card

I am having problems in reading the from the Max31855 and saving the data to the SD card. It only works in the first cycle, from the second cycle it only saves zeros. Both cards are SPI and I am selectingad the SD card with the pin 10 and the Max31855 with the pin 9.

I also have an I2C LCD and reading the temperature and displaying in it works fine until I try to save to the SD card.

I also have a RTC card (I2C also) and I had success saving the data read from the RTC.

Any help would be appreciate it.

Any help would be appreciate it.

"Hi, my code doesn't work. Help."

Sorry, my crystal ball is at the cleaners. You'll need to actually post your code.

Sorry I did not post any code, I was looking for someone that had a similar problem that is actually related to the adafruit library for the Max31855. I finally was able to work around the issue, the problem is that I tried to use the CLK and MISO pins for both boards the SD breakout board (From adafruit) and the Max31855 (Also from adafruit) but the libraries are not set up to work together so I had to configure independent pins for CLK and MISO for each breakout board.

I was somehow reluctant to publish the code since it is a little lenghty for what is actually doing, the reazon is that I am customizing the Ardublock to add support to more hardware and I had some problems with these modules, so the code is generated by ardublock with some custom block that I put togeteher.

But this is the code generated:

#include <LiquidCrystal_I2C.h>
#include <SD.h>
#include <MAX31855.h>
#include <Wire.h>

double __ardublockThermocoupleReadCelcius()
{
MAX31855 temperature(9, 7, 8);
double tempTC;
tempTC = temperature.readCelsius();
return tempTC;
}

bool __ardublockThermocoupleError()
{
MAX31855 temperature(9, 7, 8);
bool ThermocoupleError = false;
if (temperature.readFaultCode()>0)
{
ThermocoupleError = true;
}
return ThermocoupleError;
}

const int chipSelect = 10;

void __ardublockWriteStringSD (String file_name,String text)
{
char Filename[12];

if (!SD.begin(chipSelect)) {
}
file_name.toCharArray(Filename, 12);
File dataFile = SD.open(Filename, FILE_WRITE);

if (dataFile)
{
dataFile.print(text);
dataFile.close();
}
}

void __ardublockWriteNumberSD (String file_name,double number)
{
char Filename[12];

if (!SD.begin(chipSelect)) {
}

file_name.toCharArray(Filename, 12);
File dataFile = SD.open(Filename, FILE_WRITE);

if (dataFile)
{
dataFile.print(number);
dataFile.close();
}

}

void __ardublockWriteStringSDln (String file_name,String text)
{
char Filename[12];

if (!SD.begin(chipSelect)) {
}
file_name.toCharArray(Filename, 12);
File dataFile = SD.open(Filename, FILE_WRITE);

if (dataFile)
{
dataFile.println(text);
dataFile.close();
}
}

void __ardublockWriteNumberSDln (String file_name,double number)
{
char Filename[12];

if (!SD.begin(chipSelect)) {
}

file_name.toCharArray(Filename, 12);
File dataFile = SD.open(Filename, FILE_WRITE);

if (dataFile)
{
dataFile.println(number);
dataFile.close();
}

}


LiquidCrystal_I2C lcd(39,16,2);


void setup()
{
lcd.init();
}

void loop()
{
lcd.setCursor( 0, 0 );
lcd.print( "Celcius:" );
lcd.print( __ardublockThermocoupleReadCelcius()  );
__ardublockWriteNumberSDln ( "file.txt",__ardublockThermocoupleReadCelcius() );
delay( 1000 );
}

SD.begin() is meant to be called once, not each time you want to deal with a file on the SD card. That function should be called in setup().

I changed the code placing SD.begin() in the setup() function but it did not work.
The only way that it was able to work (With the old posted code or with the SD.begin() in setup()), is defining independent pins for SCLK and and MOSI for each breakout board.