Adafruit MAX 31856 to Sparkfun ESP32

Hi all,
I have a ESP32 Sparkfun hooked up to a adafruit MAX 31856 and having no joy. I used this as as guide.

I have it powered up by USB and the connections are as follows:

I changed the code to S Type thermocouple but have also tried the standard K type.

It seems the SPI is not communicating at all as I pull the wiring out and the output result is the same.

MAX31856 --- ESP32

VIN -------------------- 3V3
GND -------------------- GND
SCK -------------------- D18
SDO -------------------- D19
SDI -------------------- D23
CS --------------------- D5
DRDY -------------------- D4
The code I entered is as follows:

// This example demonstrates continuous conversion mode using the
// DRDY pin to check for conversion completion.

#include <Adafruit_MAX31856.h>
#define DRDY_PIN 4

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(5, 23, 19, 18);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10);

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);
  Serial.println("MAX31856 thermocouple test");

  pinMode(DRDY_PIN, INPUT);

  if (!maxthermo.begin()) {
    Serial.println("Could not initialize thermocouple.");
    while (1) delay(10);
  }

  maxthermo.setThermocoupleType(MAX31856_TCTYPE_S);

  Serial.print("Thermocouple type: ");
  switch (maxthermo.getThermocoupleType() ) {
    case MAX31856_TCTYPE_B: Serial.println("B Type"); break;
    case MAX31856_TCTYPE_E: Serial.println("E Type"); break;
    case MAX31856_TCTYPE_J: Serial.println("J Type"); break;
    case MAX31856_TCTYPE_K: Serial.println("K Type"); break;
    case MAX31856_TCTYPE_N: Serial.println("N Type"); break;
    case MAX31856_TCTYPE_R: Serial.println("R Type"); break;
    case MAX31856_TCTYPE_S: Serial.println("S Type"); break;
    case MAX31856_TCTYPE_T: Serial.println("T Type"); break;
    case MAX31856_VMODE_G8: Serial.println("Voltage x8 Gain mode"); break;
    case MAX31856_VMODE_G32: Serial.println("Voltage x8 Gain mode"); break;
    default: Serial.println("Unknown"); break;
  }

  maxthermo.setConversionMode(MAX31856_CONTINUOUS);
}

void loop() {
  // The DRDY output goes low when a new conversion result is available
  int count = 0;
  while (digitalRead(DRDY_PIN)) {
    if (count++ > 200) {
      count = 0;
      Serial.print(".");
    }
  }
  Serial.println(maxthermo.readThermocoupleTemperature());
}

All I am getting is 0.0 back from the serial.
On reset the following is displayed followed by repeating 0.0

ho 0 tail 12 room 4

load:0x40078000,len:15488

load:0x40080400,len:4

load:0x40080404,len:3180

entry 0x400805b8

MAX31856 thermocouple test

Thermocouple type: B Type

0.00

0.00

0.00

0.00

0.00

0.00


I have tried changing the wiring and pins pins to different pins via

Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(5, 23, 19, 18);

Im pretty stuck here.

Any help would be very much appreciated.

I believe its a problem with the SPI not starting up but I am very new at this. This is actually my first attempt.

Cheers.

Use the hardware SPI

Connect like this
VIN--3V3
GND--GND
SCK--D5
SDO--D19
SDI--D18
CS--D4

The library does not use DRDY.

Thanks for your response.
Tried that but same result. 0.0
Is there a way to test if the MAX is actually responding as im getting the same results in the program even with it disconnected?

This sketch will detect errors:

// Basic example using one-shot measurement.
// The call to readThermocoupleTemperature() is blocking for O(100ms)

#include <Adafruit_MAX31856.h>

// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(4);

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);
  Serial.println("MAX31856 thermocouple test");

  maxthermo.begin();

  maxthermo.setThermocoupleType(MAX31856_TCTYPE_K);

  Serial.print("Thermocouple type: ");
  switch (maxthermo.getThermocoupleType() ) {
    case MAX31856_TCTYPE_B: Serial.println("B Type"); break;
    case MAX31856_TCTYPE_E: Serial.println("E Type"); break;
    case MAX31856_TCTYPE_J: Serial.println("J Type"); break;
    case MAX31856_TCTYPE_K: Serial.println("K Type"); break;
    case MAX31856_TCTYPE_N: Serial.println("N Type"); break;
    case MAX31856_TCTYPE_R: Serial.println("R Type"); break;
    case MAX31856_TCTYPE_S: Serial.println("S Type"); break;
    case MAX31856_TCTYPE_T: Serial.println("T Type"); break;
    case MAX31856_VMODE_G8: Serial.println("Voltage x8 Gain mode"); break;
    case MAX31856_VMODE_G32: Serial.println("Voltage x8 Gain mode"); break;
    default: Serial.println("Unknown"); break;
  }

}

void loop() {
  Serial.print("Cold Junction Temp: ");
  Serial.println(maxthermo.readCJTemperature());

  Serial.print("Thermocouple Temp: ");
  Serial.println(maxthermo.readThermocoupleTemperature());
  // Check and print any faults
  uint8_t fault = maxthermo.readFault();
  if (fault) {
    if (fault & MAX31856_FAULT_CJRANGE) Serial.println("Cold Junction Range Fault");
    if (fault & MAX31856_FAULT_TCRANGE) Serial.println("Thermocouple Range Fault");
    if (fault & MAX31856_FAULT_CJHIGH)  Serial.println("Cold Junction High Fault");
    if (fault & MAX31856_FAULT_CJLOW)   Serial.println("Cold Junction Low Fault");
    if (fault & MAX31856_FAULT_TCHIGH)  Serial.println("Thermocouple High Fault");
    if (fault & MAX31856_FAULT_TCLOW)   Serial.println("Thermocouple Low Fault");
    if (fault & MAX31856_FAULT_OVUV)    Serial.println("Over/Under Voltage Fault");
    if (fault & MAX31856_FAULT_OPEN)    Serial.println("Thermocouple Open Fault");
  }
  delay(1000);
}

