Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Arduino library for MAX31855 chip for K type thermocouple

License

NotificationsYou must be signed in to change notification settings

RobTillaart/MAX31855_RT

Repository files navigation

Arduino CIArduino-lintJSON checkGitHub issues

License: MITGitHub releasePlatformIO Registry

MAX31855_RT

Arduino library for MAX31855 chip for K type thermocouple.

The library has experimental support for other types of thermocouples E, J, N, R, S, T.

Description

The MAX38155 is a chip to convert the reading of a K-type thermocouple to a temperature.The working of thermocouples (TC) is based upon Seebeck effect.Different TC's have a different Seebeck Coefficient (SC) expressed in µV/°C.Seehttp://www.analog.com/library/analogDialogue/archives/44-10/thermocouple.html

For every type of TC there exist an MAX31855 variant, this library is primarydeveloped for the K-type sensor. However it has experimental support for allother types of TC's. See details below.

Library tested with breakout board.

         +---------+     Vin | o       |     3V3 | o       |     GND | o     O | Thermocouple      D0 | o     O | Thermocouple      CS | o       |     CLK | o       |         +---------+

0.6.0 Breaking change

Version 0.6.0 introduced a breaking change to improve handling the SPI dependency.The user has to callSPI.begin() or equivalent before callingMX.begin().Optionally the user can provide parameters to theSPI.begin(...)

0.5.0 Breaking change

The version 0.5.0 has breaking changes in the interface.The essence is removal of ESP32 specific code from the library.This makes it possible to support the ESP32-S3 and other processors in the future.Also it makes the library a bit simpler to maintain.

Note the order of the parameters of the software SPI constructor has changed in 0.5.0.

Related

Hardware SPI vs software SPI

Default pin connections. ESP32 can overrule withsetGPIOpins().

HW SPIUNOESP32 VSPIESP32 HSPINotes
CLOCKPIN131814
MISO121912
MOSI112313not used...
SELECT4515can be others too.

Performance read() function, timing in us. (ESP32 @240MHz)

modeclocktiming UNOtiming ESP32Notes
HW SPI32000000ni~15less reliable
HW SPI16000000~68~16
HW SPI4000000~72~23
HW SPI1000000~100~51
HW SPI500000~128~89
SW SPIbit bang~500~17 (!)

Interface

#include"MAX31855.h"

Constructor

  • MAX31855(uint8_t select, SPIClassRP2040 * mySPI) hardware SPI R2040
  • MAX31855(uint8_t select, SPIClass * mySPI) hardware SPI other
  • MAX31855(uint8_t select, uint8_t miso, uint8_t clock) software SPI
  • void begin() initialize internals

Hardware SPI

To be used only if one needs a specific speed.

  • void setSPIspeed(uint32_t speed) set SPI transfer rate.
  • uint32_t getSPIspeed() returns SPI transfer rate.
  • void setSWSPIdelay(uint16_t del = 0) for tuning SW SPI signal quality. Del is the time in micros added per bit. Even numbers keep the duty cycle of the clock around 50%.
  • uint16_t getSWSPIdelay() get set value in micros.

Reading

To make a temperature reading callread().It returns the status of the read which is a value between 0..7The functiongetStatus() returns the same status value.

Table: values returned fromuint8_t read() anduint8_t getStatus()

valueDescriptionAction
0OK
1Thermocouple open circuitcheck wiring
2Thermocouple short to GNDcheck wiring
4Thermocouple short to VCCcheck wiring
7Generic error
128No read done yetcheck wiring
129No communicationcheck wiring

There are six functions to check the individual error conditions mentioned above.These make it easier to check them.

  • bool openCircuit()
  • bool shortToGND()
  • bool shortToVCC()
  • bool genericError()
  • bool noRead()
  • bool noCommunication()

After auint8_t read() you can get the temperature withfloat getTemperature()andfloat getInternal() for the internal temperature of the chip / board itself.Normally these are (almost) equal.

Repeated calls togetTemperature() will give the same value until a newread().The latter fetches a new value from the sensor. Note that if theread() failsthe value ofgetTemperature() can become incorrect. So it is important to checkthe return value ofread().

Offset

