Howdy Guys.
I've got some issues with a project I'm working on. I'm using a Due with a MAX31855 thermocouple reader, along with an SD card (both SPI). The issue I'm having is that I can't get both to work at the same time. By changing the code a little, I can get the SD to work, but then the MAX31855 doesn't seem to be sending any info. Then if I change it a bit to get the MAX31855 to work as it should, the SD card stops working. My code is pretty long and split up between a lot of functions, but I was able to replicate the problem with this simpler sketch.
(MAX31855 Library MAX31855 library - Libraries - Arduino Forum)
/*
SD card datalogger
This example shows how to log data from three analog sensors
to an SD card using the SD library.
The circuit:
* analog sensors on analog ins 0, 1, and 2
* SD card attached to SPI bus as follows:
SD Chip select pin is 53
MAX31855 Chip select pin is 22
created 24 Nov 2010
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include "MAX31855.h"
#include <SPI.h>
#include <SD.h>
//for the CD4051
#define CDA 14
#define CDB 15
#define CDC 16
// 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.
MAX31855 tc(SCK, 22, MISO);
const int SDchipSelect = 53;
void setup()
{
pinMode(CDA, OUTPUT);
pinMode(CDB, OUTPUT);
pinMode(CDC, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
delay(50);
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);
delay(50);
// see if the card is present and can be initialized:
if (!SD.begin(SDchipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
delay(50);
tc.begin();
delay(50);
}
void loop()
{
// make a string for assembling the data to log:
String dataString = "";
delay(50);
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
delay(50);
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
delay(50);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
delay(50);
digitalWrite(CDA, HIGH);
digitalWrite(CDB, LOW);
digitalWrite(CDC, HIGH);
delay(50);
Serial.print("Start max31855_demo4: ");
Serial.println(MAX31855_VERSION);
Serial.println();
delay(50);
uint32_t start = micros();
for (int i=0; i< 10; i++) tc.read();
uint32_t stop = micros();
Serial.print("10x read:\t");
Serial.println(stop - start);
delay(50);
start = micros();
float t1 = tc.getTemperature();
stop = micros();
Serial.print("getTemperature:\t");
Serial.println(stop - start);
Serial.println(t1, 2);
Serial.println();
delay(50);
start = micros();
tc.setOffset(2.0);
stop = micros();
Serial.print("setOffset:\t");
Serial.println(stop - start);
delay(50);
tc.read();
start = micros();
t1 = tc.getTemperature();
stop = micros();
Serial.print("getTemperature:\t");
Serial.println(stop - start);
Serial.println(t1, 2);
Serial.println();
delay(50);
start = micros();
float t2 = tc.getInternal();
stop = micros();
Serial.print("getInternal:\t");
Serial.println(stop - start);
Serial.println(t2, 4);
Serial.println();
delay(10000);
}
I get this in the serial monitor (SD card not working)
But, if you put the "tc.begin();" from the bottom of the "void setup()" to the top, then you get this (MAX31855 not working).
the delays in the code were just thrown in there to see if that would fix it.
I don't think it's my powersupply, I've got two separate regulators powering each item.
Any help would be great, thanks!