From a256f12bd3e6a18918cf8065c870077fc090f985 Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Wed, 16 Nov 2022 15:46:22 +0100 Subject: [PATCH] 0.4.2 MAX31855_RT --- libraries/MAX31855_RT/.arduino-ci.yml | 16 +++ libraries/MAX31855_RT/CHANGELOG.md | 90 +++++++++++++++ libraries/MAX31855_RT/MAX31855.cpp | 111 +++++++------------ libraries/MAX31855_RT/MAX31855.h | 28 ++--- libraries/MAX31855_RT/README.md | 24 ++-- libraries/MAX31855_RT/library.json | 2 +- libraries/MAX31855_RT/library.properties | 2 +- libraries/MAX31855_RT/test/unit_test_001.cpp | 30 +---- 8 files changed, 186 insertions(+), 117 deletions(-) create mode 100644 libraries/MAX31855_RT/CHANGELOG.md diff --git a/libraries/MAX31855_RT/.arduino-ci.yml b/libraries/MAX31855_RT/.arduino-ci.yml index cecf5850..25980972 100644 --- a/libraries/MAX31855_RT/.arduino-ci.yml +++ b/libraries/MAX31855_RT/.arduino-ci.yml @@ -1,3 +1,18 @@ +platforms: + rpipico: + board: rp2040:rp2040:rpipico + package: rp2040:rp2040 + gcc: + features: + defines: + - ARDUINO_ARCH_RP2040 + warnings: + flags: + +packages: + rp2040:rp2040: + url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: @@ -9,3 +24,4 @@ compile: - esp32 # - esp8266 # - mega2560 + - rpipico diff --git a/libraries/MAX31855_RT/CHANGELOG.md b/libraries/MAX31855_RT/CHANGELOG.md new file mode 100644 index 00000000..d58ab831 --- /dev/null +++ b/libraries/MAX31855_RT/CHANGELOG.md @@ -0,0 +1,90 @@ +# Change Log MAX31855_RT + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + + +## [0.4.2] - 2022-11-16 +- add RP2040 in build-CI +- add changelog.md +- minor edit readme.md +- minor edit unit test + + +## [0.4.1] - 2021-12-10 +- add SWSPI delay + getter/setter + +## [0.4.0] - 2021-12-09 +- fix #21 breaking change for HW SPI +- move constructor code to begin() +- read() removed "premature" return on status. + +---- + +## [0.3.0] - 2021-08-11 +- VSPI / HSPI support for ESP32 +- add setGIOpins - ESP32 specific +- add get/setSPIspeed() - all + +## [0.2.5] - 2021-07-04 +- fix #14 CS for STM32. + +## [0.2.4] - 2020-12-30 +- arduinoCI, unit test + +## [0.2.3] - 2020-08-30 +- fix #8 support hardware SPI + example + +## [0.2.2] - 2020-08-30 +- fix #9 +- fix failing examples +- minor refactor + +## [0.2.1] - 2020-08-26 +- read rawData and STATUS_NO_COMMUNICATION recognition (thanks to FabioBrondo) + +## [0.2.0] - 2020-06-20 +- add #pragma once +- major refactor +- remove pre 1.0 support +- fix offset + +---- + +## [0.1.10] - 2019-07-31 +- add 3 inline functions to test errors +- add demo sketch + +## [0.1.9] - 2017-07-27 +- fix #33 reverted double -> float + +## [0.1.08] - 2015-12-06 +- replaced all temperature calls with one TCfactor +- update demos. + +## [0.1.07] - 2015-12-06 +- updated TC factors from the MAX31855 datasheet + +## [0.1.06] - 2015-12-05 +- added support for other types of TC's (experimental) + +## [0.1.05] - 2015-07-12 +- refactor robust constructor. + +## [0.1.04] - 2015-03-09 +- replaced float -> double (ARM support). + +## [0.1.03] - 2014-01-24 +- fixed negative temperature. + +## [0.1.02] - 2014-01-03 +- added offset. + +## [0.1.01] - 2014-01-02 +- refactored speed/performance. + +## [0.1.00] - 2014-01-02 +- initial version. + diff --git a/libraries/MAX31855_RT/MAX31855.cpp b/libraries/MAX31855_RT/MAX31855.cpp index bf3cadf4..0059c587 100644 --- a/libraries/MAX31855_RT/MAX31855.cpp +++ b/libraries/MAX31855_RT/MAX31855.cpp @@ -1,37 +1,12 @@ // // FILE: MAX31855.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.4.1 +// VERSION: 0.4.2 // PURPOSE: Arduino library for MAX31855 chip for K type thermocouple // DATE: 2014-01-01 // URL: https://github.com/RobTillaart/MAX31855_RT // -// HISTORY: -// 0.4.1 2021-12-10 add SWSPI delay + getter/setter -// 0.4.0 2021-12-09 fix #21 breaking change for HW SPI -// move constructor code to begin() -// read() removed "premature" return on status. -// 0.3.0 2021-08-11 VSPI / HSPI support for ESP32 -// add setGIOpins - ESP32 specific -// add get/setSPIspeed() - all -// 0.2.5 2021-07-04 fix #14 CS for STM32 -// 0.2.4 2020-12-30 arduinoCI, unit test -// 0.2.3 2020-08-30 fix #8 support hardware SPI + example -// 0.2.2 2020-08-30 fix#9 + fix failing examples + minor refactor -// 0.2.1 2020-08-26 read rawData and STATUS_NO_COMMUNICATION recognition (thanks to FabioBrondo) -// 0.2.0 2020-06-20 #pragma once; major refactor; removed pre 1.0 support; fix offset -// 0.1.10 2019-07-31 add 3 inline functions to test errors + demo sketch -// 0.1.9 2017-07-27 reverted double -> float (issue33) -// 0.1.08 2015-12-06 replaced all temperature calls with one TCfactor + update demos. -// 0.1.07 2015-12-06 updated TC factors from the MAX31855 datasheet -// 0.1.06 2015-12-05 added support for other types of TC's (experimental) -// 0.1.05 2015-07-12 refactor robust constructor -// 0.1.04 2015-03-09 replaced float -> double (ARM support) -// 0.1.03 2014-01-24 fixed negative temperature -// 0.1.02 2014-01-03 added offset -// 0.1.01 2014-01-02 refactored speed/performance -// 0.1.00 2014-01-02 initial version. -// +// HISTORY: see changelog.md #include "MAX31855.h" @@ -70,19 +45,19 @@ void MAX31855::begin(const uint8_t clock, const uint8_t select, const uint8_t mi if (_hwSPI) { #if defined(ESP32) - if (_useHSPI) // HSPI + if (_useHSPI) // HSPI { mySPI = new SPIClass(HSPI); mySPI->end(); - mySPI->begin(14, 12, 13, _select); // CLK=14 MISO=12 MOSI=13 + mySPI->begin(14, 12, 13, _select); // CLK=14 MISO=12 MOSI=13 } - else // VSPI + else // VSPI { mySPI = new SPIClass(VSPI); mySPI->end(); - mySPI->begin(18, 19, 23, _select); // CLK=18 MISO=19 MOSI=23 + mySPI->begin(18, 19, 23, _select); // CLK=18 MISO=19 MOSI=23 } - #else // generic hardware SPI + #else // generic hardware SPI mySPI = &SPI; mySPI->end(); mySPI->begin(); @@ -123,21 +98,21 @@ void MAX31855::setGPIOpins(uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t se uint8_t MAX31855::read() { - // return value of _read() - // BITS DESCRIPTION - // ---------------------- - // 00 - 02 STATUS - // 03 RESERVED - // 04 - 15 INTERNAL - // 16 FAULT-BIT - // 17 RESERVED - // 18 - 30 TEMPERATURE (RAW) - // 31 SIGN + // return value of _read() + // BITS DESCRIPTION + // ------------------------------- + // 00 - 02 STATUS + // 03 RESERVED + // 04 - 15 INTERNAL + // 16 FAULT-BIT + // 17 RESERVED + // 18 - 30 TEMPERATURE (RAW) + // 31 SIGN uint32_t value = _read(); - if (value == 0xFFFFFFFF) // needs a pull up on MISO pin to work properly! + if (value == 0xFFFFFFFF) // needs a pull up on MISO pin to work properly! { - // bit 3 and bit 17 should always be 0 - P10 datasheet + // bit 3 and bit 17 should always be 0 - P10 datasheet _status = STATUS_NO_COMMUNICATION; return _status; } @@ -146,35 +121,35 @@ uint8_t MAX31855::read() // process status bit 0-2 _status = value & 0x0007; - // if (_status != STATUS_OK) // removed in 0.4.0 as internal can be valid. + // if (_status != STATUS_OK) // removed in 0.4.0 as internal can be valid. // { // return _status; // } value >>= 3; - // reserved bit 3, always 0 + // reserved bit 3, always 0 value >>= 1; - // process internal bit 4-15 + // process internal bit 4-15 _internal = (value & 0x07FF) * 0.0625; - // negative flag set ? + // negative flag set ? if (value & 0x0800) { _internal = -128 + _internal; } value >>= 12; - // Fault bit ignored as we have the 3 status bits - // _fault = value & 0x01; + // Fault bit ignored as we have the 3 status bits + // _fault = value & 0x01; value >>= 1; - // reserved bit 17, always 0 + // reserved bit 17, always 0 value >>= 1; - // process temperature bit 18-30 + sign bit = 31 + // process temperature bit 18-30 + sign bit = 31 _temperature = (value & 0x1FFF) * 0.25; - // negative flag set ? + // negative flag set ? if (value & 0x2000) { _temperature = -2048 + _temperature; @@ -186,7 +161,7 @@ uint8_t MAX31855::read() uint32_t MAX31855::_read(void) { _rawData = 0; - // DATA TRANSFER + // DATA TRANSFER if (_hwSPI) { mySPI->beginTransaction(_spi_settings); @@ -199,10 +174,10 @@ uint32_t MAX31855::_read(void) digitalWrite(_select, HIGH); mySPI->endTransaction(); } - else // Software SPI + else // Software SPI { - // split _swSPIdelay in equal dLow and dHigh - // dLow should be longer one when _swSPIdelay = odd. + // split _swSPIdelay in equal dLow and dHigh + // dLow should be longer one when _swSPIdelay = odd. uint16_t dHigh = _swSPIdelay/2; uint16_t dLow = _swSPIdelay - dHigh; digitalWrite(_select, LOW); @@ -210,10 +185,10 @@ uint32_t MAX31855::_read(void) { _rawData <<= 1; digitalWrite(_clock, LOW); - if (dLow > 0) delayMicroseconds(dLow); // DUE might need 1 us + if (dLow > 0) delayMicroseconds(dLow); // DUE might need 1 us if ( digitalRead(_miso) ) _rawData++; digitalWrite(_clock, HIGH); - if (dHigh > 0) delayMicroseconds(dHigh); // DUE + if (dHigh > 0) delayMicroseconds(dHigh); // DUE } digitalWrite(_select, HIGH); } @@ -224,18 +199,18 @@ uint32_t MAX31855::_read(void) float MAX31855::getTemperature() { - // offset needs to be added after multiplication TCfactor - // not before otherwise offset will be larger / smaller - // default behaviour + // offset needs to be added after multiplication TCfactor + // not before otherwise offset will be larger / smaller + // default behaviour if (_SeebeckC == K_TC) return _temperature + _offset; - // EXPERIMENTAL OTHER THERMOCOUPLES - // to be tested - // in practice this works also for K_TC but is way slower.. - // 1: reverse calculate the Voltage measured (is this correct?) - float Vout = K_TC * (_temperature - _internal); // PAGE 8 datasheet + // EXPERIMENTAL OTHER THERMOCOUPLES + // to be tested + // in practice this works also for K_TC but is way slower.. + // 1: reverse calculate the Voltage measured (is this correct?) + float Vout = K_TC * (_temperature - _internal); // PAGE 8 datasheet - // 2: from Voltage to corrected temperature using the Seebeck Coefficient + // 2: from Voltage to corrected temperature using the Seebeck Coefficient float _temp = Vout / _SeebeckC + _internal + _offset; return _temp; } diff --git a/libraries/MAX31855_RT/MAX31855.h b/libraries/MAX31855_RT/MAX31855.h index 178ec607..6413e0e1 100644 --- a/libraries/MAX31855_RT/MAX31855.h +++ b/libraries/MAX31855_RT/MAX31855.h @@ -2,30 +2,30 @@ // // FILE: MAX31855.h // AUTHOR: Rob Tillaart -// VERSION: 0.4.1 +// VERSION: 0.4.2 // PURPOSE: Arduino library for MAX31855 chip for K type thermocouple // DATE: 2014-01-01 // URL: https://github.com/RobTillaart/MAX31855_RT // http://forum.arduino.cc/index.php?topic=208061 -// Breakout board +// Breakout board // -// +---------+ -// Vin | o | -// 3V3 | o | -// GND | o O | Thermocouple -// D0 | o O | Thermocouple -// CS | o | -// CLK | o | -// +---------+ +// +---------+ +// Vin | o | +// 3V3 | o | +// GND | o O | Thermocouple +// D0 | o O | Thermocouple +// CS | o | +// CLK | o | +// +---------+ #include "Arduino.h" #include "SPI.h" -#define MAX31855_VERSION (F("0.4.1")) +#define MAX31855_VERSION (F("0.4.2")) #define MAX31855_NO_TEMPERATURE -999 @@ -71,7 +71,7 @@ public: // SW SPI void begin(uint8_t clock, uint8_t select, uint8_t miso); - // returns state - bit field: 0 = STATUS_OK + // returns state - bit field: 0 = STATUS_OK uint8_t read(); float getInternal(void) const { return _internal; } @@ -85,7 +85,7 @@ public: inline bool noRead() { return _status == STATUS_NOREAD; }; inline bool noCommunication() { return _status == STATUS_NO_COMMUNICATION; }; - // use offset to calibrate the TC. + // use offset to calibrate the TC. void setOffset(const float t) { _offset = t; }; float getOffset() const { return _offset; }; @@ -112,7 +112,7 @@ public: bool usesHSPI() { return _useHSPI; }; bool usesVSPI() { return !_useHSPI; }; - // to overrule ESP32 default hardware pins + // to overrule ESP32 default hardware pins void setGPIOpins(uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t select); #endif diff --git a/libraries/MAX31855_RT/README.md b/libraries/MAX31855_RT/README.md index 6d898f6b..938d2a77 100644 --- a/libraries/MAX31855_RT/README.md +++ b/libraries/MAX31855_RT/README.md @@ -27,14 +27,14 @@ other 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 | - +---------+ + +---------+ + Vin | o | + 3V3 | o | + GND | o O | Thermocouple + D0 | o O | Thermocouple + CS | o | + CLK | o | + +---------+ ``` @@ -62,7 +62,6 @@ Performance read() function, timing in us. (ESP32 @240MHz) | SW SPI | bit bang | ~500 | ~17 (!) | - ## Interface @@ -286,6 +285,13 @@ as one does not set the Seebeck Coefficient it will use the K_TC as default. ## Future +#### must + + +#### should - investigate other TC's - + +#### could + diff --git a/libraries/MAX31855_RT/library.json b/libraries/MAX31855_RT/library.json index 89b1febc..8f8e58c9 100644 --- a/libraries/MAX31855_RT/library.json +++ b/libraries/MAX31855_RT/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/MAX31855_RT" }, - "version": "0.4.1", + "version": "0.4.2", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/libraries/MAX31855_RT/library.properties b/libraries/MAX31855_RT/library.properties index 4c9ecd8c..449dc8db 100644 --- a/libraries/MAX31855_RT/library.properties +++ b/libraries/MAX31855_RT/library.properties @@ -1,5 +1,5 @@ name=MAX31855_RT -version=0.4.1 +version=0.4.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for MAX31855 chip for K type thermocouple. diff --git a/libraries/MAX31855_RT/test/unit_test_001.cpp b/libraries/MAX31855_RT/test/unit_test_001.cpp index 18f2de05..938b315b 100644 --- a/libraries/MAX31855_RT/test/unit_test_001.cpp +++ b/libraries/MAX31855_RT/test/unit_test_001.cpp @@ -36,32 +36,19 @@ #include "MAX31855.h" - unittest_setup() { + fprintf(stderr, "MAX31855_VERSION: %s\n", (char *) MAX31855_VERSION); } + unittest_teardown() { } -/* -unittest(test_new_operator) -{ - assertEqualINF(exp(800)); - assertEqualINF(0.0/0.0); - assertEqualINF(42); - - assertEqualNAN(INFINITY - INFINITY); - assertEqualNAN(0.0/0.0); - assertEqualNAN(42); -} -*/ unittest(test_constants) { - fprintf(stderr, "MAX31855_VERSION: %s\n", (char *) MAX31855_VERSION); - assertEqual(0x00, STATUS_OK); assertEqual(0x01, STATUS_OPEN_CIRCUIT); assertEqual(0x02, STATUS_SHORT_TO_GND); @@ -69,15 +56,13 @@ unittest(test_constants) assertEqual(0x07, STATUS_ERROR); assertEqual(0x80, STATUS_NOREAD); assertEqual(0x81, STATUS_NO_COMMUNICATION); - + assertEqual(-999, MAX31855_NO_TEMPERATURE); } unittest(test_status) { - fprintf(stderr, "MAX31855_VERSION: %s\n", (char *) MAX31855_VERSION); - const int doPin = 7; const int csPin = 6; const int clPin = 5; @@ -100,8 +85,6 @@ unittest(test_status) unittest(test_temperature) { - fprintf(stderr, "MAX31855_VERSION: %s\n", (char *) MAX31855_VERSION); - const int doPin = 7; const int csPin = 6; const int clPin = 5; @@ -122,7 +105,7 @@ unittest(test_temperature) } fprintf(stderr, "\nSeebeckCoefficient...\n"); - for (float sbc = 9; sbc < 100; sbc += 12.345) // non existent still good for test. + for (float sbc = 9; sbc < 100; sbc += 12.345) // non existent still good for test. { tc.setSeebeckCoefficient(sbc); fprintf(stderr, "%f\t", sbc); @@ -133,8 +116,6 @@ unittest(test_temperature) unittest(test_SPIspeed_SWSPIdelay) { - fprintf(stderr, "MAX31855_VERSION: %s\n", (char *) MAX31855_VERSION); - const int doPin = 7; const int csPin = 6; const int clPin = 5; @@ -162,4 +143,5 @@ unittest(test_SPIspeed_SWSPIdelay) unittest_main() -// -------- + +// -- END OF FILE --