The library supports a fixed offset to calibrate the thermocouple.For this the functionsfloat getOffset() andvoid setOffset(float offset) are available.This offset is "added" in thegetTemperature() function.

Notes

  • the offset can be positive or negative.
  • the offset used is a float, so decimals can be used.A typical usage is to callsetOffset(273.15) to get ° Kelvin.

Delta analysis

As thetc object holds its last known temperature it is easy to determine the deltawith the last known temperature, e.g. for trend analysis.

float last = tc.getTemperature();int state  = tc.read();if (state == STATUS_OK)  {floatnew  = tc.getTemperature();float delta =new - last;// process data  }

Last time read

Thetc object keeps track of the last timeread() is called in the functionuint32_t lastRead().The time is tracked inmillis(). This makes it easy to read the sensor at certain intervals.

if (millis() - tc.lastRead() >= interval){int state = tc.read();if (state == STATUS_OK)  {floatnew = tc.getTemperature();// process read value.  }else  {// handle error  }}

GetRawData

The functionuint32_t getRawData() allows you to get all the 32 bits raw data from the board,after the standarduint8_t tc.read() call.

Example code can be found in the examples folder.

int state = thermocouple.read();uint32_t value = thermocouple.getRawData();// Read the raw Data value from the module

This allows one to compact the measurement e.g. for storage or sending over a network.

Pull Up Resistor

To have proper working of the MAX31855 board, you need to add a pull-up resistor(e.g. 4K7 - 1K depending on length of the wires) between the MISO pin (from constructor call)and the VCC (5Volt).This improves the signal quality and will allow you to detect if there is proper communicationwith the board. Without pull-up one might get random noise that could look like real data.

Note: the MISO pin can be different from each board, please refer to your board datasheet.

If the MAX31855 board is not connectedtc.read() will returnSTATUS_NO_COMMUNICATION.

You can verify this bytc.getRawData() which will give 32 HIGH bits or 0xFFFFFFFF).

You can use a simple code to detect connection error board:

uint8_t status = thermocouple.read();if (status == STATUS_NO_COMMUNICATION)  {    Serial.println("NO COMMUNICATION");  }

or

uint8_t status = thermocouple.read();if (thermocouple.getRawData() ==0xFFFFFFFF)  {    Serial.println("NO COMMUNICATION");  }

Operation

See examples

Experimental part (to be tested)

NOTE:The support for other thermocouples is experimentaluse at your own risk.

The MAX31855 is designed for K type sensors. It essentially measures avoltage difference and converts this voltage using the Seebeck Coefficient (SC)to the temperature. As the SC is linear in its nature it is possibleto replace the K-type TC with one of the other types of TC.

Datasheet Table 1, page 8 SC = Seebeck Coefficient

Sensor typeSC in µV/°CTemp Range in °CMaterial
E_TC76.373-270 to +1000Constantan Chromel
J_TC57.953-210 to +1200Constantan Iron
K_TC41.276-270 to +1372Alumel Chromel
N_TC36.256-270 to +1300Nisil Nicrosil
R_TC10.506-50 to +1768Platinum Platinum/Rhodium
S_TC9.587+50 to +1768Platinum Platinum/Rhodium
T_TC52.18-270 to +400Constantan Copper

The core formula to calculate the temperature is (Datasheet page 8)

Vout = (41.276µV/°C) x (Temp_R - Temp_internal)

As we know the internal temperature and the returned temperature from the sensorthe library can calculate the Vout measured (as the chip assumes that a K-typethermocouple is connected.Having that Vout we can redo the math for the actual thermocouple type andcalculate the real temperature.

The library has two functionssetSeebeckCoefficient(float factor) andfloat getSeebeckCoefficient()to get/set the Seebeck Coefficient (== thermocouple) to be used.One can adjust the values to improve the accuracy of the temperature read.

Thefloat getTemperature() has implemented this algorithm, however as longas one does not set the Seebeck Coefficient it will use the K_TC as default.

Future

Must

Should

  • investigate other TC's

Could

  • move code to .cpp

Wont

Support

If you appreciate my libraries, you can support the development and maintenance.Improve the quality of the libraries by providing issues and Pull Requests, ordonate through PayPal or GitHub sponsors.

Thank you,


[8]ページ先頭

©2009-2025 Movatter.jp