Arduino library for interfacing with the Analog Devices MAX31855 thermocouple-to-digital converter.
The MAX31855 is a cold-junction compensated thermocouple-to-digital converter. The MAX31855 is available in multiple variants, each designed for a specific thermocouple type (K, J, N, T, S, R, or E). This library provides a simple interface to read temperature data and diagnostic information from the device via SPI.
Install via the Arduino Library Manager by searching for "Sitron Labs MAX31855".
Alternatively, install manually:
- Download or clone this repository
- Place it in your Arduino
librariesfolder - Restart the Arduino IDE
Install via the PlatformIO Library Manager by searching for "Sitron Labs MAX31855".
Alternatively, add the library manually to your platformio.ini file:
lib_deps =
https://github.com/sitronlabs/SitronLabs_Analog_MAX31855_Arduino_Library.gitConnect the MAX31855 to your Arduino using SPI:
- VCC → 3.3V (check your board's specifications)
- GND → GND
- SCK → SCLK (Serial Clock)
- CS → Any digital pin (configure in code)
- SO → MISO (Master In Slave Out)
#include <SPI.h>
#include <max31855.h>
// Create sensor object
max31855 sensor;
// Define chip select pin
const int CS_PIN = 10;
void setup() {
Serial.begin(9600);
// Initialize SPI
SPI.begin();
// Setup the MAX31855 (SPI instance, speed in Hz, CS pin)
// Maximum SPI speed is 5MHz
sensor.setup(SPI, 1000000, CS_PIN);
}
void loop() {
float temp_thermocouple;
float temp_internal;
bool shorted_vcc;
bool shorted_gnd;
bool open_circuit;
// Read temperature and diagnostics
sensor.read(temp_thermocouple, temp_internal, shorted_vcc, shorted_gnd, open_circuit);
// Check for faults
if (open_circuit) {
Serial.println("Error: Thermocouple open circuit");
} else if (shorted_vcc) {
Serial.println("Error: Thermocouple shorted to VCC");
} else if (shorted_gnd) {
Serial.println("Error: Thermocouple shorted to GND");
} else {
Serial.print("Thermocouple: ");
Serial.print(temp_thermocouple);
Serial.print(" C, Internal: ");
Serial.print(temp_internal);
Serial.println(" C");
}
delay(1000);
}Initializes the MAX31855 sensor.
spi_library: SPI instance to use (typicallySPI)spi_speed: SPI clock speed in Hz (maximum 5MHz)pin_cs: Chip select pin number
Returns 0 on success, or -EINVAL if SPI speed exceeds 5MHz.
read(float &temperature_thermocouple_c, float &temperature_internal_c, bool &is_shorted_vcc, bool &is_shorted_gnd, bool &is_open)
Reads temperature data and diagnostic flags from the sensor.
temperature_thermocouple_c: Output parameter for thermocouple temperature in Celsius (0.25°C resolution)temperature_internal_c: Output parameter for internal reference junction temperature in Celsius (0.0625°C resolution)is_shorted_vcc: Output parameter indicating if thermocouple is shorted to VCCis_shorted_gnd: Output parameter indicating if thermocouple is shorted to GNDis_open: Output parameter indicating if thermocouple connection is open
Returns 0 on success.
- Thermocouple temperature resolution: 0.25°C
- Internal temperature resolution: 0.0625°C
- Maximum SPI speed: 5MHz
- Supports K, J, N, T, S, R, and E type thermocouples (depending on MAX31855 variant used)