From 93e2ad0613c22839092d37639f3ca54e56aa8f83 Mon Sep 17 00:00:00 2001 From: Zachariah Mears Date: Thu, 11 Jun 2026 08:21:48 -0700 Subject: [PATCH 1/4] Create initial library prototype --- .gitignore | 28 +++++ .travis.yml | 16 +++ LICENSE | 21 ++++ README.md | 72 +++++++++++++ TMP119.cpp | 85 +++++++++++++++ TMP119.h | 115 +++++++++++++++++++++ examples/TMP119_Example/TMP119_Example.ino | 87 ++++++++++++++++ library.properties | 9 ++ 8 files changed, 433 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 TMP119.cpp create mode 100644 TMP119.h create mode 100644 examples/TMP119_Example/TMP119_Example.ino create mode 100644 library.properties diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b8bd026 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..457512d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: python +python: + - "2.7" + +cache: + directories: + - "~/.platformio" + +env: + - PLATFORMIO_CI_SRC=examples/TMP119_Example/TMP119_Example.ino + +install: + - pip install -U platformio + +script: + - platformio ci --lib="." --board=uno --board=megaatmega2560 \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3d45124 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Blue Robotics + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index a1f3bd1..1393d74 100644 --- a/README.md +++ b/README.md @@ -1 +1,73 @@ # BlueRobotics TMP119 Temperature Sensor Library + +Arduino library for the TMP119 temperature sensor. The TMP119 is an ultra-high-accuracy, low-power digital temperature sensor from Texas Instruments with an I2C-compatible interface. + +# Documentation + +Please see the examples for normal operation. Below are the available functions used in the library. + +``` cpp +/** Construct an instance of the sensor manager. The TMP119 supports up to four + * I2C addresses (0x48 - 0x4B), selected by the ADD0 pin; the default address + * (ADD0 to GND) is 0x48. Uses the default Wire bus if left unspecified. + * (e.g. "TMP119 mySensor;" is equivilent to "TMP119 mySensor(0x48, &Wire);") + */ +TMP119(uint8_t address = 0x48, TwoWire *wire = &Wire); + +/** Initialize the sensor connection - return false if not detected. + * Configures the sensor for the fastest update rate (no averaging, shortest + * standby delay); call setAveraging()/setReadDelay() afterwards to override. + */ +bool init(); + +/** Reads the latest temperature conversion from the sensor. + */ +void read(); + +/** Temperature returned in deg C. + */ +float temperature(); + +/** Sets the conversion averaging mode (TMP119_AVERAGE_1X, _8X, _32X, _64X). + * More averaging reduces noise but lengthens the conversion cycle. + * Returns false if the I2C write fails. + */ +bool setAveraging(tmp119_average_count_t avg); + +/** Sets the minimum standby delay between conversions in continuous-conversion + * mode (TMP119_DELAY_0_MS, _125_MS, _250_MS, _500_MS, _1000_MS, _4000_MS, + * _8000_MS, _16000_MS). Returns false if the I2C write fails. + */ +bool setReadDelay(tmp119_delay_t delay); + +/** Reads / writes the raw 16-bit configuration register (address 0x01) + * for advanced use. + */ +uint16_t getConfig(); +bool setConfig(uint16_t config); + +``` + +The TMP119 runs in continuous-conversion mode, so `read()` always returns the +latest result. `init()` configures the sensor for the fastest update rate (no +averaging, shortest standby delay, ~15.5 ms cycle). To trade speed for lower +noise, call `setAveraging()` and `setReadDelay()` after `init()`; per the +datasheet (Table 8-6) the actual cycle time depends on both settings. + +``` cpp +TMP119 sensor; +sensor.init(); // fastest rate by default +sensor.setAveraging(TMP119_AVERAGE_64X); // 64-sample averaging +sensor.setReadDelay(TMP119_DELAY_1000_MS); // ~1 s standby between reads +``` + +See `examples/TMP119_Example` for a complete sketch that reads the sensor +and configures averaging and the read delay (with all options listed). + +# Versions + +- `1.0.0` - initial release + +# Reference + +You can find the [TMP119 datasheet here](https://www.ti.com/lit/ds/symlink/tmp119.pdf). diff --git a/TMP119.cpp b/TMP119.cpp new file mode 100644 index 0000000..98a58e4 --- /dev/null +++ b/TMP119.cpp @@ -0,0 +1,85 @@ +#include "TMP119.h" + +#define TMP119_TEMP_REG 0x00 +#define TMP119_CONFIG_REG 0x01 +#define TMP119_DEVICE_ID_REG 0x0F +#define TMP119_DEVICE_ID 0x2117 + +#define TMP119_CONV_SHIFT 7 +#define TMP119_CONV_MASK 0x0380 // CONV[2:0], bits 9:7 +#define TMP119_AVG_SHIFT 5 +#define TMP119_AVG_MASK 0x0060 // AVG[1:0], bits 6:5 + +TMP119::TMP119(uint8_t address, TwoWire *wire) { + _address = address; + _wire = wire; +} + +bool TMP119::init() { + // Verify the device by reading its ID register + _wire->beginTransmission(_address); + _wire->write(TMP119_DEVICE_ID_REG); + _wire->endTransmission(); + + if ( _wire->requestFrom(_address, (uint8_t)2) != 2 ) { + return false; + } + + uint16_t id = (_wire->read() << 8) | _wire->read(); + if ( id != TMP119_DEVICE_ID ) { + return false; + } + + // Configure for the fastest update rate: no averaging and the shortest + // standby delay, giving a ~15.5 ms conversion cycle (datasheet Table 8-6) + uint16_t config = getConfig(); + config &= ~(TMP119_AVG_MASK | TMP119_CONV_MASK); // AVG = 1X, delay = 0 ms + return setConfig(config); +} + +void TMP119::read() { + // The TMP119 powers up in continuous-conversion mode, so the + // temperature register always holds the most recent conversion. + _wire->beginTransmission(_address); + _wire->write(TMP119_TEMP_REG); + _wire->endTransmission(); + + _wire->requestFrom(_address, (uint8_t)2); + int16_t raw = (_wire->read() << 8) | _wire->read(); + + // Each LSB represents 0.0078125 deg C, data is in 2's complement format + TEMP = raw * 0.0078125f; +} + +float TMP119::temperature() { + return TEMP; +} + +uint16_t TMP119::getConfig() { + _wire->beginTransmission(_address); + _wire->write(TMP119_CONFIG_REG); + _wire->endTransmission(); + + _wire->requestFrom(_address, (uint8_t)2); + return (_wire->read() << 8) | _wire->read(); +} + +bool TMP119::setConfig(uint16_t config) { + _wire->beginTransmission(_address); + _wire->write(TMP119_CONFIG_REG); + _wire->write(config >> 8); // MSB first + _wire->write(config & 0xFF); // LSB + return _wire->endTransmission() == 0; +} + +bool TMP119::setAveraging(tmp119_average_count_t avg) { + uint16_t config = getConfig(); + config = (config & ~TMP119_AVG_MASK) | ((uint16_t)avg << TMP119_AVG_SHIFT); + return setConfig(config); +} + +bool TMP119::setReadDelay(tmp119_delay_t delay) { + uint16_t config = getConfig(); + config = (config & ~TMP119_CONV_MASK) | ((uint16_t)delay << TMP119_CONV_SHIFT); + return setConfig(config); +} diff --git a/TMP119.h b/TMP119.h new file mode 100644 index 0000000..653448d --- /dev/null +++ b/TMP119.h @@ -0,0 +1,115 @@ +/* Blue Robotics Arduino TMP119 Temperature Sensor Library +------------------------------------------------------------ + +Title: Blue Robotics Arduino TMP119 Temperature Sensor Library +Description: This library provides utilities to communicate with and to +read data from the Texas Instruments TMP119 high-accuracy temperature +sensor. +Authors: Rustom Jehangir, Blue Robotics Inc. + Jonathan Newman, Blue Robotics Inc. + Adam Šimko, Blue Robotics Inc. +------------------------------- +The MIT License (MIT) +Copyright (c) 2016 Blue Robotics Inc. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +-------------------------------*/ + +#ifndef TMP119_H_BLUEROBOTICS +#define TMP119_H_BLUEROBOTICS + +#include "Arduino.h" +#include + +/** Conversion averaging mode (AVG[1:0], configuration register bits 6:5). + * Determines how many conversions are accumulated and averaged before the + * temperature register updates. More averaging reduces noise but lengthens + * the conversion cycle. Power-on default: TMP119_AVERAGE_8X. + */ +typedef enum { + TMP119_AVERAGE_1X, // No averaging + TMP119_AVERAGE_8X, // 8 averaged conversions (power-on default) + TMP119_AVERAGE_32X, // 32 averaged conversions + TMP119_AVERAGE_64X, // 64 averaged conversions +} tmp119_average_count_t; + +/** Minimum standby delay between conversions in continuous-conversion mode + * (CONV[2:0], configuration register bits 9:7). This sets the standby time; + * the total conversion cycle time also depends on the averaging setting (see + * datasheet Table 8-6). Power-on default: TMP119_DELAY_1000_MS. + */ +typedef enum { + TMP119_DELAY_0_MS, + TMP119_DELAY_125_MS, + TMP119_DELAY_250_MS, + TMP119_DELAY_500_MS, + TMP119_DELAY_1000_MS, // power-on default + TMP119_DELAY_4000_MS, + TMP119_DELAY_8000_MS, + TMP119_DELAY_16000_MS, +} tmp119_delay_t; + +class TMP119 { +public: + + /** The TMP119 supports up to four I2C addresses (0x48 - 0x4B), selected + * by the ADD0 pin. The default address (ADD0 to GND) is 0x48. + */ + TMP119(uint8_t address = 0x48, TwoWire *wire = &Wire); + + /** Initialize the sensor connection - returns false if not detected. + * Configures the sensor for the fastest update rate (no averaging and + * the shortest standby delay). Call setAveraging() / setReadDelay() + * afterwards to override. + */ + bool init(); + + /** Reads the latest temperature conversion from the sensor. + */ + void read(); + + /** Temperature returned in deg C. + */ + float temperature(); + + /** Sets the conversion averaging mode. Returns false if the I2C write + * fails. Other configuration bits are preserved. + */ + bool setAveraging(tmp119_average_count_t avg); + + /** Sets the minimum standby delay between conversions in + * continuous-conversion mode. Returns false if the I2C write fails. + * Other configuration bits are preserved. + */ + bool setReadDelay(tmp119_delay_t delay); + + /** Reads the raw 16-bit configuration register (address 0x01). + */ + uint16_t getConfig(); + + /** Writes the raw 16-bit configuration register (address 0x01). Returns + * false if the I2C write fails. Read-only bits are ignored by the device. + */ + bool setConfig(uint16_t config); + +private: + TwoWire* _wire; + uint8_t _address; + float TEMP; + +}; + +#endif diff --git a/examples/TMP119_Example/TMP119_Example.ino b/examples/TMP119_Example/TMP119_Example.ino new file mode 100644 index 0000000..68eb0c5 --- /dev/null +++ b/examples/TMP119_Example/TMP119_Example.ino @@ -0,0 +1,87 @@ + +/* Blue Robotics TMP119 Library Example +----------------------------------------------------- + +Title: Blue Robotics TMP119 Library Example + +Description: This example demonstrates the TMP119 Library with a connected +sensor. It reads the sensor and prints the values to the serial terminal, +and shows how to configure the conversion averaging and the standby delay +between conversions. After init(), the sensor is set to its fastest update +rate; here we override that with heavy averaging and a 1 second cycle for +low-noise readings. + +The code is designed for the Arduino Uno board and can be compiled and +uploaded via the Arduino 1.0+ software. + +------------------------------- +The MIT License (MIT) + +Copyright (c) 2016 Blue Robotics Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +-------------------------------*/ + +#include +#include "TMP119.h" + +// Optional constructor parameters: TMP119(address, wire) +// address - I2C address set by the ADD0 pin (default 0x48): +// 0x48 (GND), 0x49 (V+), 0x4A (SDA), 0x4B (SCL) +// wire - I2C bus to use (default &Wire) +// e.g. "TMP119 sensor;" is equivalent to "TMP119 sensor(0x48, &Wire);" +TMP119 sensor(0x48, &Wire1); + +void setup() { + Serial.begin(9600); + Serial.println("Starting"); + + Wire1.begin(); + + while (!sensor.init()) { + Serial.println("TMP119 device failed to initialize!"); + delay(2000); + } + + // Override the fast defaults set by init() with low-noise settings: + // average 64 conversions and update roughly once per second. + // + // Averaging options (setAveraging): + // TMP119_AVERAGE_1X - no averaging (lowest noise rejection) + // TMP119_AVERAGE_8X - 8 averaged conversions + // TMP119_AVERAGE_32X - 32 averaged conversions + // TMP119_AVERAGE_64X - 64 averaged conversions (lowest noise) + // + // Standby delay options (setReadDelay): + // TMP119_DELAY_0_MS, TMP119_DELAY_125_MS, TMP119_DELAY_250_MS, + // TMP119_DELAY_500_MS, TMP119_DELAY_1000_MS, TMP119_DELAY_4000_MS, + // TMP119_DELAY_8000_MS, TMP119_DELAY_16000_MS + // (the resulting conversion cycle time depends on both settings, + // see datasheet Table 8-6) + //sensor.setAveraging(TMP119_AVERAGE_64X); + //sensor.setReadDelay(TMP119_DELAY_1000_MS); +} + +void loop() { + sensor.read(); + Serial.print("Temperature: "); + Serial.print(sensor.temperature()); + Serial.println(" deg C"); + //delay(1000); +} diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..cbf779d --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=BlueRobotics TMP119 Library +version=1.0.0 +author=BlueRobotics +maintainer=BlueRobotics +sentence=A simple and easy library for the TMP119 temperature sensor +paragraph=A simple and easy library for the TMP119 temperature sensor +category=Sensors +url=https://github.com/bluerobotics/BlueRobotics_TMP119_Library +architectures=* From 518aaa83584547bc077b534e904a5faca6be9362 Mon Sep 17 00:00:00 2001 From: Zachariah Mears Date: Thu, 11 Jun 2026 09:43:41 -0700 Subject: [PATCH 2/4] Fix CI and dates and names --- .github/workflows/test.yml | 30 ++++++++++++++++++++++ .travis.yml | 16 ------------ LICENSE | 2 +- TMP119.h | 6 ++--- examples/TMP119_Example/TMP119_Example.ino | 2 +- library.properties | 2 +- 6 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5f63eff --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Test + +on: ["pull_request", "push"] + +jobs: + Test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Cache PlatformIO + uses: actions/cache@v4 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + - name: Set up Python + uses: actions/setup-python@v5 + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + - name: Run PlatformIO + run: platformio ci --lib="." --board=uno --board=megaatmega2560 examples/TMP119_Example/*.ino diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 457512d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: python -python: - - "2.7" - -cache: - directories: - - "~/.platformio" - -env: - - PLATFORMIO_CI_SRC=examples/TMP119_Example/TMP119_Example.ino - -install: - - pip install -U platformio - -script: - - platformio ci --lib="." --board=uno --board=megaatmega2560 \ No newline at end of file diff --git a/LICENSE b/LICENSE index 3d45124..adbd1dd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 Blue Robotics +Copyright (c) 2026 Blue Robotics Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/TMP119.h b/TMP119.h index 653448d..e1cf122 100644 --- a/TMP119.h +++ b/TMP119.h @@ -5,12 +5,10 @@ Title: Blue Robotics Arduino TMP119 Temperature Sensor Library Description: This library provides utilities to communicate with and to read data from the Texas Instruments TMP119 high-accuracy temperature sensor. -Authors: Rustom Jehangir, Blue Robotics Inc. - Jonathan Newman, Blue Robotics Inc. - Adam Šimko, Blue Robotics Inc. +Authors: Zachariah Mears, Blue Robotics Inc. ------------------------------- The MIT License (MIT) -Copyright (c) 2016 Blue Robotics Inc. +Copyright (c) 2026 Blue Robotics Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/examples/TMP119_Example/TMP119_Example.ino b/examples/TMP119_Example/TMP119_Example.ino index 68eb0c5..66e667e 100644 --- a/examples/TMP119_Example/TMP119_Example.ino +++ b/examples/TMP119_Example/TMP119_Example.ino @@ -17,7 +17,7 @@ uploaded via the Arduino 1.0+ software. ------------------------------- The MIT License (MIT) -Copyright (c) 2016 Blue Robotics Inc. +Copyright (c) 2026 Blue Robotics Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/library.properties b/library.properties index cbf779d..6f7551d 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=BlueRobotics TMP119 Library version=1.0.0 -author=BlueRobotics +author=Zachariah Mears maintainer=BlueRobotics sentence=A simple and easy library for the TMP119 temperature sensor paragraph=A simple and easy library for the TMP119 temperature sensor From e9d327418d89f22505c319c280adc8c492c3e4d4 Mon Sep 17 00:00:00 2001 From: Zachariah Mears Date: Thu, 11 Jun 2026 10:19:35 -0700 Subject: [PATCH 3/4] Fix example and some comments --- TMP119.cpp | 3 ++- examples/TMP119_Example/TMP119_Example.ino | 18 ++++++------------ library.properties | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/TMP119.cpp b/TMP119.cpp index 98a58e4..c8cec1a 100644 --- a/TMP119.cpp +++ b/TMP119.cpp @@ -33,7 +33,8 @@ bool TMP119::init() { // Configure for the fastest update rate: no averaging and the shortest // standby delay, giving a ~15.5 ms conversion cycle (datasheet Table 8-6) uint16_t config = getConfig(); - config &= ~(TMP119_AVG_MASK | TMP119_CONV_MASK); // AVG = 1X, delay = 0 ms + // Cute trick to set all the values to zero to acheive AVG = 1X, delay = 0 ms + config &= ~(TMP119_AVG_MASK | TMP119_CONV_MASK); return setConfig(config); } diff --git a/examples/TMP119_Example/TMP119_Example.ino b/examples/TMP119_Example/TMP119_Example.ino index 66e667e..9ce1e2e 100644 --- a/examples/TMP119_Example/TMP119_Example.ino +++ b/examples/TMP119_Example/TMP119_Example.ino @@ -11,9 +11,6 @@ between conversions. After init(), the sensor is set to its fastest update rate; here we override that with heavy averaging and a 1 second cycle for low-noise readings. -The code is designed for the Arduino Uno board and can be compiled and -uploaded via the Arduino 1.0+ software. - ------------------------------- The MIT License (MIT) @@ -46,13 +43,13 @@ THE SOFTWARE. // 0x48 (GND), 0x49 (V+), 0x4A (SDA), 0x4B (SCL) // wire - I2C bus to use (default &Wire) // e.g. "TMP119 sensor;" is equivalent to "TMP119 sensor(0x48, &Wire);" -TMP119 sensor(0x48, &Wire1); +TMP119 sensor; void setup() { Serial.begin(9600); Serial.println("Starting"); - Wire1.begin(); + Wire.begin(); while (!sensor.init()) { Serial.println("TMP119 device failed to initialize!"); @@ -63,10 +60,7 @@ void setup() { // average 64 conversions and update roughly once per second. // // Averaging options (setAveraging): - // TMP119_AVERAGE_1X - no averaging (lowest noise rejection) - // TMP119_AVERAGE_8X - 8 averaged conversions - // TMP119_AVERAGE_32X - 32 averaged conversions - // TMP119_AVERAGE_64X - 64 averaged conversions (lowest noise) + // TMP119_AVERAGE_1X, TMP119_AVERAGE_8X, TMP119_AVERAGE_32X, TMP119_AVERAGE_64X // // Standby delay options (setReadDelay): // TMP119_DELAY_0_MS, TMP119_DELAY_125_MS, TMP119_DELAY_250_MS, @@ -74,8 +68,8 @@ void setup() { // TMP119_DELAY_8000_MS, TMP119_DELAY_16000_MS // (the resulting conversion cycle time depends on both settings, // see datasheet Table 8-6) - //sensor.setAveraging(TMP119_AVERAGE_64X); - //sensor.setReadDelay(TMP119_DELAY_1000_MS); + sensor.setAveraging(TMP119_AVERAGE_64X); + sensor.setReadDelay(TMP119_DELAY_1000_MS); } void loop() { @@ -83,5 +77,5 @@ void loop() { Serial.print("Temperature: "); Serial.print(sensor.temperature()); Serial.println(" deg C"); - //delay(1000); + delay(1000); } diff --git a/library.properties b/library.properties index 6f7551d..cbf779d 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=BlueRobotics TMP119 Library version=1.0.0 -author=Zachariah Mears +author=BlueRobotics maintainer=BlueRobotics sentence=A simple and easy library for the TMP119 temperature sensor paragraph=A simple and easy library for the TMP119 temperature sensor From fa70ea599665269e983615c1bd228af896d468e1 Mon Sep 17 00:00:00 2001 From: Zachariah Mears Date: Thu, 11 Jun 2026 14:07:48 -0700 Subject: [PATCH 4/4] Improve clarity around delay times and update licence headers --- README.md | 18 +++--- TMP119.cpp | 9 ++- TMP119.h | 65 +++++++++------------ examples/TMP119_Example/TMP119_Example.ino | 66 ++++++++-------------- 4 files changed, 70 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 1393d74..1843a4b 100644 --- a/README.md +++ b/README.md @@ -29,14 +29,14 @@ void read(); float temperature(); /** Sets the conversion averaging mode (TMP119_AVERAGE_1X, _8X, _32X, _64X). - * More averaging reduces noise but lengthens the conversion cycle. - * Returns false if the I2C write fails. + * More averaging reduces noise but takes longer per result (1X=15.5ms, + * 8X=125ms, 32X=500ms, 64X=1s). Returns false if the I2C write fails. */ bool setAveraging(tmp119_average_count_t avg); /** Sets the minimum standby delay between conversions in continuous-conversion - * mode (TMP119_DELAY_0_MS, _125_MS, _250_MS, _500_MS, _1000_MS, _4000_MS, - * _8000_MS, _16000_MS). Returns false if the I2C write fails. + * mode (TMP119_DELAY_NONE, TMP119_DELAY_125_MS, _250_MS, _500_MS, _1000_MS, + * _4000_MS, _8000_MS, _16000_MS). Returns false if the I2C write fails. */ bool setReadDelay(tmp119_delay_t delay); @@ -50,9 +50,13 @@ bool setConfig(uint16_t config); The TMP119 runs in continuous-conversion mode, so `read()` always returns the latest result. `init()` configures the sensor for the fastest update rate (no -averaging, shortest standby delay, ~15.5 ms cycle). To trade speed for lower -noise, call `setAveraging()` and `setReadDelay()` after `init()`; per the -datasheet (Table 8-6) the actual cycle time depends on both settings. +averaging, no added standby delay, ~15.5 ms cycle). To trade speed for lower +noise, call `setAveraging()` and `setReadDelay()` after `init()`. + +`setReadDelay()` sets only the *minimum* standby delay. The actual time between +readings is the greater of the averaging time and that standby delay (datasheet +Table 8-6). For example, `TMP119_AVERAGE_64X` always yields at least a ~1 s +cycle because the averaging alone takes 1 s, regardless of the delay setting. ``` cpp TMP119 sensor; diff --git a/TMP119.cpp b/TMP119.cpp index c8cec1a..9186372 100644 --- a/TMP119.cpp +++ b/TMP119.cpp @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2026 Blue Robotics Inc. + #include "TMP119.h" #define TMP119_TEMP_REG 0x00 @@ -30,10 +33,10 @@ bool TMP119::init() { return false; } - // Configure for the fastest update rate: no averaging and the shortest - // standby delay, giving a ~15.5 ms conversion cycle (datasheet Table 8-6) + // Configure for the fastest update rate: no averaging and no added standby + // delay, giving a ~15.5 ms conversion cycle (datasheet Table 8-6) uint16_t config = getConfig(); - // Cute trick to set all the values to zero to acheive AVG = 1X, delay = 0 ms + // Cute trick to set all the values to zero to acheive AVG = 1X, delay = none config &= ~(TMP119_AVG_MASK | TMP119_CONV_MASK); return setConfig(config); } diff --git a/TMP119.h b/TMP119.h index e1cf122..a3bb715 100644 --- a/TMP119.h +++ b/TMP119.h @@ -1,30 +1,13 @@ /* Blue Robotics Arduino TMP119 Temperature Sensor Library ------------------------------------------------------------- - -Title: Blue Robotics Arduino TMP119 Temperature Sensor Library -Description: This library provides utilities to communicate with and to -read data from the Texas Instruments TMP119 high-accuracy temperature -sensor. -Authors: Zachariah Mears, Blue Robotics Inc. -------------------------------- -The MIT License (MIT) -Copyright (c) 2026 Blue Robotics Inc. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. --------------------------------*/ + * + * This library provides utilities to communicate with and read data from the + * Texas Instruments TMP119 high-accuracy temperature sensor. + * + * Author: Zachariah Mears, Blue Robotics Inc. + * + * SPDX-License-Identifier: MIT + * Copyright (c) 2026 Blue Robotics Inc. + */ #ifndef TMP119_H_BLUEROBOTICS #define TMP119_H_BLUEROBOTICS @@ -34,23 +17,31 @@ THE SOFTWARE. /** Conversion averaging mode (AVG[1:0], configuration register bits 6:5). * Determines how many conversions are accumulated and averaged before the - * temperature register updates. More averaging reduces noise but lengthens - * the conversion cycle. Power-on default: TMP119_AVERAGE_8X. + * temperature register updates. More averaging reduces noise but takes longer + * to produce each result. The time to compute one averaged result is the + * per-mode minimum conversion time shown below (datasheet Table 8-6). + * Power-on default: TMP119_AVERAGE_8X. */ typedef enum { - TMP119_AVERAGE_1X, // No averaging - TMP119_AVERAGE_8X, // 8 averaged conversions (power-on default) - TMP119_AVERAGE_32X, // 32 averaged conversions - TMP119_AVERAGE_64X, // 64 averaged conversions + TMP119_AVERAGE_1X, // No averaging (min conversion time 15.5 ms) + TMP119_AVERAGE_8X, // 8 conversions (min conversion time 125 ms, default) + TMP119_AVERAGE_32X, // 32 conversions (min conversion time 500 ms) + TMP119_AVERAGE_64X, // 64 conversions (min conversion time 1 s) } tmp119_average_count_t; -/** Minimum standby delay between conversions in continuous-conversion mode - * (CONV[2:0], configuration register bits 9:7). This sets the standby time; - * the total conversion cycle time also depends on the averaging setting (see - * datasheet Table 8-6). Power-on default: TMP119_DELAY_1000_MS. +/** Minimum standby delay inserted between conversions in continuous-conversion + * mode (CONV[2:0], configuration register bits 9:7). + * + * This is not the actual time between readings on its own. The actual + * conversion cycle time is the greater of this standby delay and the time + * needed by the selected averaging mode (see tmp119_average_count_t). For + * example, TMP119_DELAY_NONE with TMP119_AVERAGE_64X still produces a ~1 s + * cycle because the 64x average alone takes 1 s. See datasheet Table 8-6. + * + * Power-on default: TMP119_DELAY_1000_MS. */ typedef enum { - TMP119_DELAY_0_MS, + TMP119_DELAY_NONE, // no added standby delay TMP119_DELAY_125_MS, TMP119_DELAY_250_MS, TMP119_DELAY_500_MS, diff --git a/examples/TMP119_Example/TMP119_Example.ino b/examples/TMP119_Example/TMP119_Example.ino index 9ce1e2e..cad015e 100644 --- a/examples/TMP119_Example/TMP119_Example.ino +++ b/examples/TMP119_Example/TMP119_Example.ino @@ -1,39 +1,17 @@ - /* Blue Robotics TMP119 Library Example ------------------------------------------------------ - -Title: Blue Robotics TMP119 Library Example - -Description: This example demonstrates the TMP119 Library with a connected -sensor. It reads the sensor and prints the values to the serial terminal, -and shows how to configure the conversion averaging and the standby delay -between conversions. After init(), the sensor is set to its fastest update -rate; here we override that with heavy averaging and a 1 second cycle for -low-noise readings. - -------------------------------- -The MIT License (MIT) - -Copyright (c) 2026 Blue Robotics Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. --------------------------------*/ + * + * This example demonstrates the TMP119 Library with a connected sensor. It + * reads the sensor and prints the values to the serial terminal, and shows how + * to configure the conversion averaging and the standby delay between + * conversions. After init(), the sensor is set to its fastest update rate; + * here we override that with heavy averaging and a 1 second cycle for low-noise + * readings. + * + * Designed for the Arduino Uno; compile and upload via the Arduino 1.0+ IDE. + * + * SPDX-License-Identifier: MIT + * Copyright (c) 2026 Blue Robotics Inc. + */ #include #include "TMP119.h" @@ -59,15 +37,21 @@ void setup() { // Override the fast defaults set by init() with low-noise settings: // average 64 conversions and update roughly once per second. // - // Averaging options (setAveraging): - // TMP119_AVERAGE_1X, TMP119_AVERAGE_8X, TMP119_AVERAGE_32X, TMP119_AVERAGE_64X + // Averaging options (setAveraging) and the time each takes per result: + // TMP119_AVERAGE_1X -> 15.5 ms + // TMP119_AVERAGE_8X -> 125 ms + // TMP119_AVERAGE_32X -> 500 ms + // TMP119_AVERAGE_64X -> 1 s // - // Standby delay options (setReadDelay): - // TMP119_DELAY_0_MS, TMP119_DELAY_125_MS, TMP119_DELAY_250_MS, + // Minimum standby delay options (setReadDelay): + // TMP119_DELAY_NONE, TMP119_DELAY_125_MS, TMP119_DELAY_250_MS, // TMP119_DELAY_500_MS, TMP119_DELAY_1000_MS, TMP119_DELAY_4000_MS, // TMP119_DELAY_8000_MS, TMP119_DELAY_16000_MS - // (the resulting conversion cycle time depends on both settings, - // see datasheet Table 8-6) + // + // The actual time between readings is the greater of the averaging time + // above and the standby delay (datasheet Table 8-6). So 64x averaging with + // TMP119_DELAY_1000_MS gives ~1 s, but 64x with TMP119_DELAY_NONE is also + // ~1 s since the averaging itself takes 1 s. sensor.setAveraging(TMP119_AVERAGE_64X); sensor.setReadDelay(TMP119_DELAY_1000_MS); }