Running these connections with the code you just sent outputs the following:

entry 0x400805b8
MAX31856 thermocouple test
Thermocouple type: B Type
Cold Junction Temp: 0.00
Thermocouple Temp: 0.00
Cold Junction Temp: 0.00
Thermocouple Temp: 0.00
Cold Junction Temp: 0.00
Thermocouple Temp: 0.00

It does look like the MAX31856 is not sending data back
Which board do you have selected?
The pinout I gave you was for the Sparkfun ESP32 Thing.
I see the pinouts are different for the other ESP32 boards

Yes I selected Sparkfun ESP32 Thing. COM port 10.

Maybe a hardware issue?

No, I looked at the wrong pinout, for the thing plus
Your original connections are correct for the thing but no need for DRDY
So try the code again with your original connections but change the CS pin in the code to 5

I have done that but same deal.

Here is the code with pin change:

// Basic example using one-shot measurement.
// The call to readThermocoupleTemperature() is blocking for O(100ms)

#include <Adafruit_MAX31856.h>

// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(5);

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);
  Serial.println("MAX31856 thermocouple test");

  maxthermo.begin();

  maxthermo.setThermocoupleType(MAX31856_TCTYPE_S);

  Serial.print("Thermocouple type: ");
  switch (maxthermo.getThermocoupleType() ) {
    case MAX31856_TCTYPE_B: Serial.println("B Type"); break;
    case MAX31856_TCTYPE_E: Serial.println("E Type"); break;
    case MAX31856_TCTYPE_J: Serial.println("J Type"); break;
    case MAX31856_TCTYPE_K: Serial.println("K Type"); break;
    case MAX31856_TCTYPE_N: Serial.println("N Type"); break;
    case MAX31856_TCTYPE_R: Serial.println("R Type"); break;
    case MAX31856_TCTYPE_S: Serial.println("S Type"); break;
    case MAX31856_TCTYPE_T: Serial.println("T Type"); break;
    case MAX31856_VMODE_G8: Serial.println("Voltage x8 Gain mode"); break;
    case MAX31856_VMODE_G32: Serial.println("Voltage x8 Gain mode"); break;
    default: Serial.println("Unknown"); break;
  }

}

void loop() {
  Serial.print("Cold Junction Temp: ");
  Serial.println(maxthermo.readCJTemperature());

  Serial.print("Thermocouple Temp: ");
  Serial.println(maxthermo.readThermocoupleTemperature());
  // Check and print any faults
  uint8_t fault = maxthermo.readFault();
  if (fault) {
    if (fault & MAX31856_FAULT_CJRANGE) Serial.println("Cold Junction Range Fault");
    if (fault & MAX31856_FAULT_TCRANGE) Serial.println("Thermocouple Range Fault");
    if (fault & MAX31856_FAULT_CJHIGH)  Serial.println("Cold Junction High Fault");
    if (fault & MAX31856_FAULT_CJLOW)   Serial.println("Cold Junction Low Fault");
    if (fault & MAX31856_FAULT_TCHIGH)  Serial.println("Thermocouple High Fault");
    if (fault & MAX31856_FAULT_TCLOW)   Serial.println("Thermocouple Low Fault");
    if (fault & MAX31856_FAULT_OVUV)    Serial.println("Over/Under Voltage Fault");
    if (fault & MAX31856_FAULT_OPEN)    Serial.println("Thermocouple Open Fault");
  }
  delay(1000);
}

and printout from strtup:

Thermocouple type: B Type
Cold Junction Temp: 0.00
Thermocouple Temp: 0.00
Cold Junction Temp: 0.00
Thermocouple Temp: 0.00

I can see it says B type thermocouple too when I selected S type. There definitely seems to be no comms between ESP amd module.

Then, I suspect the max31856 board is bad

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4604
ho 0 tail 12 room 4
load:0x40078000,len:15488
load:0x40080400,len:4
load:0x40080404,len:3180
entry 0x400805b8
MAX31856 thermocouple test
Thermocouple type: B Type
Cold Junction Temp: 0.00
Thermocouple Temp: 0.00
Cold Junction Temp: 0.00
Thermocouple Temp: 0.00

Yes OK I was thinking it could be that but as it was my first project I was sure it was something I had to be doing wrong.

Thankyou very much. I really appreciate your time.

If you soldered the header pins on yourself, you should check the solder connections. You may have a bad/cold solder joint or if you are using a breadboard it may be a bad connection. Try moving the board to a different location on the breadboard.

I did solder them myself so I will try and resolder the connections and do as you suggested.
I will report back tomorrow on this.
Cheers.

No hurry

OK I resoldered everything and all the joints look fine. Im assuming its a hardware problem at this stage then..

Will get some new boards and try again I guess.

Which thermocouple type are you using ?
The red wire goes to the "─" terminal.
Make sure that there's plenty of exposed wire getting clamped.

I’m using an S Type and it’s definitely wired correctly with black positive and red negative and the correct type compensating wire

OK its going.
I think the main problem was bad solder joints. Once I fixed that it still wasnt working but that was my fault with a misconnection on the breadboard.

I am now getting readings back OK.

Thanks for the help. Much appreciated and a lesson learned regarding soldering.

Glad you have it working.
Now have fun!