communication error between max31855 and TFT featherwing

Hello Support,

I am kind of looking for an answer, how to tackle a SPI problem.
I am using a MAX31855, and a Featherwing 3.5 inch. and both components work if one of the programs is not active in the arduino software.

I am looking for an answer how to access the SPI bus over SPI.h how to say to the first device, do 10 samples and send them over to the display and then run the Display.

if the max31855 initiliaser is set in the void setup before the TFT.begin the Thermocouple doesnt work, if I set it behind the TFT.begin() the TFT screen doesnt work.

please help.

here is the example code, which works and has been tested thoroughly.

/***************************************************
  This is an example for the Adafruit Thermocouple Sensor w/MAX31855K

  Designed specifically to work with the Adafruit Thermocouple Sensor
  ----> https://www.adafruit.com/products/269

  These displays use SPI to communicate, 3 pins are required to
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <SPI.h>
#include "Adafruit_MAX31855.h"
#include "HX8357_t3n.h"
//#include <FlickerFreePrint.h>// library to draw w/o flicker
#include <math.h>
#include <stdio.h>
#include <elapsedMillis.h>
#include <ButtonEvents.h>
#include <ADC.h>
#include <Encoder.h>
#include <PID_v1.h>


// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define C_BLACK      0x0000
#define C_BLUE        0x001F
#define C_RED         0xF800
#define C_GREEN       0x07E0
#define C_CYAN        0x07FF
#define C_MAGENTA     0xF81F
#define C_YELLOW      0xFFE0
#define C_WHITE       0xFFFF


#define TFT_CS     10
#define TFT_RST    -1
#define TFT_DC      9
#define MAXMISO    12
#define MAXCLK     13 //max31855 nothing else.

#define MAX31855_1 14
#define MAX31855_2 15
#define MAX31855_3 16
#define MAX31855_4 17

SPISettings settingsTFT(25000000, MSBFIRST, SPI_MODE3);
SPISettings SettingsA(5000000, MSBFIRST, SPI_MODE0);

// initialize the Thermocouple
Adafruit_MAX31855 TH1(MAXCLK, MAX31855_1, MAXMISO);

//constructors for TFT without flickering
HX8357_t3n tft = HX8357_t3n(TFT_CS, TFT_DC, TFT_RST);

//flickerfree variables:
float j;
unsigned long StartTime, EndTime;
char str[30];
unsigned long endmicros;  //speed check variables
unsigned long currentmicros;

//arrays for the temperature
double TC1[12];
double *pArray_From_TC;
double  pArray_Screen;


//Intervals execution of the various functions
//TFT update:
unsigned long ScreenpreviousMillis = 0;
unsigned long ScreenInterval = 100;//used
//Thermocouple Function update
unsigned long TC_previousMillis = 0;
unsigned long TC_Interval = 1000;//not used
//total update repeat Thermocouple + TFT every Second
unsigned long ValuespreviousMillis = 0;
unsigned long ValuesInterval = 1000;//used
unsigned long DelaypreviousMillis = 0;





double TFTscreen(double *pArray_Screen) //Menu 1 //Display
{

  if (pArray_Screen == nullptr)
  {
    Serial.println("TFTSCREEN- NULL pointer Passed!");
    Serial.flush();

    return 0;
  }
  // get some data
  j += 0.0013;
  currentmicros = micros();
  long value;
  double voltage;
  Serial.println("inside the TFT function");


  tft.setTextColor(C_WHITE, C_BLACK);
  tft.setCursor(0, 20);
  tft.setTextSize(2);
  tft.println(" This is just a test");
  tft.println(" this is just a test ");
  tft.setTextSize(2);

  Serial.println(tft.println("test"));
  tft.setTextColor(C_WHITE, C_BLACK);
  tft.setCursor(20, 200);
  tft.print("TempEmag: ");
  Serial.println("pArray_Screen[8]");
  Serial.println(pArray_Screen[8]);
  tft.print(pArray_Screen[8]);

  //  tft.print(j, 2);
  tft.print("    "); // blank out some if new string not as long as previous..
  sprintf(str, "TempEmag: %.2lf\n", pArray_Screen[8]);
  tft.print(str);

  return 0;
}





double *Thermocouples1()
{
  //use this to test the code and the pointers, you dont need to have MAX31855. good idea for debugging
  ////    for (int i = 0; i < 12; i++) TC1[i] += 0.25;
  ////    return TC1;
  if (TH1.readCelsius() < 0) //if temperature is lower than 0   ////Thermocouple 1
  {



    TC1[8] = TH1.readCelsius();
    delay(10);
    TC1[4] = TH1.readInternal();

    if (isnan( TC1[8]))
    {
      Serial.print("Something wrong with Thermocouple ");
    }
    else {
      Serial.print("C = ");
      Serial.println(TC1[8]);
    }
  } else  //this is the 0...500°
  {

    TC1[4] = TH1.readInternal();

    TC1[8] = TH1.readCelsius();
    if (isnan( TC1[8]))
    {
      Serial.print("Something wrong with Thermocouple ");
    }
    else {
      Serial.print("C = ");
      Serial.println(TC1[8]);
    }
    Serial.print("Thermocouples1 Print cArray_TC[8] = ");
    Serial.println(TC1[8]);



  }

  return TC1;
}



void setup()
{
  Serial.begin(115200);
  //SPI CS pins for the MAX31855 need to be set high!
  pinMode(MAX31855_1, OUTPUT); digitalWrite(MAX31855_1, HIGH);

  pinMode(TFT_CS,     OUTPUT); digitalWrite(TFT_CS, HIGH);

  SPI.begin();
  tft.begin();


  uint8_t x = tft.readcommand8(HX8357_RDMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDPIXFMT);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDIMGFMT);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDSELFDIAG);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);


  tft.setRotation(1);
  tft.fillScreen(C_BLACK);

  tft.fillRect(0, 30, 480, 10, C_RED);
  tft.fillRect(0, 140, 480, 10, C_BLUE);

  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
  Serial.print("Initializing sensor...");
  if (!TH1.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");
}

void loop()
{
elapsedMillis firstsecond;
elapsedMillis TCmillis;
elapsedMillis TFTmillis;
elapsedMillis Delaymillis;

  if (TCmillis <= 50) //during the first 50ms read the sensor.
  {
    Thermocouples1();
    TCmillis = TCmillis - 50;
  }
  else if (TFTmillis >= 50) 
  {
    TFTscreen(Thermocouples1());
    tft.fillScreen(C_RED);
    TFTmillis = TFTmillis - 250; //it calls the screen 4x in a second

  }
}

Single_Max31855_to_screen_withMAX31855_withdelay.ino (6.17 KB)

Hello Support,

Bad news my friend, this is not a support forum staffed with experts paid by Arduino Corp. It's a community support forum. We help each other as we can.

Edit: thanks for putting in the code tags! +1 karma

This is what I think the problem could be.

SPISettings settingsTFT(25000000, MSBFIRST, SPI_MODE3);
SPISettings SettingsA(5000000, MSBFIRST, SPI_MODE0);

You have the correct (presumably) settings for each spi device set up with those 2 lines of code. But they are never actually used. Those two objects "settingsTFT" and "SettingsA" never appear again in the sketch. They won't automatically get used at the appropriate times, it's necessary to explicitly set them to be used whenever the Arduino switches to communicating to each spi device. Have a look at the spi functions beginTransaction() and endTransaction().

What kind of Arduino are you using? Are you wanting to use hardware SPI with both the display and the thermocouple? Using hardware SPI with the display is important, because lots of data needs to be transferred. For the sensors, less so, only small amounts of data.

PaulRB:
This is what I think the problem could be.

SPISettings settingsTFT(25000000, MSBFIRST, SPI_MODE3);

SPISettings SettingsA(5000000, MSBFIRST, SPI_MODE0);



You have the correct (presumably) settings for each spi device set up with those 2 lines of code. But they are never actually used. Those two objects "settingsTFT" and "SettingsA" never appear again in the sketch. They won't automatically get used at the appropriate times, it's necessary to explicitly set them to be used whenever the Arduino switches to communicating to each spi device. Have a look at the spi functions beginTransaction() and endTransaction().

I posted this also on PJRC. KURT E told me these settings are only required in the beginning and are intelligently called in the max31855 and in the Featherwing HX8357_t3n library. I could be mistaken. I wouldnt doubt a guru. also no calls to the CS Pins DigitalWrite(14,HIGH, LOW) are required, this is also done automatically in the SPI.h.

I tried the SettingsA and SettingsTFT also today again and commented those sections with void setup and void loop which make calls to the functions and initialisation of the max31855 and hx8357

if I place the

 if (!TH1.begin())
  {
    //dont do anything
    Serial.println("Error");
  }

inside the void Setup before the TFT.begin(), the Thermocouple values on the Serial monitor show 0.0000.
the screen works and the tftScreen(Thermocouples()) prints to the TFT Screen.

is there anyway to check the max31855 if its ready. close connection send the data to the screen. I am posting this on this forum, because they "with all due respect cant help me".solve a simple communication problem.

I have also tested the code with the following line in the double *Thermocouples1(). this allows me to shows data on the Featherwing Screen which works.

for (int i = 0; i < 12; i++) TC1 += 0.25;
return TC1;
this is the forum with all tests I have done on the MAX31855 and featherwing. it also shows oscilloscope images of the CS pins pulled high and low.
rewriting the functions to closed void functions | Teensy Forum
so its not the code to transport data. its not the code in the void setup but some device and I am thinking its the MAX31855 is clogging the SPI lines. because the tft.fillscreen and other tft calls are not working.
its there someone here and I am in dire need for someone to call me or write me with a concise clear answer.