Wiring & Test

You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For another kind of microcontroller, as long as you have 4 available pins it is possible to 'bit-bang SPI' or you can use hardware SPI if you like. Just check out the library, then port the code.

SPI Wiring

Since this is a SPI-capable sensor, we can use hardware or 'software' SPI. To make wiring identical on all Arduinos, we'll begin with 'software' SPI. The following pins should be used:

  • Connect Vin to the power supply, 3V or 5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V
  • Connect GND to common power/data ground
  • Connect the SCK pin to Digital #13 but any pin can be used later
  • Connect the SDO pin to Digital #12 but any pin can be used later
  • Connect the SDI pin to Digital #11 but any pin can be used later
  • Connect the CS pin Digital #10 but any pin can be used later

Later on, once we get it working, we can adjust the library to use hardware SPI if you desire, or change the pins to other

Download Adafruit_MAX31856 library

To begin reading sensor data, you will need to install Adafruit MAX31856 from the Arduino library manager.

Open up the Arduino library manager:

Search for the Adafruit MAX31856 library and install it

We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

Attach Thermocouple

You'll need to attach a thermocouple, for this demo we'll be using a K-type but you can adjust the demo if you do not have a K-type handy!

Load Demo

Open up File->Examples->Adafruit_MAX31856->max31856 and upload to your Arduino wired up to the sensor. Adjust the max.setThermocoupleType(MAX31856_TCTYPE_K) line if necessary.

Upload to your Arduino and open up the serial console at 115200 baud to see a print out of the cold junction temperature (temperature of the microcontroller chip) and the thermocouple temperature (temperature detected at the end of the thermocouple probe

You can also see some of the faults that are detectable by say disconnecting one of the pins:

Library Reference

You can start out by creating a MAX31856 object with either software SPI (where all four pins can be any I/O) using

Download: file
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31856 max = Adafruit_MAX31856(10, 11, 12, 13);

Or you can use hardware SPI. With hardware SPI you must use the hardware SPI pins for your Arduino - and each arduino type has different pins! Check the SPI reference to see what pins to use.
In this case, you can use any CS pin, but the other three pins are fixed

Download: file
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31856 max = Adafruit_MAX31856(10);

Once started, you can initialize the sensor with

Download: file
max.begin()

You'll also need to set the thermocouple type, remember there's a lot of options! Set the type with:

Download: file
max.setThermocoupleType(MAX31856_TCTYPE_xxx)

Your options for the TCTYPE are:

  • MAX31856_TCTYPE_B
  • MAX31856_TCTYPE_E
  • MAX31856_TCTYPE_J
  • MAX31856_TCTYPE_K
  • MAX31856_TCTYPE_N
  • MAX31856_TCTYPE_R
  • MAX31856_TCTYPE_S
  • MAX31856_TCTYPE_T
  • MAX31856_VMODE_G8
  • MAX31856_VMODE_G32

The last two are not thermocouple types, they're just 'plain' voltage readings (check the datasheet for more details, we don't use these modes in the library)

If you're ever not sure which mode you're in, query it with

Download: file
max.getThermocoupleType()

Once that's set you can read the cold junction temperature, which will return a floating point Celsius reading. This is the temperature detected inside the MAX31856 chip ('ambient' temp)

Download: file
max.readCJTemperature()

Or, of course, the temperature at the end/tip of the thermocouple, likewise a floating point #

Download: file
max.readThermocoupleTemperature()

Faults

The MAX31856 has a wide-ranging fault mechanism that can alert you via pin or function when something is amiss. Don't forget to test this functionality before relying on it!

You can read faults with

Download: file
 max.readFault()

Which will return a uint8_t type with bits set for each of 8 different fault types. You can test for each one with this set of code:

Download: file
  uint8_t fault = max.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");
  }

The last two faults are built in. For the low/high threshholds, you can set those with two functions.

For the cold junction (chip) temp, use:

Download: file
max.setColdJunctionFaultThreshholds(lowtemp, hightemp)

Where lowtemp and hightemp range between -127 and +127 Centigrade (the chip wont function down to -127 but that's the lowest number you can put in.

For the thermocouple, use

Download: file
setTempFaultThreshholds(lowtemp, hightemp)

Where lowtemp and hightemp are floating point numbers with a range of -4096 to +4096 and a resolution of 0.0625 degrees Centigrade

This guide was first published on Sep 22, 2016. It was last updated on Sep 22, 2016. This page (Wiring & Test) was last updated on Dec 05, 2019.