SPI - Pro Trinket 5V + SSD1306 + 2x MAX31855 + MicroSD (all Adafruit) = [Workin]

All,

so i'm working to take two thermocouple inputs (process temps), then datalog to SD. All modules are working over SPI, and the OLED+MAX's work alone, and the OLED+SD works alone. The combined program below doesn't open the SD file and save (it does update the thermocouple temps each loop).

I've heard that the SD library doesn't play well with other SPI modules, but can't figure out what to do about it or what other options i have. I tried the SdFat library, but i can't get an examply to work, or figure out how to re-mold my code to do the same thing (can't find any guides anywhere either).

Does anyone have any ideas on how i can get these modules to work together?

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_MAX31855.h>
#include <SD.h>

const int SD1CS = 10;

File kerfLog;

// Thermocouple(s) hardware SPI
const int TC1CS = 4;
const int TC2CS = 3;
Adafruit_MAX31855 TC1(TC1CS);
Adafruit_MAX31855 TC2(TC2CS);

// OLED(s) hardware SPI
const int OLED1DC = 6;
const int OLED1CS = 5;
const int OLED1RESET = 8;
Adafruit_SSD1306 display(OLED1DC, OLED1RESET, OLED1CS);

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

double c1 = 0;
double c2 = 0;
double c3 = 0;
double c4 = 0;

void setup() {
  Serial.begin(9600);

  display.begin(SSD1306_SWITCHCAPVCC);

  display.setRotation(2);
  
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(5,10);
  display.print("Initialize");
  display.display();

  pinMode(SD1CS, OUTPUT);
  
  SD.begin(SD1CS);
  
  kerfLog = SD.open("log.txt", FILE_WRITE);
  
  delay(2000);
  
}

void loop() {
  
  c1 = TC1.readCelsius();
  c2 = TC2.readCelsius();
  c3 = TC1.readInternal();
  c4 = TC2.readInternal();

  display.clearDisplay();
  display.setCursor(21,0);
  display.print("RM");
  display.setCursor(78,0);
  display.print("H2O");
  display.drawLine(8,15,57,15,WHITE);
  display.drawLine(70,15,119,15,WHITE);
  
   if (isnan(c3)) {
     display.setCursor(13,18);
     display.print("Err");
   } else {
     display.setCursor(10,18);
     display.print(c3,1);
   }
   
   if (isnan(c4)) {
     display.setCursor(75,18);
     display.print("Err");
   } else {
     display.setCursor(72,18);
     display.print(c4,1);
   }
   
   display.display(); 

   String data = "";

   data += c1;
   data += ",";
   data += c2;
   data += ",";
   data += c3;
   data += ",";
   data += c4;
  
  // if the file opened okay, write to it:
  if (! kerfLog) {
    // if the file didn't open, print an error:
    display.drawPixel(126,30,WHITE);
    display.display();
  } else {
    kerfLog.println(data);
    // save the file:
    kerfLog.flush();
    display.drawPixel(126,2,WHITE);
    display.display();
  }

  delay(1000);
  

}

jk.

after DAYS of working on this, was reading up on the files in SdFat, and if one replaces:

#include <SD.h>

with

#include <SdFat.h>
SdFat SD;

.... it works.