├── .gitignore ├── .travis.yml ├── ISSUE_TEMPLATE.md ├── LICENSE.md ├── README.md ├── examples ├── Example1_BasicReadings │ └── Example1_BasicReadings.ino ├── Example2_AlertStatuses │ └── Example2_AlertStatuses.ino ├── Example3_SetOffsetTemperatureValue │ └── Example3_SetOffsetTemperatureValue.ino ├── Example4_SetConversionMode │ └── Example4_SetConversionMode.ino ├── Example5_SetAlertModeTemperatureLimits │ └── Example5_SetAlertModeTemperatureLimits.ino ├── Example6_SetConversionCycleTime │ └── Example6_SetConversionCycleTime.ino └── Example7_AdvancedI2CFunctions │ └── Example7_AdvancedI2CFunctions.ino ├── keywords.txt ├── library.properties └── src ├── SparkFun_TMP117.cpp ├── SparkFun_TMP117.h └── SparkFun_TMP117_Registers.h /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/* 2 | *.bin 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | before_install: 3 | - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16" 4 | - sleep 3 5 | - export DISPLAY=:1.0 6 | - wget http://downloads.arduino.cc/arduino-1.8.9-linux64.tar.xz 7 | - tar xf arduino-1.8.9-linux64.tar.xz 8 | - sudo mv arduino-1.8.9 /usr/local/share/arduino 9 | - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino 10 | 11 | # Arduino IDE adds a lot of noise caused by network traffic, trying to firewall it off 12 | - sudo iptables -P INPUT DROP 13 | - sudo iptables -P FORWARD DROP 14 | - sudo iptables -P OUTPUT ACCEPT 15 | - sudo iptables -A INPUT -i lo -j ACCEPT 16 | - sudo iptables -A OUTPUT -o lo -j ACCEPT 17 | - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 18 | 19 | install: 20 | - ln -s $PWD /usr/local/share/arduino/libraries/SparkFun_TMP117_Arduino_Library 21 | - arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json,https://adafruit.github.io/arduino-board-index/package_adafruit_index.json" --save-prefs 3>&1 22 | - arduino --install-boards SparkFun:samd 23 | - arduino --install-boards SparkFun:apollo3 24 | - arduino --install-boards SparkFun:avr 25 | - arduino --install-boards adafruit:avr 26 | 27 | script: 28 | #compile for SparkFun RedBoard 29 | - echo Compiling for SparkFun RedBoard... 30 | - arduino --verify --board SparkFun:avr:RedBoard $PWD/examples/Example1_BasicReadings/Example1_BasicReadings.ino 31 | - arduino --verify --board SparkFun:avr:RedBoard $PWD/examples/Example2_AlertStatuses/Example2_AlertStatuses.ino 32 | - arduino --verify --board SparkFun:avr:RedBoard $PWD/examples/Example3_SetOffsetTemperatureValue/Example3_SetOffsetTemperatureValue.ino 33 | - arduino --verify --board SparkFun:avr:RedBoard $PWD/examples/Example4_SetConversionMode/Example4_SetConversionMode.ino 34 | - arduino --verify --board SparkFun:avr:RedBoard $PWD/examples/Example5_SetAlertModeTemperatureLimits/Example5_SetAlertModeTemperatureLimits.ino 35 | - arduino --verify --board SparkFun:avr:RedBoard $PWD/examples/Example6_SetConversionCycleTime/Example6_SetConversionCycleTime.ino 36 | # - arduino --verify --board SparkFun:avr:RedBoard $PWD/examples/Example7_AdvancedI2CFunctions/Example7_AdvancedI2CFunctions.ino 37 | 38 | #compile for SparkFun Artemis 39 | - echo Compiling for SparkFun Artemis... 40 | - arduino --verify --board SparkFun:apollo3:amap3redboard $PWD/examples/Example1_BasicReadings/Example1_BasicReadings.ino 41 | - arduino --verify --board SparkFun:apollo3:amap3redboard $PWD/examples/Example2_AlertStatuses/Example2_AlertStatuses.ino 42 | - arduino --verify --board SparkFun:apollo3:amap3redboard $PWD/examples/Example3_SetOffsetTemperatureValue/Example3_SetOffsetTemperatureValue.ino 43 | - arduino --verify --board SparkFun:apollo3:amap3redboard $PWD/examples/Example4_SetConversionMode/Example4_SetConversionMode.ino 44 | - arduino --verify --board SparkFun:apollo3:amap3redboard $PWD/examples/Example5_SetAlertModeTemperatureLimits/Example5_SetAlertModeTemperatureLimits.ino 45 | - arduino --verify --board SparkFun:apollo3:amap3redboard $PWD/examples/Example6_SetConversionCycleTime/Example6_SetConversionCycleTime.ino 46 | - arduino --verify --board SparkFun:apollo3:amap3redboard $PWD/examples/Example7_AdvancedI2CFunctions/Example7_AdvancedI2CFunctions.ino 47 | 48 | #compile for SparkFun SAMD 49 | - echo Compiling for SparkFun SAMD... 50 | - arduino --verify --board SparkFun:samd:samd51_thing_plus $PWD/examples/Example1_BasicReadings/Example1_BasicReadings.ino 51 | - arduino --verify --board SparkFun:samd:samd51_thing_plus $PWD/examples/Example2_AlertStatuses/Example2_AlertStatuses.ino 52 | - arduino --verify --board SparkFun:samd:samd51_thing_plus $PWD/examples/Example3_SetOffsetTemperatureValue/Example3_SetOffsetTemperatureValue.ino 53 | - arduino --verify --board SparkFun:samd:samd51_thing_plus $PWD/examples/Example4_SetConversionMode/Example4_SetConversionMode.ino 54 | - arduino --verify --board SparkFun:samd:samd51_thing_plus $PWD/examples/Example5_SetAlertModeTemperatureLimits/Example5_SetAlertModeTemperatureLimits.ino 55 | - arduino --verify --board SparkFun:samd:samd51_thing_plus $PWD/examples/Example6_SetConversionCycleTime/Example6_SetConversionCycleTime.ino 56 | # - arduino --verify --board SparkFun:samd:samd51_thing_plus $PWD/examples/Example7_AdvancedI2CFunctions/Example7_AdvancedI2CFunctions.ino 57 | 58 | #compile for Adafruit Pro Trinket 5 59 | - echo Compiling for AdaFruit Pro Trinket 5... 60 | - arduino --verify --board adafruit:avr:protrinket5 $PWD/examples/Example1_BasicReadings/Example1_BasicReadings.ino 61 | - arduino --verify --board adafruit:avr:protrinket5 $PWD/examples/Example2_AlertStatuses/Example2_AlertStatuses.ino 62 | - arduino --verify --board adafruit:avr:protrinket5 $PWD/examples/Example3_SetOffsetTemperatureValue/Example3_SetOffsetTemperatureValue.ino 63 | - arduino --verify --board adafruit:avr:protrinket5 $PWD/examples/Example4_SetConversionMode/Example4_SetConversionMode.ino 64 | - arduino --verify --board adafruit:avr:protrinket5 $PWD/examples/Example5_SetAlertModeTemperatureLimits/Example5_SetAlertModeTemperatureLimits.ino 65 | - arduino --verify --board adafruit:avr:protrinket5 $PWD/examples/Example6_SetConversionCycleTime/Example6_SetConversionCycleTime.ino 66 | # - arduino --verify --board adafruit:avr:protrinket5 $PWD/examples/Example7_AdvancedI2CFunctions/Example7_AdvancedI2CFunctions.ino -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Subject of the issue 2 | Describe your issue here. 3 | 4 | ### Your workbench 5 | * What development board or microcontroller are you using? 6 | * What version of hardware or breakout board are you using? 7 | * How is the breakout board wired to your microcontroller? 8 | * How is everything being powered? 9 | * Are there any additional details that may help us help you? 10 | 11 | ### Steps to reproduce 12 | Tell us how to reproduce this issue. Please post stripped down example code demonstrating your issue. 13 | 14 | ### Expected behavior 15 | Tell us what should happen 16 | 17 | ### Actual behavior 18 | Tell us what happens instead 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | SparkFun License Information 2 | ============================ 3 | 4 | SparkFun uses two different licenses for our files — one for hardware and one for code. 5 | 6 | Hardware 7 | --------- 8 | 9 | **SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).** 10 | 11 | Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode). 12 | 13 | You are free to: 14 | 15 | Share — copy and redistribute the material in any medium or format 16 | Adapt — remix, transform, and build upon the material 17 | for any purpose, even commercially. 18 | The licensor cannot revoke these freedoms as long as you follow the license terms. 19 | Under the following terms: 20 | 21 | Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. 22 | ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. 23 | No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. 24 | Notices: 25 | 26 | You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation. 27 | No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material. 28 | 29 | 30 | Code 31 | -------- 32 | 33 | **SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).** 34 | 35 | The MIT License (MIT) 36 | 37 | Copyright (c) 2016 SparkFun Electronics 38 | 39 | Permission is hereby granted, free of charge, to any person obtaining a copy 40 | of this software and associated documentation files (the "Software"), to deal 41 | in the Software without restriction, including without limitation the rights 42 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 43 | copies of the Software, and to permit persons to whom the Software is 44 | furnished to do so, subject to the following conditions: 45 | 46 | The above copyright notice and this permission notice shall be included in all 47 | copies or substantial portions of the Software. 48 | 49 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 50 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 51 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 52 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 53 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 54 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 55 | SOFTWARE. 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SparkFun TMP117 Arduino Library 2 | ======================================== 3 | 4 | [![SparkFun High Precision Temperature Sensor - TMP117 (Qwiic)](https://cdn.sparkfun.com//assets/parts/1/4/4/3/0/15805-SparkFun_High_Precision_Temperature_Sensor_-_TMP117__Qwiic_-01.jpg)](https://www.sparkfun.com/products/15805) 5 | 6 | [*SparkFun High Precision Temperature Sensor - TMP117 (Qwiic) (SEN-15805)*](https://www.sparkfun.com/products/15805) 7 | 8 | The TMP117 is a high precision temperature Sensor with accuracy of up to +/-0.1 degrees celsius and an operating temperature range of -55°C to +150°C. It is NIST traceable and verified with equipment that is calibrated to ISO/IEC 17025 accredited standards. It has a very low power consumption with a supply range of 1.8V to 5.5V. 9 | 10 | The TMP117 address can be changed with an external jumper to 4 different addresses. There are 4 different conversion modes that it can read from, with continuous conversion, shutdown, and one shot conversion. There is also digital offset for system correction, programmable temperature limits, General-Purpose EEPROM, and selectable averaging. 11 | 12 | SparkFun labored with love to create this code. Feel like supporting open source hardware? 13 | Buy a [board](https://www.sparkfun.com/products/15805) from SparkFun! 14 | 15 | Repository Contents 16 | ------------------- 17 | 18 | * **/examples** - Example code to be used in the Arduino IDE. 19 | * **/src** - Source files for the library (.cpp, .h). 20 | * **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE. 21 | * **libaray.properties** - General library properties for the Arduino package manager 22 | 23 | Documentation 24 | -------------- 25 | 26 | * **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library. 27 | * **[Product Repository](https://github.com/sparkfun/SparkFun_High_Precision_Temperature_Sensor_TMP117_Qwiic)** - Main repository (including hardware files) 28 | * **[Hookup Guide](https://learn.sparkfun.com/tutorials/qwiic-tmp117-high-precision-digital-temperature-sensor-hookup-guide)** - Basic hookup guide for the SparkFun High Precision Temperature Sensor TMP117 (Qwiic). 29 | 30 | Products that use this Repository 31 | -------------- 32 | 33 | * [SEN-13166](https://www.sparkfun.com/products/15805)- SparkFun Version 34 | * [SPX-15413](https://www.sparkfun.com/products/15413)- SparkX Version 35 | 36 | License Information 37 | ------------------- 38 | 39 | This product is _**open source**_! 40 | 41 | Please review the LICENSE.md file for license information. 42 | 43 | If you have any questions or concerns on licensing, please contact technical support on our [SparkFun forums](https://forum.sparkfun.com/viewforum.php?f=152). 44 | 45 | Distributed as-is; no warranty is given. 46 | 47 | - Your friends at SparkFun. 48 | 49 | __ 50 | -------------------------------------------------------------------------------- /examples/Example1_BasicReadings/Example1_BasicReadings.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Example1_BasicReadings.ino 3 | Example for the TMP117 I2C Temperature Sensor 4 | Madison Chodikov @ SparkFun Electronics 5 | May 29 2019 6 | ~ 7 | 8 | This sketch configures the TMP117 temperature sensor and prints the 9 | temperature in degrees celsius and fahrenheit with a 500ms delay for 10 | easier readings. 11 | 12 | Resources: 13 | Wire.h (included with Arduino IDE) 14 | SparkFunTMP117.h (included in the src folder) http://librarymanager/All#SparkFun_TMP117 15 | 16 | Development environment specifics: 17 | Arduino 1.8.9+ 18 | Hardware Version 1.0.0 19 | 20 | This code is beerware; if you see me (or any other SparkFun employee) at 21 | the local, and you've found our code helpful, please buy us a round! 22 | 23 | Distributed as-is; no warranty is given. 24 | ******************************************************************************/ 25 | 26 | /* 27 | NOTE: For the most accurate readings: 28 | - Avoid heavy bypass traffic on the I2C bus 29 | - Use the highest available communication speeds 30 | - Use the minimal supply voltage acceptable for the system 31 | - Place device horizontally and out of any airflow when storing 32 | For more information on reaching the most accurate readings from the sensor, 33 | reference the "Precise Temperature Measurements with TMP116" datasheet that is 34 | linked on Page 35 of the TMP117's datasheet 35 | */ 36 | 37 | #include // Used to establish serial communication on the I2C bus 38 | #include // Used to send and recieve specific information from our sensor 39 | 40 | // The default address of the device is 0x48 = (GND) 41 | TMP117 sensor; // Initalize sensor 42 | 43 | void setup() 44 | { 45 | Wire.begin(); 46 | Serial.begin(115200); // Start serial communication at 115200 baud 47 | Wire.setClock(400000); // Set clock speed to be the fastest for better communication (fast mode) 48 | 49 | Serial.println("TMP117 Example 1: Basic Readings"); 50 | if (sensor.begin() == true) // Function to check if the sensor will correctly self-identify with the proper Device ID/Address 51 | { 52 | Serial.println("Begin"); 53 | } 54 | else 55 | { 56 | Serial.println("Device failed to setup- Freezing code."); 57 | while (1); // Runs forever 58 | } 59 | } 60 | 61 | void loop() 62 | { 63 | // Data Ready is a flag for the conversion modes - in continous conversion the dataReady flag should always be high 64 | if (sensor.dataReady() == true) // Function to make sure that there is data ready to be printed, only prints temperature values when data is ready 65 | { 66 | float tempC = sensor.readTempC(); 67 | float tempF = sensor.readTempF(); 68 | // Print temperature in °C and °F 69 | Serial.println(); // Create a white space for easier viewing 70 | Serial.print("Temperature in Celsius: "); 71 | Serial.println(tempC); 72 | Serial.print("Temperature in Fahrenheit: "); 73 | Serial.println(tempF); 74 | delay(500); // Delay added for easier readings 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /examples/Example2_AlertStatuses/Example2_AlertStatuses.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Example2_AlertStatuses.ino 3 | Example for the TMP117 I2C Temperature Sensor 4 | Modified by: Ho Yun "Bobby" Chan @ SparkFun Electronics 5 | Date Modified: November 12, 2019 6 | Written by: Madison Chodikov @ SparkFun Electronics 7 | Date: May 29 2019 8 | ~ 9 | 10 | This sketch sets the TMP117 temperature sensor's high limit, 11 | low limit, and alert function mode. Once set, we read the 12 | temperature in °C and checks alert status. If we are outside 13 | of the boundary, we will output a message indicating 14 | that we are beyond the limit. The alert statuses is dependent 15 | on the mode so make sure to 16 | 17 | 18 | Resources: 19 | Wire.h (included with Arduino IDE) 20 | SparkFunTMP117.h (included in the src folder) http://librarymanager/All#SparkFun_TMP117 21 | 22 | Development environment specifics: 23 | Arduino 1.8.9+ 24 | Hardware Version 1.0.0 25 | 26 | This code is beerware; if you see me (or any other SparkFun employee) at 27 | the local, and you've found our code helpful, please buy us a round! 28 | 29 | Distributed as-is; no warranty is given. 30 | ******************************************************************************/ 31 | 32 | /* 33 | NOTE: For the most accurate readings: 34 | - Avoid heavy bypass traffic on the I2C bus 35 | - Use the highest available communication speeds 36 | - Use the minimal supply voltage acceptable for the system 37 | - Place device horizontally and out of any airflow when storing 38 | For more information on reaching the most accurate readings from the sensor, 39 | reference the "Precise Temperature Measurements with TMP116" datasheet that is 40 | linked on Page 35 of the TMP117's datasheet 41 | */ 42 | 43 | #include // Used to establish serial communication on the I2C bus 44 | #include // Used to send and recieve specific information from our sensor 45 | 46 | // The default address of the device is 0x48 (GND) 47 | TMP117 sensor; // Initalize sensor 48 | 49 | byte AlertFlag = 0; //variable to hold high and low alert flags from configuration register 50 | boolean H_AlertFlag = 0; //variable to hold state of high alert flag 51 | boolean L_AlertFlag = 0; //variable to hold state of low alert flag 52 | 53 | void setup() 54 | { 55 | Wire.begin(); 56 | Serial.begin(115200); // Start serial communication at 115200 baud 57 | Wire.setClock(400000); // Set clock speed to be the fastest for better communication (fast mode) 58 | Serial.println("TMP117 Example 2: Alert Statuses"); 59 | if (sensor.begin() == true) // Function to check if the sensor will correctly self-identify with the proper Device ID/Address 60 | { 61 | Serial.println("Begin"); 62 | } 63 | else 64 | { 65 | Serial.println("Device failed to setup- Freezing code."); 66 | while (1); 67 | } 68 | 69 | Serial.println(""); 70 | Serial.println("Note: Make sure to configure the your High and"); 71 | Serial.println("Low Temperature Limits. These values will"); 72 | Serial.println("be cleared on power cycle since it is only"); 73 | Serial.println("saved in the volatile registers. This code"); 74 | Serial.println("sets it manually. You can look at Example 5"); 75 | Serial.println("in the library for more ideas!"); 76 | 77 | /*Note: Set the high and low limits. Make sure to set limits 78 | between -256°C and 255.99°C. For quick testing at room 79 | temperature that is about 20°C-25°C, we can use the heat 80 | from our hand or lightly breathing on the sensor. Adjust 81 | as necessary.*/ 82 | sensor.setHighLimit(25.50); //set high limit to 25.50°C 83 | sensor.setLowLimit(25.00); //set low limit to 25.00°C 84 | 85 | //Get High Temperature Limit 86 | Serial.println(""); 87 | Serial.print("High Temperature Limit: "); 88 | Serial.print(sensor.getHighLimit()); 89 | Serial.println("°C"); 90 | 91 | //Get Low Temperature Limit 92 | Serial.print("Low Temperature Limit: "); 93 | Serial.print(sensor.getLowLimit()); 94 | Serial.print("°C"); 95 | Serial.println(""); 96 | 97 | /*Note: Set to alert or therm mode. To change, simply adjust 98 | add or remove a `//` to the line.*/ 99 | sensor.setAlertFunctionMode(0);//set to alert mode 100 | //sensor.setAlertFunctionMode(1);//set to therm mode 101 | 102 | /*Get "Alert Function Mode" Bit from configuration register 103 | Note: Depending on the mode, this affects the way HIGH and 104 | LOW Alert Fields behave in the Configuration Register. For more 105 | information, check out the following sections of the datasheet: 106 | 7.4.4.1 Alert Mode (pg 14) 107 | 7.4.4.2 Therm Mode (pg 16) 108 | 7.6.1.2 Configuration Register (pg 26) 109 | */ 110 | delay(500);//wait a little before grabbing current mode 111 | Serial.print("Alert Function Mode = "); 112 | Serial.println(sensor.getAlertFunctionMode()); 113 | Serial.println("----------------------------------------"); //start checking temp and alert flags after this line 114 | } 115 | 116 | /* Alert statuses below for high or low temperature reading 117 | possibilities: High Alert = 256°C, Low Alert = -256°C*/ 118 | void loop() 119 | { 120 | // Data Ready is a flag for the conversion modes - in continous conversion the dataReady flag should always be high 121 | if (sensor.dataReady() == true) // Function to make sure that there is data ready to be printed, only prints temperature values when data is ready 122 | { 123 | /*Note: If you are in Alert Mode (T/nA = 0), the high and low alert 124 | flags will clear whenever you read the configuration register. You 125 | can add a delay to to perform another temperature conversion to trigger the 126 | flags again. The delay depends on the conversion cycle time so make 127 | sure to adjust as necessary to check the if the flags are triggered. 128 | */ 129 | Serial.println(""); 130 | Serial.print("Current Temperature: "); 131 | Serial.print(sensor.readTempC()); 132 | Serial.println("°C"); 133 | /*Note: Add short delay before reading the again configuration register 134 | adjust this value as necessary based on your conversion cycle time. 135 | Default conversion time for AVG = 1 and CONV = 4 about 1 second. Therefore, 136 | a value of between 1-3 seconds should be sufficient.*/ 137 | delay(1500);//wait a little before grabbing 138 | 139 | AlertFlag = sensor.getHighLowAlert(); //read the alert flags from the configuration register 140 | H_AlertFlag = bitRead(AlertFlag, 1); //grab the high alert field using bitwise operator and save current to H_AlertFlag 141 | L_AlertFlag = bitRead(AlertFlag, 0); //grab the low alert field using bitwise operator and save current L_AlertFlag 142 | 143 | //output byte and bits, Arduino will not output leading 0's toward the MSB 144 | Serial.print("High and Low Alert Flags = "); 145 | Serial.println(AlertFlag, BIN); 146 | Serial.print("High Alert Flag = "); 147 | Serial.println(H_AlertFlag, BIN); 148 | Serial.print("Low Alert Flag = "); 149 | Serial.println(L_AlertFlag, BIN); 150 | 151 | if (H_AlertFlag == true) 152 | { 153 | /*Alert when the temperature is over the HIGH limit: 154 | - In Alert Mode (T/nA = 0) this flag will clear 155 | when the configuration register is read. 156 | - In Therm mode (T/nA = 1), this flag will clear ONLY 157 | when we have reached the lower limit. This high and 158 | low limits act as a hystersis. 159 | */ 160 | Serial.println("High Alert"); 161 | } 162 | else if (L_AlertFlag == true) 163 | { 164 | /*Alert when the temperature is over the LOW limit: 165 | - In Alert Mode (T/nA = 0) this flag will clear 166 | when the configuration register is read. 167 | - In Therm mode (T/nA = 1), this flag is always 0 168 | */ 169 | Serial.println("Low Alert"); 170 | } 171 | else 172 | { 173 | Serial.println("No Alert"); 174 | } 175 | delay(500); // Delay for a 1/2 second before printing again if the data is ready 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /examples/Example3_SetOffsetTemperatureValue/Example3_SetOffsetTemperatureValue.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Example3_SetOffsetTemperatureValue.ino 3 | Example for the TMP117 I2C Temperature Sensor 4 | Madison Chodikov @ SparkFun Electronics 5 | May 29 2019 6 | ~ 7 | 8 | This sketch configures the TMP117 temperature sensor and allows the user to 9 | set the offset temperature for System Correction. 10 | 11 | Resources: 12 | Wire.h (included with Arduino IDE) 13 | SparkFunTMP117.h (included in the src folder) http://librarymanager/All#SparkFun_TMP117 14 | 15 | Development environment specifics: 16 | Arduino 1.8.9+ 17 | Hardware Version 1.0.0 18 | 19 | This code is beerware; if you see me (or any other SparkFun employee) at 20 | the local, and you've found our code helpful, please buy us a round! 21 | 22 | Distributed as-is; no warranty is given. 23 | ******************************************************************************/ 24 | 25 | /* 26 | NOTE: For the most accurate readings: 27 | - Avoid heavy bypass traffic on the I2C bus 28 | - Use the highest available communication speeds 29 | - Use the minimal supply voltage acceptable for the system 30 | - Place device horizontally and out of any airflow when storing 31 | For more information on reaching the most accurate readings from the sensor, 32 | reference the "Precise Temperature Measurements with TMP116" datasheet that is 33 | linked on Page 35 of the TMP117's datasheet 34 | */ 35 | 36 | #include // Used to establish serial communication on the I2C bus 37 | #include // Used to send and recieve specific information from our sensor 38 | 39 | // The default address of the device is 0x48 (GND) 40 | TMP117 sensor; // Initalize sensor 41 | 42 | 43 | void setup() 44 | { 45 | Wire.begin(); 46 | Serial.begin(115200); // Start serial communication at 115200 baud 47 | Wire.setClock(400000); // Set clock speed to be the fastest for better communication (fast mode) 48 | 49 | Serial.println("TMP117 Example 3: Set Temperature Offset Value"); 50 | if (sensor.begin() == true) // Function to check if the sensor will correctly self-identify with the proper Device ID/Address 51 | { 52 | Serial.println("Begin"); 53 | } 54 | else 55 | { 56 | Serial.println("Device failed to setup- Freezing code."); 57 | while (1); 58 | } 59 | 60 | Serial.println(); // Create a new line for the loop for easier readings 61 | Serial.print("Current Temperature Offset (in °C): "); 62 | Serial.println(sensor.getTemperatureOffset()); 63 | } 64 | 65 | 66 | // For function to work properly, make sure the Serial Monitor is set to "No Line Ending" 67 | // The temperature offset function will not work if set outside the sensors bounds of +/- 255.98°C 68 | void loop() 69 | { 70 | float tempOffset = 0; 71 | if (sensor.dataReady() == true) // Only prints when there is data ready from the temperature sensor 72 | { 73 | Serial.print("Enter new temperature offset (in °C): "); 74 | while (Serial.available() == 0); // Waits for the user input 75 | tempOffset = Serial.parseFloat(); // Reads the input from the serial port, adds 1 for precision 76 | Serial.println(tempOffset); 77 | if (tempOffset > 255.98 || tempOffset < -255.98) 78 | { 79 | Serial.println("Please enter a number within the range of +/-255.98°C"); 80 | Serial.println(); 81 | } 82 | else 83 | { 84 | sensor.setTemperatureOffset(tempOffset); // Write to the temperature offset register 85 | delay(1000); // Delay for conversion to successfully work 86 | Serial.println(); // Create a new line after each run of the loop 87 | Serial.print("New Offset Temperature: "); 88 | Serial.print(sensor.getTemperatureOffset()); // Print the new temperature offset 89 | Serial.println("°C"); 90 | Serial.print("Temperature with Offset: "); 91 | Serial.print(sensor.readTempC()); 92 | Serial.println("°C"); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /examples/Example4_SetConversionMode/Example4_SetConversionMode.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Example4_SetConversionMode.ino 3 | Example for the TMP117 I2C Temperature Sensor 4 | Madison Chodikov @ SparkFun Electronics 5 | May 29 2019 6 | ~ 7 | 8 | This sketch can get and set the conversion mode that the temperature sensor can be in, 9 | which is Continuous Conversion, Shutdown, or One-Shot. The specific values for these 10 | are found below at the end of the comments section. 11 | 12 | Resources: 13 | Wire.h (included with Arduino IDE) 14 | SparkFunTMP117.h (included in the src folder) http://librarymanager/All#SparkFun_TMP117 15 | 16 | Development environment specifics: 17 | Arduino 1.8.9+ 18 | Hardware Version 1.0.0 19 | 20 | This code is beerware; if you see me (or any other SparkFun employee) at 21 | the local, and you've found our code helpful, please buy us a round! 22 | 23 | Distributed as-is; no warranty is given. 24 | ******************************************************************************/ 25 | 26 | /* 27 | NOTE: For the most accurate readings: 28 | - Avoid heavy bypass traffic on the I2C bus 29 | - Use the highest available communication speeds 30 | - Use the minimal supply voltage acceptable for the system 31 | - Place device horizontally and out of any airflow when storing 32 | For more information on reaching the most accurate readings from the sensor, 33 | reference the "Precise Temperature Measurements with TMP116" datasheet that is 34 | linked on Page 35 of the TMP117's datasheet 35 | 36 | The default address of the device is 0x48 (GND) 37 | 38 | There are 3 different modes 39 | Continuous Conversion (CC) = 0b00 = 1 40 | Shutdown (SD) = 0b01 = 2 41 | One-Shot Conversion (OS) = 0b11 = 3 42 | */ 43 | 44 | #include // Used to establish serial communication on the I2C bus 45 | #include // Used to send and recieve specific information from our sensor 46 | 47 | // The default address of the device is 0x48 (GND) 48 | TMP117 sensor; // Initalize sensor object 49 | 50 | void setup() 51 | { 52 | Wire.begin(); 53 | Serial.begin(115200); // Start serial communication at 115200 baud 54 | Wire.setClock(400000); // Set clock speed to be the fastest for better communication (fast mode) 55 | 56 | Serial.println("TMP117 Example 4: Setting Conversion Modes"); 57 | if (sensor.begin() == true) // Function to check if the sensor will correctly self-identify with the proper Device ID/Address 58 | { 59 | Serial.println("Begin"); 60 | } 61 | else 62 | { 63 | Serial.println("Device failed to setup- Freezing code."); 64 | while (1); // Runs forever if the sensor does not initialize correctly 65 | } 66 | 67 | Serial.println("Conversion Modes: "); 68 | Serial.println("1: Continuous"); 69 | Serial.println("2: Shutdown"); 70 | Serial.println("3: One-Shot"); 71 | Serial.print("Current Conversion Mode: "); 72 | Serial.println(sensor.getConversionMode()); // Prints the conversion mode of the device to the Serial Monitor 73 | } 74 | 75 | 76 | // For function to work, make sure the Serial Monitor is set to "No Line Ending" 77 | void loop() 78 | { 79 | Serial.println("Enter your mode of Conversion (number 1 - 3): "); 80 | while (Serial.available() == 0); // Waits for the user input 81 | uint8_t convMode = Serial.parseInt(); // Reads the input from the serial port 82 | Serial.print("Number received: "); 83 | Serial.println(convMode); 84 | if (convMode == 1) 85 | { 86 | sensor.setContinuousConversionMode(); // Sets mode register value to be 0b00 87 | Serial.print("New Conversion Mode: "); 88 | if (sensor.getConversionMode() == 1) 89 | { 90 | Serial.println("Continuous Conversion"); 91 | } 92 | else 93 | { 94 | Serial.println("Error setting new Conversion Mode"); 95 | } 96 | Serial.println(); // Create a whitespace for easier readings 97 | } 98 | else if (convMode == 2) 99 | { 100 | sensor.setShutdownMode(); // Sets mode register value to be 0b01 101 | Serial.print("New Conversion Mode: "); 102 | if (sensor.getConversionMode() == 2) 103 | { 104 | Serial.println("Shutdown Mode"); 105 | } 106 | else 107 | { 108 | Serial.println("Error setting new Conversion Mode"); 109 | } 110 | sensor.getConversionMode(); 111 | Serial.println(); // Create a whitespace for easier readings 112 | } 113 | else if (convMode == 3) 114 | { 115 | sensor.setOneShotMode(); // Sets mode register value to be 0b11 116 | Serial.print("New Conversion Mode: "); 117 | if (sensor.getConversionMode() == 3) 118 | { 119 | Serial.println("One-Shot Mode"); 120 | } 121 | else 122 | { 123 | Serial.println("Error setting new Conversion Mode"); 124 | } 125 | sensor.getConversionMode(); 126 | Serial.println(); // Create a whitespace for easier readings 127 | } 128 | else 129 | { 130 | Serial.println("Conversion mode unsuccessfully set - Please enter a number 1 - 3"); 131 | Serial.println(); // Create a whitespace for easier readings 132 | } 133 | delay(1000); 134 | } 135 | -------------------------------------------------------------------------------- /examples/Example5_SetAlertModeTemperatureLimits/Example5_SetAlertModeTemperatureLimits.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Example5_SetAlertModeTemperatureLimits.ino 3 | Example for the TMP117 I2C Temperature Sensor 4 | Madison Chodikov @ SparkFun Electronics 5 | June 11 2019 6 | ~ 7 | 8 | 9 | This sketch can set and get the Alert Function Mode, Low Temperature 10 | Limit, and High Temperature Limit for the sensor. These limits can 11 | be set within +/- 256°C. When the temperature goes above/below the 12 | specified temperature limits, it will cause the alert pins to go 13 | high. To access these registers, please reference Example 2: Alert Statuses. 14 | 15 | Resources: 16 | Wire.h (included with Arduino IDE) 17 | SparkFunTMP117.h (included in the src folder) http://librarymanager/All#SparkFun_TMP117 18 | 19 | Development environment specifics: 20 | Arduino 1.8.9+ 21 | Hardware Version 1.0.0 22 | 23 | This code is beerware; if you see me (or any other SparkFun employee) at 24 | the local, and you've found our code helpful, please buy us a round! 25 | 26 | Distributed as-is; no warranty is given. 27 | ******************************************************************************/ 28 | 29 | /* 30 | NOTE: For the most accurate readings: 31 | - Avoid heavy bypass traffic on the I2C bus 32 | - Use the highest available communication speeds 33 | - Use the minimal supply voltage acceptable for the system 34 | - Place device horizontally and out of any airflow when storing 35 | For more information on reaching the most accurate readings from the sensor, 36 | reference the "Precise Temperature Measurements with TMP116" datasheet that is 37 | linked on Page 35 of the TMP117's datasheet. 38 | */ 39 | 40 | #include // Used to establish serial communication on the I2C bus 41 | #include // Used to send and recieve specific information from the sensor 42 | 43 | // The default address of the device is 0x48 (GND) 44 | TMP117 sensor; // Initalize sensor 45 | 46 | 47 | void setup() 48 | { 49 | Wire.begin(); 50 | Serial.begin(115200); // Start serial communication at 115200 baud 51 | Wire.setClock(400000); // Set clock speed to be the fastest for better communication (fast mode) 52 | 53 | Serial.println("TMP117 Example 5: Setting Alert Function Mode and Temperature Limits"); 54 | if (sensor.begin() == true) // Function to check if the sensor will correctly self-identify with the proper Device ID/Address 55 | { 56 | Serial.println("Begin"); 57 | } 58 | else 59 | { 60 | Serial.println("Device failed to setup- Freezing code."); 61 | while (1); // Runs forever if the sensor does not initialize correctly 62 | } 63 | 64 | Serial.print("Current Alert Function Mode: "); 65 | Serial.println(sensor.getAlertFunctionMode()); 66 | Serial.print("Current Low Limit: "); 67 | Serial.println(sensor.getLowLimit()); // Returns the low limit temperature in °C 68 | Serial.print("Current High Limit: "); 69 | Serial.println(sensor.getHighLimit()); // Returns the high limit temperature in °C 70 | Serial.println(" "); 71 | } 72 | 73 | 74 | // For function to work, make sure the Serial Monitor is set to "No Line Ending" 75 | void loop() 76 | { 77 | float lowTemp, highTemp; 78 | int alertMode; 79 | Serial.println("Enter a value to change the alert function mode, low limit, or high limit."); 80 | Serial.println("0 for Alert Function Mode, 1 for Low Limit, and 2 for High Limit: "); 81 | 82 | while (Serial.available() == 0); // Waits for the user input 83 | int menu_option = Serial.parseInt(); // Reads the input from the serial port 84 | 85 | if (menu_option == 0) 86 | { 87 | Serial.print("Current Alert Function Mode: "); 88 | Serial.println(sensor.getAlertFunctionMode()); 89 | Serial.println("Please enter mode(0 or 1): "); 90 | while (Serial.available() == 0); // Waits for the user input 91 | alertMode = Serial.parseFloat(); 92 | if (alertMode == 0) 93 | { 94 | sensor.setAlertFunctionMode(0);//set to alert mode 95 | Serial.print("New Alert Function Mode: "); 96 | Serial.println(sensor.getAlertFunctionMode()); 97 | } 98 | else if (alertMode == 1) 99 | { 100 | sensor.setAlertFunctionMode(1);//set to therm mode 101 | Serial.print("New Alert Function Mode: "); 102 | Serial.println(sensor.getAlertFunctionMode()); 103 | } 104 | else 105 | { 106 | Serial.println("Please enter the Alert Function Mode (either 0 or 1)"); 107 | } 108 | } 109 | else if (menu_option == 1) 110 | { 111 | Serial.print("Current Low Limit: "); 112 | Serial.println(sensor.getLowLimit()); 113 | Serial.println("Please enter Low Limit Temperature (between -256°C and 255.98°C): "); 114 | while (Serial.available() == 0); // Waits for the user input 115 | lowTemp = Serial.parseFloat(); 116 | if ((lowTemp >= -256) && (lowTemp < 255.99)) 117 | { 118 | sensor.setLowLimit(lowTemp); 119 | Serial.print("New Low Limit (in °C): "); 120 | Serial.println(sensor.getLowLimit()); 121 | } 122 | else 123 | { 124 | Serial.println("Please enter a temperature between -256°C and 255.98°C"); 125 | } 126 | 127 | } 128 | else if (menu_option == 2) 129 | { 130 | Serial.print("Current High Limit: "); 131 | Serial.println(sensor.getHighLimit()); 132 | Serial.println("Please enter High Limit Temperature (between -256°C and 255.98°C): "); 133 | while (Serial.available() == 0); // Waits for the user input 134 | highTemp = Serial.parseFloat(); // Reads the input from the serial port 135 | if ((highTemp >= -256) && (highTemp < 255.99)) 136 | { 137 | sensor.setHighLimit(highTemp); 138 | Serial.print("New High Limit (in °C): "); 139 | Serial.println(sensor.getHighLimit()); 140 | } 141 | else 142 | { 143 | Serial.println("Please enter a temperature between -256°C and 255.98°C"); 144 | } 145 | } 146 | else 147 | { 148 | Serial.println("Please enter 0, 1, or 2"); 149 | } 150 | Serial.println(""); // Create a whitespace for easier readings 151 | } 152 | 153 | -------------------------------------------------------------------------------- /examples/Example6_SetConversionCycleTime/Example6_SetConversionCycleTime.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Example6_SetConversionCycleTime.ino 3 | Example for the TMP117 I2C Temperature Sensor 4 | Madison Chodikov @ SparkFun Electronics 5 | July 3rd 2019 6 | ~ 7 | 8 | This sketch can set and get the Conversion Times in Continuous Conversion mode 9 | for the Sensor. A chart for the averaging modes and the conversion times can 10 | be found in the comments below or in the Datasheet on Page 26, Table 7. 11 | 12 | Resources: 13 | Wire.h (included with Arduino IDE) 14 | SparkFunTMP117.h (included in the src folder) http://librarymanager/All#SparkFun_TMP117 15 | 16 | Development environment specifics: 17 | Arduino 1.8.9+ 18 | Hardware Version 1.0.0 19 | 20 | This code is beerware; if you see me (or any other SparkFun employee) at 21 | the local, and you've found our code helpful, please buy us a round! 22 | 23 | Distributed as-is; no warranty is given. 24 | ******************************************************************************/ 25 | 26 | /* 27 | NOTE: For the most accurate readings: 28 | - Avoid heavy bypass traffic on the I2C bus 29 | - Use the highest available communication speeds 30 | - Use the minimal supply voltage acceptable for the system 31 | - Place device horizontally and out of any airflow when storing 32 | For more information on reaching the most accurate readings from the sensor, 33 | reference the "Precise Temperature Measurements with TMP116" datasheet that is 34 | linked on Page 35 of the TMP117's datasheet. 35 | 36 | 37 | Conversion Cycle Times in CC Mode (found in the datasheet page 26 table 6) 38 | AVG 0 1 2 3 39 | CONV averaging (0) (8) (32) (64) 40 | 0 15.5ms 125ms 500ms 1s 41 | 1 125ms 125ms 500ms 1s 42 | 2 250ms 250ms 500ms 1s 43 | 3 500ms 500ms 500ms 1s 44 | 4 1s 1s 1s 1s 45 | 5 4s 4s 4s 4s 46 | 6 8s 8s 8s 8s 47 | 7 16s 16s 16s 16s 48 | 49 | CONV = Conversion Cycle Bit 50 | AVG = Conversion Averaging Mode 51 | */ 52 | 53 | #include // Used to establish serial communication on the I2C bus 54 | #include // Used to send and recieve specific information from the sensor 55 | 56 | // The default address of the device is 0x48 (GND) 57 | TMP117 sensor; // Initalize sensor 58 | 59 | 60 | void setup() 61 | { 62 | Wire.begin(); 63 | Serial.begin(115200); // Start serial communication at 115200 baud 64 | Wire.setClock(400000); // Set clock speed to be the fastest for better communication (fast mode) 65 | Serial.println("TMP117 Example 6: Setting Conversion Cycle Time"); 66 | if (sensor.begin() == true) // Function to check if the sensor will correctly self-identify with the proper Device ID/Address 67 | { 68 | Serial.println("Begin"); 69 | } 70 | else 71 | { 72 | Serial.println("Device failed to setup- Freezing code."); 73 | while (1); // Runs forever if the sensor does not initialize correctly 74 | } 75 | 76 | Serial.println(" Conversion Cycle Times in CC Mode "); 77 | Serial.println(" AVG 0 1 2 3"); 78 | Serial.println(" CONV averaging (0) (8) (32) (64)"); 79 | Serial.println(" 0 15.5ms 125ms 500ms 1s"); 80 | Serial.println(" 1 125ms 125ms 500ms 1s"); 81 | Serial.println(" 2 250ms 250ms 500ms 1s"); 82 | Serial.println(" 3 500ms 500ms 500ms 1s"); 83 | Serial.println(" 4 1s 1s 1s 1s"); 84 | Serial.println(" 5 4s 4s 4s 4s"); 85 | Serial.println(" 6 8s 8s 8s 8s"); 86 | Serial.println(" 7 16s 16s 16s 16s"); 87 | Serial.println("AVG = Conversion Average Mode"); 88 | Serial.println("CONV = Conversion Cycle Bit"); 89 | Serial.println(); 90 | Serial.print("Current Conversion Average Mode: "); 91 | Serial.println(sensor.getConversionAverageMode()); 92 | Serial.print("Current Conversion Cycle Bit Value: "); 93 | Serial.println(sensor.getConversionCycleBit()); 94 | } 95 | 96 | 97 | // Global variables declared for the loop 98 | uint8_t cycleBit; 99 | uint8_t avMode; 100 | 101 | // For function to work, make sure the Serial Monitor is set to "No Line Ending" 102 | void loop() 103 | { 104 | Serial.println("Enter 1 for changing the Averaging Mode or 2 for changing the Cycle Bit Value: "); 105 | while (Serial.available() == 0); // Waits for the user input 106 | int mode = Serial.parseInt(); // Reads the input from the serial port 107 | if (mode == 1) 108 | { 109 | Serial.print("Current Averaging Mode: "); 110 | Serial.println(sensor.getConversionAverageMode()); 111 | Serial.println("Please 0 - 3 for the New Averaging Mode: "); 112 | while (Serial.available() == 0); // Waits for the user input 113 | avMode = Serial.parseInt(); 114 | Serial.print("Number received: "); 115 | Serial.println(avMode); 116 | if ((avMode >= 0) && (avMode <= 3)) 117 | { 118 | sensor.setConversionAverageMode(avMode); 119 | Serial.print("New Conversion Average Mode: "); 120 | Serial.println(sensor.getConversionAverageMode()); 121 | } 122 | else 123 | { 124 | Serial.println("Please Enter a Number 0 - 3"); 125 | } 126 | } 127 | 128 | else if (mode == 2) 129 | { 130 | Serial.print("Current Cycle Bit Value: "); 131 | Serial.println(sensor.getConversionCycleBit()); 132 | Serial.println("Please enter 0 - 7 for the Conversion Cycle Bit: "); 133 | while (Serial.available() == 0); // Waits for the user input 134 | cycleBit = Serial.parseInt(); // Reads the input from the serial port 135 | Serial.print("Number received: "); 136 | Serial.println(cycleBit); 137 | if ((cycleBit >= 0) && (cycleBit <= 7)) 138 | { 139 | sensor.setConversionCycleBit(cycleBit); 140 | Serial.print("New Conversion Cycle Bit Value: "); 141 | Serial.println(sensor.getConversionCycleBit()); 142 | } 143 | else 144 | { 145 | Serial.println("Please enter a Number 0 - 7"); 146 | } 147 | } 148 | else 149 | { 150 | Serial.println("Please enter 1 or 2"); 151 | } 152 | Serial.println(""); // Create a whitespace for easier readings 153 | } 154 | -------------------------------------------------------------------------------- /examples/Example7_AdvancedI2CFunctions/Example7_AdvancedI2CFunctions.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Example7_AdvancedI2CFunctions.ino 3 | Example for the TMP117 I2C Temperature Sensor 4 | Madison Chodikov @ SparkFun Electronics 5 | July 22 2019 6 | ~ 7 | 8 | This sketch allows the user to change the address of the device and to 9 | change the Wire port for I2C Communications. The address can be physically 10 | changed with an external jumper on the back of the sensor. 11 | 12 | Resources: 13 | Wire.h (included with Arduino IDE) 14 | SparkFunTMP117.h (included in the src folder) http://librarymanager/All#SparkFun_TMP117 15 | 16 | Development environment specifics: 17 | Arduino 1.8.9+ 18 | Hardware Version 1.0.0 19 | 20 | This code is beerware; if you see me (or any other SparkFun employee) at 21 | the local, and you've found our code helpful, please buy us a round! 22 | 23 | Distributed as-is; no warranty is given. 24 | ******************************************************************************/ 25 | 26 | /* 27 | NOTE: For the most accurate readings: 28 | - Avoid heavy bypass traffic on the I2C bus 29 | - Use the highest available communication speeds 30 | - Use the minimal supply voltage acceptable for the system 31 | - Place device horizontally and out of any airflow when storing 32 | For more information on reaching the most accurate readings from the sensor, 33 | reference the "Precise Temperature Measurements with TMP116" datasheet that is 34 | linked on Page 35 of the TMP117's datasheet 35 | */ 36 | 37 | #include // Used to establish serial communication on the I2C bus 38 | #include // Used to send and recieve specific information from our sensor 39 | 40 | TMP117 sensor; // Initalize sensor 41 | 42 | /* The default address of the device is 0x48 (GND) 43 | Sensor address can be changed with an external jumper to: 44 | VCC = 0x49 45 | SDA = 0x4A 46 | SCL = 0x4B 47 | For a table of the addresses, reference page 19, Table 2 on the TMP117 Datasheet 48 | 49 | 50 | This sketch only works if your platform doesn't have multiple I2C ports. This will not 51 | work on an Arduino Uno platform. 52 | 53 | To test the functionality of changing the addresses, change "Wire1" to "Wire" below 54 | */ 55 | 56 | void setup() 57 | { 58 | Wire1.begin(); // Compilation will fail here if your platform doesn't have multiple I2C ports 59 | Serial.begin(115200); // Start serial communication at 115200 baud 60 | Wire1.setClock(400000); // Set clock speed to be the fastest for better communication (fast mode) 61 | 62 | Serial.println("TMP117 Example 7: Advanced I2C Functions"); 63 | if (sensor.begin() == true) // Function to check if the sensor will correctly self-identify with the proper Device ID/Address 64 | { 65 | Serial.println("Begin"); 66 | } 67 | else 68 | { 69 | Serial.println("Device failed to setup- Freezing code."); 70 | while (1); // Runs forever 71 | } 72 | Serial.println("Device Address Options: "); 73 | Serial.println("1: 0x48 (GND/Default)"); 74 | Serial.println("2: 0x49 (V+)"); 75 | Serial.println("3: 0x4A (SDA)"); 76 | Serial.println("4: 0x4B (SCL)"); 77 | Serial.println(); // White space for easier readings 78 | Serial.print("Current Device Address: "); 79 | Serial.println(sensor.getAddress(), HEX); // Prints the current address of the device in Hex 80 | } 81 | 82 | void loop() 83 | { 84 | Serial.println("Enter new address (number 1 - 4): "); 85 | while (Serial.available() == 0); // Waits for the user input 86 | uint8_t newAddress = Serial.parseInt(); // Reads the input from the serial port 87 | Serial.print("Number received: "); 88 | Serial.println(newAddress); 89 | if(newAddress == 1) // 0x48 (GND/Default) 90 | { 91 | sensor.begin(0x48, Wire); 92 | Serial.print("New Address: "); 93 | Serial.println(sensor.getAddress(), HEX); 94 | Serial.println(); 95 | } 96 | else if(newAddress == 2) // 0x49 (V+) 97 | { 98 | sensor.begin(0x49, Wire); 99 | Serial.print("New Address: "); 100 | Serial.println(sensor.getAddress(), HEX); 101 | Serial.println(); 102 | } 103 | else if(newAddress == 3) // 0x4A (SDA) 104 | { 105 | sensor.begin(0x4A, Wire); 106 | Serial.print("New Address: "); 107 | Serial.println(sensor.getAddress(), HEX); 108 | Serial.println(); 109 | } 110 | else if(newAddress == 4) // 0x4B (SCL) 111 | { 112 | sensor.begin(0x4B, Wire); 113 | Serial.print("New Address: "); 114 | Serial.println(sensor.getAddress(), HEX); 115 | Serial.println(); 116 | } 117 | else // Runs when a number not 1-4 is entered 118 | { 119 | Serial.println("Please enter a number 1-4"); 120 | Serial.println(); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Syntax Coloring Map for SparkFun TMP117 Temperature Sensor Library # 3 | ###################################################################### 4 | # Class 5 | ###################################################################### 6 | 7 | TMP117 KEYWORD1 8 | 9 | ###################################################################### 10 | # Methods and Functions 11 | ###################################################################### 12 | 13 | begin KEYWORD2 14 | getAddress KEYWORD2 15 | readTempC KEYWORD2 16 | readTempF KEYWORD2 17 | softReset KEYWORD2 18 | getTemperatureOffset KEYWORD2 19 | setTemperatureOffset KEYWORD2 20 | getLowLimit KEYWORD2 21 | setLowLimit KEYWORD2 22 | getHighLimit KEYWORD2 23 | setHighLimit KEYWORD2 24 | getConfigurationRegister KEYWORD2 25 | getHighLowAlert KEYWORD2 26 | getHighAlert KEYWORD2 27 | getLowAlert KEYWORD2 28 | setAlertFunctionMode KEYWORD2 29 | getAlertFunctionMode KEYWORD2 30 | getConversionMode KEYWORD2 31 | setContinuousConversionMode KEYWORD2 32 | setOneShotMode KEYWORD2 33 | setShutdownMode KEYWORD2 34 | setConversionAverageMode KEYWORD2 35 | getConversionAverageMode KEYWORD2 36 | setConversionCycleBit KEYWORD2 37 | getConversionCycleBit KEYWORD2 38 | dataReady KEYWORD2 39 | readRegister KEYWORD2 40 | writeRegister KEYWORD2 -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=SparkFun High Precision Temperature Sensor TMP117 Qwiic 2 | version=1.2.5 3 | author=SparkFun Electronics 4 | maintainer=SparkFun Electronics 5 | sentence=A library to drive the Texas Instruments TMP117 by I2C. 6 | paragraph=Communicates with the TMP117 over I2C to quickly integrate a temperature sensor into your project. The sensor outputs temperature readings with high precision of +/- 0.1°C over the range of -20°C to +50°C with no calibration. The maximum range is from -55°C to 150°C with a slightly lower precision of +/-0.3°C. It also has a very low power consumption which minimizes the impact of self-heating on measurement accuracy. The sensor operates from 1.8V to 5.5V. 7 | category=Sensors 8 | url=https://github.com/sparkfun/SparkFun_TMP117_Arduino_Library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/SparkFun_TMP117.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | SparkFunTMP117.cpp 3 | SparkFunTMP117 Library Source File 4 | Madison Chodikov @ SparkFun Electronics 5 | Original Creation Date: April 22, 2019 6 | https://github.com/sparkfun/SparkFun_TMP117_Arduino_Library 7 | 8 | This file implements all functions of the TMP117 class. Functions here range 9 | from reading the temperature from the sensor, to reading and writing various 10 | settings in the sensor. 11 | 12 | Development environment specifics: 13 | IDE: Arduino 1.8.9 14 | Hardware Platform: Arduino Uno 15 | TMP117 Breakout Version: 1.0.0 16 | 17 | This code is beerware; if you see me (or any other SparkFun employee) at the 18 | local, and you've found our code helpful, please buy us a round! 19 | 20 | Distributed as-is; no warranty is given. 21 | ******************************************************************************/ 22 | 23 | /* 24 | NOTE: Read for use for the most accurate readings from the sensor 25 | - Avoid heavy bypass traffic on the I2C bus for most accurate temperature readings 26 | - Use the highest available communication speeds 27 | - Use the minimal supply voltage acceptable for the system 28 | - Place device horizontally and out of any airflow when storing 29 | For more information on reaching the most accurate readings from the sensor, 30 | reference the "Precise Temperature Measurements with TMP116" datasheet that is 31 | linked on Page 35 of the TMP117's datasheet 32 | */ 33 | 34 | #include 35 | #include 36 | #include "SparkFun_TMP117_Registers.h" 37 | #include "SparkFun_TMP117.h" 38 | 39 | /* CONSTRUCTOR 40 | This function will use the main I2C port on the Arduino 41 | by default, but this is configurable with the setBus function. 42 | This needs to be called when running the example sketches to 43 | initialize the sensor and be able to call to the library. 44 | */ 45 | TMP117::TMP117() 46 | { 47 | } 48 | 49 | /* BEGIN 50 | This function checks if the TMP will ACK over I2C, and 51 | if the TMP will correctly self-identify with the proper 52 | device ID. This will set the address of the device along 53 | with setting the wire for the I2C Communication. 54 | This will return true if both checks pass. 55 | */ 56 | bool TMP117::begin(uint8_t sensorAddress, TwoWire &wirePort) 57 | { 58 | _i2cPort = &wirePort; // Chooses the wire port of the device 59 | _deviceAddress = sensorAddress; // Sets the address of the device 60 | 61 | //make sure the TMP will acknowledge over I2C 62 | _i2cPort->beginTransmission(_deviceAddress); 63 | if (_i2cPort->endTransmission() != 0) 64 | { 65 | return false; 66 | } 67 | 68 | uint16_t deviceID = readRegister(TMP117_DEVICE_ID); // reads registers into rawData 69 | 70 | //make sure the device ID reported by the TMP is correct 71 | //should always be 0x0117 72 | if (deviceID != DEVICE_ID_VALUE) 73 | { 74 | return false; 75 | } 76 | 77 | return true; //returns true if all the checks pass 78 | } 79 | 80 | /* GET ADDRESS 81 | This function returns the address of the device once 82 | called upon. This address can only be 0x48 (GND), 83 | 0x49 (V+), 0x4A (SDA), and 0x4B (SCL) 84 | */ 85 | uint8_t TMP117::getAddress() 86 | { 87 | return _deviceAddress; 88 | } 89 | 90 | /* READ REGISTER 91 | This function reads the register bytes from the sensor when called upon. 92 | This reads 2 bytes of information from the 16-bit registers. 93 | */ 94 | uint16_t TMP117::readRegister(uint8_t reg) // originally TMP117_Register reg 95 | { 96 | _i2cPort->beginTransmission(_deviceAddress); // Originally cast (uint8_t) 97 | _i2cPort->write(reg); 98 | _i2cPort->endTransmission(); // endTransmission but keep the connection active 99 | _i2cPort->requestFrom(_deviceAddress, (uint8_t)2); // Ask for 2 bytes, once done, bus is released by default 100 | 101 | uint8_t data[2] = {0}; // Declares an array of length 2 to be empty 102 | int16_t datac = 0; // Declares the return variable to be 0 103 | if (_i2cPort->available() <= 2) // Won't read more than 2 bits 104 | { 105 | data[0] = _i2cPort->read(); // Reads the first set of bits (D15-D8) 106 | data[1] = _i2cPort->read(); // Reads the second set of bits (D7-D0) 107 | datac = ((data[0] << 8) | data[1]); // Swap the LSB and the MSB 108 | } 109 | return datac; 110 | } 111 | 112 | /* WRITE REGISTER 113 | Wire data to a TMP117 register 114 | */ 115 | void TMP117::writeRegister(uint8_t reg, uint16_t data) // originally TMP117_Register reg 116 | { 117 | _i2cPort->beginTransmission(_deviceAddress); // Originally cast uint8_t when a register value again 118 | _i2cPort->write(reg); 119 | _i2cPort->write(highByte(data)); // Write MSB (D15-D8) 120 | _i2cPort->write(lowByte(data)); // Write LSB (D7-D0) 121 | _i2cPort->endTransmission(); // Stop transmitting data 122 | } 123 | 124 | /* READ TEMPERATURE CELSIUS 125 | This function reads the temperature reading from the sensor 126 | and returns the value in degrees celsius. 127 | 128 | NOTE: The data type of digitalTemp is a signed integer, meaning that the 129 | value of the binary number being read will be negative if the MSB is 1, 130 | and positive if the bit is 0. 131 | */ 132 | double TMP117::readTempC() 133 | { 134 | int16_t digitalTempC = readRegister(TMP117_TEMP_RESULT); // Calls to read registers to pull all the bits to store in an array 135 | 136 | float finalTempC = digitalTempC * TMP117_RESOLUTION; // Multiplies by the resolution for digital to final temp 137 | 138 | return finalTempC; 139 | } 140 | 141 | /* READ TEMPERATURE FAHRENHEIT 142 | This function calculates the fahrenheit reading from the 143 | celsius reading initially found. 144 | The device reads in celsius unless this function is called. 145 | */ 146 | double TMP117::readTempF() 147 | { 148 | return readTempC() * 9.0 / 5.0 + 32.0; // Conversion from °C to °F 149 | } 150 | 151 | /* GET TEMPERATURE OFFSET 152 | This function reads the temperature offset. This reads from the register 153 | value 0x07 (TMP117_TEMP_OFFSET). This can be found on page 23 of the 154 | datasheet. 155 | */ 156 | float TMP117::getTemperatureOffset() 157 | { 158 | int16_t _offset = 0; 159 | _offset = readRegister(TMP117_TEMP_OFFSET); // Reads from the temperature offset register 160 | float finalOffset = (float)_offset * TMP117_RESOLUTION; // Multiplies by the resolution for correct offset temperature 161 | return finalOffset; 162 | } 163 | 164 | /* SET TEMPERATURE OFFSET 165 | This function sets the offset temperature of the device. The user 166 | can write to this to set any desired offset within the temperature range. 167 | This writes to the register value 0x07 (TMP117_TEMP_OFFSET) 168 | */ 169 | void TMP117::setTemperatureOffset(float offset) 170 | { 171 | int16_t resolutionOffset = offset / TMP117_RESOLUTION; // Divides by the resolution to send the correct value to the sensor 172 | writeRegister(TMP117_TEMP_OFFSET, resolutionOffset); // Writes to the offset temperature register with the new offset value 173 | } 174 | 175 | /* GET LOW LIMIT 176 | This function reads the low limit register that is set by the user. 177 | The values are signed integers since they can be negative. 178 | */ 179 | float TMP117::getLowLimit() 180 | { 181 | int16_t lowLimit = 0; 182 | lowLimit = readRegister(TMP117_T_LOW_LIMIT); // Calls to read register to pull all the bits to store in a variable 183 | float finalLimit = (float)lowLimit * TMP117_RESOLUTION; // Multiplies by the resolution for correct offset temperature 184 | return finalLimit; 185 | } 186 | 187 | /* SET LOW LIMIT 188 | This function allows the user to set the low limit register to whatever 189 | specified value, as long as in the range for the temperature sensor. This 190 | function can be used as a threshold for Therm mode and or Alert mode. 191 | The values are signed integers since they can be negative. 192 | */ 193 | void TMP117::setLowLimit(float lowLimit) 194 | { 195 | int16_t finalLimit = lowLimit / TMP117_RESOLUTION; // Divides by the resolution to send the correct value to the sensor 196 | writeRegister(TMP117_T_LOW_LIMIT, finalLimit); // Writes to the low limit temperature register with the new limit value 197 | } 198 | 199 | /* GET HIGH LIMIT 200 | This function reads the high limit register that is set by the user. 201 | The values are signed integers since they can be negative. 202 | */ 203 | float TMP117::getHighLimit() 204 | { 205 | int16_t highLimit = 0; 206 | highLimit = readRegister(TMP117_T_HIGH_LIMIT); // Calls to read registers to pull all the bits to store in an array 207 | float finalLimit = (float)highLimit * TMP117_RESOLUTION; // Multiplies by the resolution for correct offset temperature 208 | return finalLimit; 209 | } 210 | 211 | /* SET HIGH LIMIT 212 | This function allows the user to set the high limit register to whatever 213 | specified value, as long as in the range for the temperature sensor. This 214 | function can be used as a threshold for Therm mode and or Alert mode 215 | The values are signed integers since they can be negative. 216 | */ 217 | void TMP117::setHighLimit(float highLimit) 218 | { 219 | int16_t finalLimit = highLimit / TMP117_RESOLUTION; // Divides by the resolution to send the correct value to the sensor 220 | writeRegister(TMP117_T_HIGH_LIMIT, finalLimit); // Writes to the high limit temperature register with the new limit value 221 | } 222 | 223 | /*GET CONFIGURATION REGISTER 224 | This function reads configuration register. Use this function if you need to read 225 | certain flags before they are cleared. This can be found on page 25 of the 226 | datasheet. 227 | */ 228 | uint16_t TMP117::getConfigurationRegister() 229 | { 230 | uint16_t configReg = 0; 231 | configReg = readRegister(TMP117_CONFIGURATION); 232 | 233 | return configReg; 234 | } 235 | 236 | /*GET HIGH AND LOW ALERT 237 | This function reads configuration register and saves the high and low alert flags. 238 | Use this function if you need to read the alert flags before they are cleared. 239 | This can be found on page 25 of the datasheet. 240 | */ 241 | uint8_t TMP117::getHighLowAlert() 242 | { 243 | uint16_t configReg = 0; 244 | configReg = readRegister(TMP117_CONFIGURATION); //Grab what is in the configuration register 245 | 246 | uint8_t highlowAlert = 0; //temporary variable to hold high and low alert flags 247 | //Get high alert flag from 15th bit of the configuration register, 248 | // then write bit to highlowAlert's 2nd position from the right 249 | bitWrite(highlowAlert, 1, bitRead(configReg, 15)); 250 | 251 | //Get high alert flag from 14th bit of the configuration register, 252 | // then write bit to highlowAlert's 1st position from the right 253 | bitWrite(highlowAlert, 0, bitRead(configReg, 14)); 254 | 255 | return highlowAlert; //return high and low alert flags 256 | } 257 | 258 | /*GET HIGH ALERT 259 | This function reads the 15th bit of the configuration register to 260 | tell if the conversion result is higher than the high limit. This 261 | is set as a High Alert flag. This can be found on page 25 of the 262 | datasheet. 263 | */ 264 | bool TMP117::getHighAlert() 265 | { 266 | uint16_t configReg = 0; 267 | configReg = readRegister(TMP117_CONFIGURATION); //Grab what is in the configuration register 268 | 269 | uint8_t highAlert = bitRead(configReg, 15); // Fills with the 15th bit of the configuration register 270 | 271 | if (highAlert == 1) 272 | { 273 | return true; 274 | } 275 | else 276 | { 277 | return false; 278 | } 279 | } 280 | 281 | /*GET LOW ALERT 282 | This function reads the 14th bit of the configuration register to 283 | tell if the conversion result is lower than the low limit. This 284 | is set as a Low Alert flag. This can be found on page 25 of the 285 | datasheet. 286 | */ 287 | bool TMP117::getLowAlert() 288 | { 289 | uint16_t configReg = 0; 290 | configReg = readRegister(TMP117_CONFIGURATION); //Grab what is in the configuration register 291 | 292 | uint8_t lowAlert = bitRead(configReg, 14); // Fills with the 14th bit of the configuration register 293 | 294 | if (lowAlert == 1) 295 | { 296 | return true; 297 | } 298 | else 299 | { 300 | return false; 301 | } 302 | } 303 | 304 | /*SET ALERT FUNCTION MODE 305 | This function sets the alert function mode to either "alert" or 306 | "therm" mode. This can be found on page 25 of the datasheet. 307 | */ 308 | void TMP117::setAlertFunctionMode(uint8_t setAlertMode) 309 | { 310 | uint16_t AlertFunctionMode = 0; 311 | AlertFunctionMode = readRegister(TMP117_CONFIGURATION); // Fills mode to be the config register 312 | 313 | if (setAlertMode == 1) // 1: Therm mode 314 | { 315 | bitWrite(AlertFunctionMode, 4, 1); //set register bit to be 1 316 | writeRegister(TMP117_CONFIGURATION, AlertFunctionMode); 317 | } 318 | else // 0: alert mode 319 | { 320 | bitClear(AlertFunctionMode, 4); //set register bit to be 0 321 | writeRegister(TMP117_CONFIGURATION, AlertFunctionMode); 322 | } 323 | } 324 | 325 | /*GET ALERT FUNCTION MODE 326 | This function gets the alert function mode to either "alert" or 327 | "therm" mode. This can be found on page 25 of the datasheet. 328 | */ 329 | uint8_t TMP117::getAlertFunctionMode() 330 | { 331 | uint16_t configReg = 0; 332 | configReg = readRegister(TMP117_CONFIGURATION); // Fill configReg with the configuration register 333 | 334 | uint8_t currentAlertMode = bitRead(configReg, 4); //Get the value from the Therm/alert mode ("T/nA") select field 335 | 336 | if (currentAlertMode == 1) //if "therm" mode 337 | { 338 | return 1; 339 | } 340 | else //if "alert" mode 341 | { 342 | return 0; 343 | } 344 | } 345 | 346 | /* SOFTWARE RESET 347 | This function performs a software reset, loading all the default 348 | values into the configuration register. A table of the configuration 349 | register can be found on page 25 of the datasheet. 350 | */ 351 | void TMP117::softReset() 352 | { 353 | uint16_t reset = 0; 354 | reset = readRegister(TMP117_CONFIGURATION); // Fills mode to be the configuration register 355 | bitWrite(reset, 1, 1); 356 | writeRegister(TMP117_CONFIGURATION, reset); 357 | } 358 | 359 | /* SET CONTINUOUS CONVERSION MODE 360 | This function sets the conversion mode of the sensor to be 361 | continuous. This can be found in the datasheet on Page 25 Table 6. 362 | The TMP117 defaults to Continuous Conversion Mode on reset. 363 | */ 364 | void TMP117::setContinuousConversionMode() 365 | { 366 | uint16_t mode = 0; 367 | mode = readRegister(TMP117_CONFIGURATION); // Fills mode to be the configuration register 368 | 369 | bitClear(mode, 10); // Clears bit 10 370 | bitClear(mode, 11); // Clears bit 11 371 | writeRegister(TMP117_CONFIGURATION, mode); 372 | } 373 | 374 | /* SET SHUTDOWN MODE 375 | This function sets the conversion mode of the sensor to be 376 | in shutdown mode. This can be found in the datasheet on Page 377 | 25 Table 6. The TMP117 defaults to Continuous Conversion Mode 378 | on reset. 379 | */ 380 | void TMP117::setShutdownMode() 381 | { 382 | uint16_t mode = 0; 383 | mode = readRegister(TMP117_CONFIGURATION); // Fills mode to be the configuration register 384 | 385 | bitClear(mode, 11); // Clears bit 11 386 | bitWrite(mode, 10, 1); // Sets bit 10 to 1 387 | writeRegister(TMP117_CONFIGURATION, mode); 388 | } 389 | 390 | /* SET ONE SHOT MODE 391 | This function sets the conversion mode of the sensor to be 392 | in one shot mode. This can be found in the datasheet on Page 393 | 25 Table 6. The TMP117 defaults to Continuous Conversion Mode 394 | on reset. 395 | */ 396 | void TMP117::setOneShotMode() 397 | { 398 | uint16_t mode = 0; 399 | mode = readRegister(TMP117_CONFIGURATION); // Fills mode to be the configuration register 400 | 401 | bitWrite(mode, 10, 1); // Sets bit 10 to 1 402 | bitWrite(mode, 11, 1); // Sets bit 11 to 1 403 | writeRegister(TMP117_CONFIGURATION, mode); 404 | } 405 | 406 | /* GET CONVERSION MODE 407 | This function reads the mode for the conversions, then 408 | prints it to the Serial Monitor in the Arduino IDE. 409 | This can be found in the datasheet on Page 25 Table 6. 410 | This function can return Continuous Conversion Mode (1), 411 | Shutdown Mode (2), and One-Shot Mode (3). This should never 412 | return 4 (the other continuous conversion) since there is 413 | no function for writing to the value. 414 | */ 415 | uint8_t TMP117::getConversionMode() 416 | { 417 | uint16_t configReg = 0; 418 | configReg = readRegister(TMP117_CONFIGURATION); // Fill configReg with the configuration register 419 | 420 | uint8_t currentMode1 = bitRead(configReg, 11); // Left most conversion bit 421 | uint8_t currentMode2 = bitRead(configReg, 10); // Right most conversion bit 422 | 423 | if ((currentMode1 == 0) && (currentMode2 == 0)) // 0b00, Continuous Conversion Mode 424 | { 425 | return 1; // Actually 0, but return 1 for the example sketch 426 | } 427 | else if ((currentMode1 == 1) && (currentMode2 == 0)) // 0b10, should not be set this 428 | { 429 | return 4; // This value should never be returned 430 | } 431 | else if ((currentMode1 == 0) && (currentMode2 == 1)) // 0b01, Shutdown Mode 432 | { 433 | return 2; // Actually 0b01, but return 2 for the example sketch 434 | } 435 | else if ((currentMode1 == 1) && (currentMode2 == 1)) // 0b11, One-Shot Mode 436 | { 437 | return 3; 438 | } 439 | else 440 | { 441 | return 1; //Default 442 | } 443 | } 444 | 445 | /*SET CONVERSION AVERAGE MODE 446 | This function sets the conversion averaging mode of the device 447 | when in Continuous Conversion Mode. This can be found on page 448 | 25 of the TMP117 datasheet. 449 | */ 450 | void TMP117::setConversionAverageMode(uint8_t convMode) 451 | { 452 | uint16_t mode = 0; 453 | mode = readRegister(TMP117_CONFIGURATION); // Fills to be the config register 454 | 455 | if (convMode == 0) // No Averaging, 0b00 456 | { 457 | bitClear(mode, 5); // Clears bit 5 458 | bitClear(mode, 6); // Clears bit 6 459 | writeRegister(TMP117_CONFIGURATION, mode); 460 | } 461 | else if (convMode == 1) // 8 Averaged Conversions, 0b01 462 | { 463 | bitClear(mode, 6); // Clears bit 6 464 | bitWrite(mode, 5, 1); // Sets bit 5 to be 1 465 | writeRegister(TMP117_CONFIGURATION, mode); 466 | } 467 | else if (convMode == 2) // 32 Averaged Conversions, 0b10 468 | { 469 | bitWrite(mode, 6, 1); // Sets bit 6 to be 1 470 | bitClear(mode, 5); // Clears bit 5 471 | writeRegister(TMP117_CONFIGURATION, mode); 472 | } 473 | else if (convMode == 3) // 64 Averaged Conversions, 0b11 474 | { 475 | bitWrite(mode, 6, 1); // Sets bit 6 to be 1 476 | bitWrite(mode, 5, 1); // Sets bit 5 to be 1 477 | writeRegister(TMP117_CONFIGURATION, mode); 478 | } 479 | } 480 | 481 | /*GET CONVERSION AVERAGE MODE 482 | This function reads for the averaging mode of the conversions, 483 | then prints it to the Serial Monitor in the Arduino IDE. 484 | This can be found in the datasheet on Page 25 Table 6. 485 | */ 486 | uint8_t TMP117::getConversionAverageMode() 487 | { 488 | uint16_t configReg = 0; 489 | configReg = readRegister(TMP117_CONFIGURATION); // Fills configReg with config register values 490 | 491 | uint8_t currentMode6 = bitRead(configReg, 6); // Left most averaging bit 492 | uint8_t currentMode5 = bitRead(configReg, 5); // Right most averaging bit 493 | 494 | if ((currentMode6 == 0) && (currentMode5 == 0)) // 0b00, no averaging 495 | { 496 | return 0b00; 497 | } 498 | else if ((currentMode6 == 0) && (currentMode5 == 1)) // 0b01, 8 averaged conversions 499 | { 500 | return 0b01; 501 | } 502 | else if ((currentMode6 == 1) && (currentMode5 == 0)) // 0b10, 32 averaged conversions 503 | { 504 | return 0b10; 505 | } 506 | else if ((currentMode6 == 1) && (currentMode5 == 1)) // 0b11, 64 averaged conversions 507 | { 508 | return 0b11; 509 | } 510 | else 511 | { 512 | return 0b00; //No averaging 513 | } 514 | } 515 | 516 | /* SET CONVERSION CYCLE BIT 517 | This function sets the conversion cycle time bit in 518 | Continuous Conversion mode. The times for the conversions 519 | can be found below or in the datasheet on Page 25 Table 520 | 6 or on Page 27 Table 7. The user puts in 0-7 and it will 521 | return the cycle time accoring to the values in the chart. 522 | 523 | Conversion Cycle Time in CC Mode (found on the datasheet page 26 table 6) 524 | AVG 0 1 2 3 525 | CONV averaging (0) (8) (32) (64) 526 | 0 15.5ms 125ms 500ms 1s 527 | 1 125ms 125ms 500ms 1s 528 | 2 250ms 250ms 500ms 1s 529 | 3 500ms 500ms 500ms 1s 530 | 4 1s 1s 1s 1s 531 | 5 4s 4s 4s 4s 532 | 6 8s 8s 8s 8s 533 | 7 16s 16s 16s 16s 534 | */ 535 | void TMP117::setConversionCycleBit(uint8_t convTime) 536 | { 537 | uint16_t mode = 0; 538 | mode = readRegister(TMP117_CONFIGURATION); // Fills in time to be the config register 539 | 540 | if (convTime == 0) // 0b000 541 | { 542 | bitClear(mode, 9); // Clears bit 9 543 | bitClear(mode, 8); // Clears bit 8 544 | bitClear(mode, 7); // Clears bit 7 545 | writeRegister(TMP117_CONFIGURATION, mode); 546 | } 547 | else if (convTime == 1) // 0b001 548 | { 549 | bitClear(mode, 9); // Clears bit 9 550 | bitClear(mode, 8); // Clears bit 8 551 | bitWrite(mode, 7, 1); // Sets bit 7 to be 1 552 | writeRegister(TMP117_CONFIGURATION, mode); 553 | } 554 | else if (convTime == 2) // 0b010 555 | { 556 | bitClear(mode, 9); // Clears bit 9 557 | bitWrite(mode, 8, 1); // Sets bit 8 to be 1 558 | bitClear(mode, 7); // Clears bit 7 559 | writeRegister(TMP117_CONFIGURATION, mode); 560 | } 561 | else if (convTime == 3) // 0b011 562 | { 563 | bitClear(mode, 9); // Clears bit 9 564 | bitWrite(mode, 8, 1); // Sets bit 8 to be 1 565 | bitWrite(mode, 7, 1); // Sets bit 7 to be 1 566 | writeRegister(TMP117_CONFIGURATION, mode); 567 | } 568 | else if (convTime == 4) // 0b100 569 | { 570 | bitWrite(mode, 9, 1); // Sets bit 9 to be 1 571 | bitClear(mode, 8); // Clears bit 8 572 | bitClear(mode, 7); // Clears bit 7 573 | writeRegister(TMP117_CONFIGURATION, mode); 574 | } 575 | else if (convTime == 5) // 0b101 576 | { 577 | bitWrite(mode, 9, 1); // Sets bit 9 to be 1 578 | bitClear(mode, 8); // Clears bit 8 579 | bitWrite(mode, 7, 1); // Sets bit 7 to be 1 580 | writeRegister(TMP117_CONFIGURATION, mode); 581 | } 582 | else if (convTime == 6) // 0b110 583 | { 584 | bitWrite(mode, 9, 1); // Sets bit 9 to be 1 585 | bitWrite(mode, 8, 1); // Sets bit 8 to be 1 586 | bitClear(mode, 7); // Clears bit 7 587 | writeRegister(TMP117_CONFIGURATION, mode); 588 | } 589 | else if (convTime == 7) // 0b111 590 | { 591 | bitWrite(mode, 9, 1); // Sets bit 9 to be 1 592 | bitWrite(mode, 8, 1); // Sets bit 8 to be 1 593 | bitWrite(mode, 7, 1); // Sets bit 7 to be 1 594 | writeRegister(TMP117_CONFIGURATION, mode); 595 | } 596 | } 597 | 598 | /* GET CONVERSION CYCLE BIT 599 | This function returns the Conversion Cycle Bit value that the 600 | device is currently in at the time. This bit can help determine 601 | the conversion cycle time that the device is in while being in 602 | continuous conversion mode. 603 | 604 | Conversion Cycle Time in CC Mode (found on the datasheet page 26 table 6) 605 | AVG 0 1 2 3 606 | CONV averaging (0) (8) (32) (64) 607 | 0 15.5ms 125ms 500ms 1s 608 | 1 125ms 125ms 500ms 1s 609 | 2 250ms 250ms 500ms 1s 610 | 3 500ms 500ms 500ms 1s 611 | 4 1s 1s 1s 1s 612 | 5 4s 4s 4s 4s 613 | 6 8s 8s 8s 8s 614 | 7 16s 16s 16s 16s 615 | */ 616 | uint8_t TMP117::getConversionCycleBit() 617 | { 618 | uint16_t configReg = 0; 619 | configReg = readRegister(TMP117_CONFIGURATION); // Fills configReg with config register values 620 | 621 | uint8_t currentTime9 = bitRead(configReg, 9); // Left most bit (9) 622 | uint8_t currentTime8 = bitRead(configReg, 8); // Middle bit (8) 623 | uint8_t currentTime7 = bitRead(configReg, 7); // Right most bit (7) 624 | 625 | if ((currentTime9 == 0) && (currentTime8 == 0) && (currentTime7 == 0)) // 0b000 626 | { 627 | return 0b000; 628 | } 629 | else if ((currentTime9 == 0) && (currentTime8 == 0) && (currentTime7 == 1)) // 0b001 630 | { 631 | return 0b001; 632 | } 633 | else if ((currentTime9 == 0) && (currentTime8 == 1) && (currentTime7 == 0)) // 0b010 634 | { 635 | return 0b010; 636 | } 637 | else if ((currentTime9 == 0) && (currentTime8 == 1) && (currentTime7 == 1)) // 0b011 638 | { 639 | return 0b011; 640 | } 641 | else if ((currentTime9 == 1) && (currentTime8 == 0) && (currentTime7 == 0)) // 0b100 642 | { 643 | return 0b100; 644 | } 645 | else if ((currentTime9 == 1) && (currentTime8 == 0) && (currentTime7 == 1)) // 0b101 646 | { 647 | return 0b101; 648 | } 649 | else if ((currentTime9 == 1) && (currentTime8 == 1) && (currentTime7 == 0)) // 0b110 650 | { 651 | return 0b110; 652 | } 653 | else if ((currentTime9 == 1) && (currentTime8 == 1) && (currentTime7 == 1)) // 0b111 654 | { 655 | return 0b111; 656 | } 657 | else 658 | { 659 | return 0b000; //Default 660 | } 661 | } 662 | 663 | /* DATA READY 664 | This function checks to see if there is data ready to be sent 665 | from the TMP117. This can be found in Page 25 Table 6 of the 666 | data sheet. 667 | */ 668 | bool TMP117::dataReady() 669 | { 670 | uint16_t response = readRegister(TMP117_CONFIGURATION); 671 | 672 | // If statement to see if the 13th bit of the register is 1 or not 673 | if (response & 1 << 13) 674 | { 675 | return true; 676 | } 677 | else 678 | { 679 | return false; 680 | } 681 | } 682 | -------------------------------------------------------------------------------- /src/SparkFun_TMP117.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | SparkFunTMP117.h 3 | SparkFunTMP117 Library Header File 4 | Madison Chodikov @ SparkFun Electronics 5 | Original Creation Date: April 29, 2016 6 | https://github.com/sparkfunX/Qwiic_TMP117 7 | 8 | This file prototypes the TMP117 class, implemented in SparkFunTMP117.cpp. 9 | 10 | Development environment specifics: 11 | IDE: Arduino 1.8.9 12 | Hardware Platform: Arduino Uno 13 | TMP117 Breakout Version: 1.0.0 14 | 15 | This code is beerware; if you see me (or any other SparkFun employee) at the 16 | local, and you've found our code helpful, please buy us a round! 17 | 18 | Distributed as-is; no warranty is given. 19 | ******************************************************************************/ 20 | 21 | #ifndef __SparkFun_TMP117_H__ 22 | #define __SparkFun_TMP117_H__ 23 | 24 | #include 25 | #include 26 | #include "SparkFun_TMP117_Registers.h" 27 | 28 | #define DEVICE_ID_VALUE 0x0117 // Value found in the device ID register on reset (page 24 Table 3 of datasheet) 29 | #define TMP117_RESOLUTION 0.0078125f // Resolution of the device, found on (page 1 of datasheet) 30 | #define CONTINUOUS_CONVERSION_MODE 0b00 // Continuous Conversion Mode 31 | #define ONE_SHOT_MODE 0b11 // One Shot Conversion Mode 32 | #define SHUTDOWN_MODE 0b01 // Shutdown Conversion Mode 33 | 34 | // Configuration register found on page 25 Figure 26 and Table 6 35 | typedef union { 36 | struct 37 | { 38 | uint8_t EMPTY : 1; // Empty bit in register 39 | uint8_t TMP_SOFT_RESET : 1; // Software reset bit 40 | uint8_t DR_ALERT : 1; // ALERT pin select bit 41 | uint8_t POL : 1; // ALERT pin polarity bit 42 | uint8_t T_NA : 1; // Therm/alert mode select 43 | uint8_t AVG : 2; // Conversion averaging modes 44 | uint8_t CONV : 3; // Conversion cycle bit 45 | uint8_t MOD : 2; // Set conversion mode 46 | uint8_t EEPROM_BUSY : 1; // EEPROM busy flag 47 | uint8_t DATA_READY : 1; // Data ready flag 48 | uint8_t LOW_ALERT : 1; // Low Alert flag 49 | uint8_t HIGH_ALERT : 1; // High Alert flag 50 | } CONFIGURATION_FIELDS; 51 | uint16_t CONFIGURATION_COMBINED; 52 | } CONFIGURATION_REG; 53 | 54 | // Device ID Register used for checking if the device ID is the same as declared 55 | // This register is found on Page 30 of the datasheet in Table 15 and Figure 34 56 | typedef union { 57 | struct 58 | { 59 | uint16_t DID : 12; // Indicates the device ID 60 | uint8_t REV : 4; // Indicates the revision number 61 | } DEVICE_ID_FIELDS; 62 | uint16_t DEVICE_ID_COMBINED; 63 | } DEVICE_ID_REG; 64 | 65 | class TMP117 66 | { 67 | public: 68 | TMP117(); // Constructor 69 | 70 | bool begin(uint8_t sensorAddress = 0x48, TwoWire &wirePort = Wire); // Checks for ACK over I2C, and sets the device ID of the TMP and chooses the wire port 71 | uint8_t getAddress(); // Returns the address of the device 72 | double readTempC(); // Returns the temperature in degrees C 73 | double readTempF(); // Converts readTempC result to degrees F 74 | void softReset(); // Performs a software reset on the Configuration Register Field bits 75 | float getTemperatureOffset(); // Reads the temperature offset 76 | void setTemperatureOffset(float offset); // Writes to the temperature offset 77 | float getLowLimit(); // Returns the low limit register 78 | void setLowLimit(float lowLimit); // Sets the low limit temperature for the low limit register 79 | float getHighLimit(); // Returns the high limit register 80 | void setHighLimit(float highLimit); // Sets the low limit temperature for the low limit register 81 | uint16_t getConfigurationRegister(); // Get Configuration Register 82 | uint8_t getHighLowAlert(); // Reads in Alert mode for high and low alert flags 83 | bool getHighAlert(); // Reads in Alert mode for a high alert flag 84 | bool getLowAlert(); // Reads in Alert mode for a low alert flag 85 | void setAlertFunctionMode(uint8_t setAlertMode); // Set alert or therm mode 86 | uint8_t getAlertFunctionMode(); // Check to see if in alert or therm mode 87 | uint8_t getConversionMode(); // Checks to see the Conversion Mode the device is currently in 88 | void setContinuousConversionMode(); // Sets the Conversion Mode of the Device to be Continuous 89 | void setOneShotMode(); // Sets the Conversion Mode of the Device to be One Shot 90 | void setShutdownMode(); // Sets the Conversion Mode of the Device to be Shutdown 91 | void setConversionAverageMode(uint8_t convMode); // Sets the conversion averaging mode 92 | uint8_t getConversionAverageMode(); // Returns the Conversion Averaging Mode 93 | void setConversionCycleBit(uint8_t convTime); // Sets the conversion cycle time bit 94 | uint8_t getConversionCycleBit(); // Returns the conversion cycle time bit value 95 | bool dataReady(); // Checks to see if there is data ready from the device 96 | 97 | uint16_t readRegister(uint8_t reg); // Reads 2 register bytes from sensor 98 | void writeRegister(uint8_t reg, uint16_t data); // Wires single byte of data to the sensor 99 | private: 100 | TwoWire *_i2cPort = NULL; //The generic connection to user's chosen I2C hardware 101 | uint8_t _deviceAddress; // Address of Temperature sensor 102 | }; 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /src/SparkFun_TMP117_Registers.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | SparkFun_TMP117_Registers.h 3 | TMP117 Library - TMP117 Register Map 4 | Madison Chodikov @ SparkFun Electronics 5 | Original Creation Date: April 19, 2019 6 | https://github.com/sparkfunX/Qwiic_TMP117 7 | 8 | This file defines all registers internal to the TMP117 sensor. 9 | 10 | Development environment specifics: 11 | IDE: Arduino 1.8.9 12 | Hardware Platform: Arduino Uno 13 | TMP117 Breakout Version: 1.0.0 14 | 15 | This code is beerware; if you see me (or any other SparkFun employee) at the 16 | local, and you've found our code helpful, please buy us a round! 17 | 18 | Distributed as-is; no warranty is given. 19 | ******************************************************************************/ 20 | 21 | #ifndef __SparkFun_TMP117_Registers_H__ 22 | #define __SparkFun_TMP117_Registers_H__ 23 | /* 24 | TMP117 Registers as defined in Table 3 from datasheet (pg 24) 25 | Features of the TMP117: 26 | - ±0.1°C (Maximum) From –20°C to +50°C 27 | - ±0.15°C (Maximum) From –40°C to +70°C 28 | - ±0.2°C (Maximum) From –40°C to +100°C 29 | - ±0.25°C (Maximum) From –55°C to +125°C 30 | - ±0.3°C (Maximum) From –55°C to +150°C 31 | - Low Power Consumption 3.5-µA, 1-Hz Conversion Cycle 32 | */ 33 | 34 | // Address of the registers. This can be found on page 23 of the datasheet 35 | enum TMP117_Register 36 | { 37 | TMP117_TEMP_RESULT = 0X00, 38 | TMP117_CONFIGURATION = 0x01, 39 | TMP117_T_HIGH_LIMIT = 0X02, 40 | TMP117_T_LOW_LIMIT = 0X03, 41 | TMP117_EEPROM_UL = 0X04, 42 | TMP117_EEPROM1 = 0X05, 43 | TMP117_EEPROM2 = 0X06, 44 | TMP117_TEMP_OFFSET = 0X07, 45 | TMP117_EEPROM3 = 0X08, 46 | TMP117_DEVICE_ID = 0X0F 47 | }; 48 | 49 | #endif --------------------------------------------------------------------------------