{"id":20989967,"url":"https://github.com/robtillaart/max31855_rt","last_synced_at":"2025-05-14T18:32:24.217Z","repository":{"id":45495954,"uuid":"273669244","full_name":"RobTillaart/MAX31855_RT","owner":"RobTillaart","description":"Arduino library for MAX31855 chip for K type thermocouple","archived":false,"fork":false,"pushed_at":"2024-06-03T13:03:47.000Z","size":80,"stargazers_count":17,"open_issues_count":0,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-06T18:19:00.297Z","etag":null,"topics":["arduino","library","thermocouple"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2020-06-20T08:32:20.000Z","updated_at":"2024-07-03T07:00:01.000Z","dependencies_parsed_at":"2024-01-19T18:43:46.376Z","dependency_job_id":"bd34ec60-96dc-450e-b4c0-f63c0a12fbc4","html_url":"https://github.com/RobTillaart/MAX31855_RT","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FMAX31855_RT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FMAX31855_RT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FMAX31855_RT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FMAX31855_RT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/MAX31855_RT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225305828,"owners_count":17453463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","library","thermocouple"],"created_at":"2024-11-19T06:27:04.102Z","updated_at":"2024-11-19T06:27:04.714Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":[],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/MAX31855_RT/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/MAX31855_RT/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MAX31855_RT/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/MAX31855_RT/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/MAX31855_RT/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/MAX31855_RT.svg)](https://github.com/RobTillaart/MAX31855_RT/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/MAX31855_RT/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/MAX31855_RT.svg?maxAge=3600)](https://github.com/RobTillaart/MAX31855_RT/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/MAX31855.svg)](https://registry.platformio.org/libraries/robtillaart/MAX31855)\n\n\n# MAX31855_RT\n\nArduino library for MAX31855 chip for K type thermocouple.\n\nThe library has experimental support for other types of thermocouples E, J, N, R, S, T.\n\n\n## Description\n\nThe MAX38155 is a chip to convert the reading of a K-type thermocouple to a temperature.\nThe working of thermocouples (TC) is based upon Seebeck effect.\nDifferent TC's have a different Seebeck Coefficient (SC) expressed in µV/°C.\nSee http://www.analog.com/library/analogDialogue/archives/44-10/thermocouple.html\n\nFor every type of TC there exist an MAX31855 variant, this library is primary\ndeveloped for the K-type sensor. However it has experimental support for all\nother types of TC's. See details below.\n\nLibrary tested with breakout board.\n\n```\n         +---------+\n     Vin | o       |\n     3V3 | o       |\n     GND | o     O | Thermocouple\n      D0 | o     O | Thermocouple\n      CS | o       |\n     CLK | o       |\n         +---------+\n\n```\n\n\n#### 0.6.0 Breaking change\n\nVersion 0.6.0 introduced a breaking change to improve handling the SPI dependency.\nThe user has to call **SPI.begin()** or equivalent before calling **MX.begin()**.\nOptionally the user can provide parameters to the **SPI.begin(...)**\n\n\n#### 0.5.0 Breaking change\n\nThe version 0.5.0 has breaking changes in the interface. \nThe essence is removal of ESP32 specific code from the library. \nThis makes it possible to support the ESP32-S3 and other processors in the future. \nAlso it makes the library a bit simpler to maintain.\n\nNote the order of the parameters of the software SPI constructor has changed in 0.5.0.\n\n\n#### Related\n\n- https://github.com/RobTillaart/MAX6675\n- https://github.com/RobTillaart/MAX31850\n- https://github.com/RobTillaart/MAX31855_RT\n\n\n## Hardware SPI vs software SPI\n\nDefault pin connections. ESP32 can overrule with **setGPIOpins()**.\n\n |  HW SPI    |  UNO  |  ESP32 VSPI  |  ESP32 HSPI  |  Notes\n |:-----------|:-----:|:------------:|:------------:|:----------|\n |  CLOCKPIN  |   13  |     18       |     14       |\n |  MISO      |   12  |     19       |     12       |\n |  MOSI      |   11  |     23       |     13       |  *not used...*\n |  SELECT    |    4  |      5       |     15       |  *can be others too.*\n\n\nPerformance read() function, timing in us.  (ESP32 @240MHz)\n\n|   mode   |  clock     |  timing UNO  |  timing ESP32  |  Notes\n|:---------|-----------:|-------------:|---------------:|:----------|\n|  HW SPI  |  32000000  |       ni     |      ~15       |  *less reliable*\n|  HW SPI  |  16000000  |      ~68     |      ~16       |\n|  HW SPI  |   4000000  |      ~72     |      ~23       |\n|  HW SPI  |   1000000  |      ~100    |      ~51       |\n|  HW SPI  |    500000  |      ~128    |      ~89       |\n|  SW SPI  |  bit bang  |      ~500    |      ~17 (!)   |\n\n\n## Interface\n\n```cpp\n#include \"MAX31855.h\"\n```\n\n#### Constructor\n\n- **MAX31855(uint8_t select, SPIClassRP2040 \\* mySPI)** hardware SPI R2040\n- **MAX31855(uint8_t select, SPIClass \\* mySPI)** hardware SPI other\n- **MAX31855(uint8_t select, uint8_t miso, uint8_t clock)** software SPI\n- **void begin()** initialize internals\n\n\n#### Hardware SPI\n\nTo be used only if one needs a specific speed.\n\n- **void setSPIspeed(uint32_t speed)** set SPI transfer rate.\n- **uint32_t getSPIspeed()** returns SPI transfer rate.\n- **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%.\n- **uint16_t getSWSPIdelay()** get set value in micros.\n\n\n#### Reading\n\nTo make a temperature reading call **read()**.\nIt returns the status of the read which is a value between 0..7\nThe function **getStatus()** returns the same status value. \n\nTable: values returned from **uint8_t read()** and **uint8_t getStatus()**\n\n| value | Description               | Action       |\n|:-----:|:--------------------------|:-------------|\n|    0  | OK                        |              |\n|    1  | Thermocouple open circuit | check wiring |\n|    2  | Thermocouple short to GND | check wiring |\n|    4  | Thermocouple short to VCC | check wiring |\n|    7  | Generic error             |              |\n|  128  | No read done yet          | check wiring |\n|  129  | No communication          | check wiring |\n\nThere are six functions to check the individual error conditions mentioned above.\nThese make it easier to check them.\n\n- **bool openCircuit()**\n- **bool shortToGND()**\n- **bool shortToVCC()**\n- **bool genericError()**\n- **bool noRead()**\n- **bool noCommunication()**\n\nAfter a **uint8_t read()** you can get the temperature with **float getTemperature()** \nand **float getInternal()** for the internal temperature of the chip / board itself.\nNormally these are (almost) equal.\n\nRepeated calls to **getTemperature()** will give the same value until a new **read()**.\nThe latter fetches a new value from the sensor. Note that if the **read()** fails\nthe value of **getTemperature()** can become incorrect. So it is important to check \nthe return value of **read()**.\n\n\n#### Offset\n\nThe library supports a fixed offset to calibrate the thermocouple.\nFor this the functions **float getOffset()** and **void setOffset(float offset)** are available.\nThis offset is \"added\" in the **getTemperature()** function.\n\nNotes\n- the offset can be positive or negative.\n- the offset used is a float, so decimals can be used.\nA typical usage is to call **setOffset(273.15)** to get ° Kelvin.\n\n\n#### Delta analysis\n\nAs the **tc** object holds its last known temperature it is easy to determine the delta \nwith the last known temperature, e.g. for trend analysis.\n\n```cpp\n  float last = tc.getTemperature();\n  int state  = tc.read();\n  if (state == STATUS_OK)\n  {\n    float new  = tc.getTemperature();\n    float delta = new - last;\n    // process data\n  }\n```\n\n\n#### Last time read\n\nThe **tc** object keeps track of the last time **read()** is called in the function **uint32_t lastRead()**.\nThe time is tracked in **millis()**. This makes it easy to read the sensor at certain intervals.\n\n```cpp\nif (millis() - tc.lastRead() \u003e= interval)\n{\n  int state = tc.read();\n  if (state == STATUS_OK)\n  {\n    float new = tc.getTemperature();\n    // process read value.\n  }\n  else\n  {\n    // handle error\n  }\n}\n```\n\n\n#### GetRawData \n\nThe function **uint32_t getRawData()** allows you to get all the 32 bits raw data from the board, \nafter the standard **uint8_t tc.read()** call.\n\nExample code can be found in the examples folder.\n\n```cpp\n  int state = thermocouple.read();              \n  uint32_t value = thermocouple.getRawData();  // Read the raw Data value from the module\n```\n\nThis allows one to compact the measurement e.g. for storage or sending over a network.\n\n\n## Pull Up Resistor \n\nTo have proper working of the MAX31855 board, you need to add a pull-up resistor \n(e.g. 4K7 - 1K depending on length of the wires) between the MISO pin (from constructor call) \nand the VCC (5Volt). \nThis improves the signal quality and will allow you to detect if there is proper communication \nwith the board. Without pull-up one might get random noise that could look like real data.\n\n**Note:** the MISO pin can be different from each board, please refer to your board datasheet.\n\nIf the MAX31855 board is not connected **tc.read()** will return **STATUS_NO_COMMUNICATION**.\n\nYou can verify this by **tc.getRawData()** which will give 32 HIGH bits or 0xFFFFFFFF).\n\nYou can use a simple code to detect connection error board:\n\n```cpp\n  uint8_t status = thermocouple.read();\n  if (status == STATUS_NO_COMMUNICATION)\n  {\n    Serial.println(\"NO COMMUNICATION\");\n  }\n```\n\nor\n\n```cpp\n  uint8_t status = thermocouple.read();\n  if (thermocouple.getRawData() == 0xFFFFFFFF)\n  {\n    Serial.println(\"NO COMMUNICATION\");\n  }\n```\n\n\n## Operation\n\nSee examples\n\n\n## Experimental part (to be tested)\n\n**NOTE:** \nThe support for other thermocouples is experimental **use at your own risk**.\n\n\nThe MAX31855 is designed for K type sensors. It essentially measures a \nvoltage difference and converts this voltage using the Seebeck Coefficient (SC) \nto the temperature. As the SC is linear in its nature it is possible\nto replace the K-type TC with one of the other types of TC.\n\n\nDatasheet Table 1, page 8  SC = Seebeck Coefficient\n\n| Sensor type | SC in µV/°C | Temp Range in °C | Material                  |\n|:-----------:|:------------|:-----------------|:--------------------------|\n|   E_TC      |    76.373   |   -270 to +1000  | Constantan Chromel        |\n|   J_TC      |    57.953   |   -210 to +1200  | Constantan Iron           |\n|   K_TC      |    41.276   |   -270 to +1372  | Alumel Chromel            |\n|   N_TC      |    36.256   |   -270 to +1300  | Nisil Nicrosil            |\n|   R_TC      |    10.506   |    -50 to +1768  | Platinum Platinum/Rhodium |\n|   S_TC      |     9.587   |    +50 to +1768  | Platinum Platinum/Rhodium |\n|   T_TC      |    52.18    |   -270 to +400   | Constantan Copper         |\n\n\nThe core formula to calculate the temperature is  (Datasheet page 8)\n```\nVout = (41.276µV/°C) x (Temp_R - Temp_internal)\n```\nAs we know the internal temperature and the returned temperature from the sensor\nthe library can calculate the Vout measured (as the chip assumes that a K-type \nthermocouple is connected. \nHaving that Vout we can redo the math for the actual thermocouple type and\ncalculate the real temperature. \n\nThe library has two functions **setSeebeckCoefficient(float factor)** and \n**float getSeebeckCoefficient()**\nto get/set the Seebeck Coefficient (== thermocouple) to be used. \nOne can adjust the values to improve the accuracy of the temperature read. \n\nThe **float getTemperature()** has implemented this algorithm, however as long\nas one does not set the Seebeck Coefficient it will use the K_TC as default.\n\n\n## Future\n\n#### Must\n\n#### Should\n\n- investigate other TC's \n\n#### Could\n\n- move code to .cpp\n\n#### Wont\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Fmax31855_rt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobtillaart%2Fmax31855_rt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Fmax31855_rt/lists"}