Adafruit TMP117 Library
Adafruit_TMP117.h
Go to the documentation of this file.
1 
15 // "requires_busio": "y",
16 // "requires_sensor": "y",
17 #ifndef _ADAFRUIT_TMP117_H
18 #define _ADAFRUIT_TMP117_H
19 
20 #include "Arduino.h"
21 #include <Adafruit_BusIO_Register.h>
22 #include <Adafruit_I2CDevice.h>
23 #include <Adafruit_Sensor.h>
24 #include <Wire.h>
25 
26 #define TMP117_I2CADDR_DEFAULT 0x48
27 #define TMP117_CHIP_ID 0x0117
28 
29 #define TMP117_WHOAMI 0x0F
30 #define _CONFIGURATION 0x01
31 
32 #define TMP117_TEMP_DATA 0x00
33 #define TMP117_CONFIGURATION 0x01
34 #define TMP117_T_HIGH_LIMIT 0x02
35 #define TMP117_T_LOW_LIMIT 0x03
36 #define TMP117_TEMP_OFFSET 0x07
37 #define TMP117_DEVICE_ID 0x0F
38 #define WHOAMI_ANSWER 0x0117
39 
40 #define HIGH_ALRT_FLAG 0b100
41 #define LOW_ALRT_FLAG 0b010
42 #define DRDY_ALRT_FLAG 0b001
43 
44 #define TMP117_RESOLUTION \
45  0.0078125f
46 
47 // #define TMP117_EEPROM_UL 0x04
48 // #define TMP117_EEPROM1 0x05
49 // #define TMP117_EEPROM2 0x06
50 // #define TMP117_EEPROM3 0x08
51 
53 
59 typedef enum {
60  TMP117_RATE_ONE_SHOT,
62 
69 typedef struct {
70  bool high;
71  bool low;
72  bool data_ready;
74 
79 typedef enum {
80  TMP117_AVERAGE_1X,
81  TMP117_AVERAGE_8X,
82  TMP117_AVERAGE_32X,
83  TMP117_AVERAGE_64X,
85 
90 typedef enum {
91  TMP117_DELAY_0_MS,
92  TMP117_DELAY_125_MS,
93  TMP117_DELAY_250_MS,
94  TMP117_DELAY_500_MS,
95  TMP117_DELAY_1000_MS,
96  TMP117_DELAY_4000_MS,
97  TMP117_DELAY_8000_MS,
98  TMP117_DELAY_16000_MS,
100 
125 typedef enum {
126  TMP117_MODE_CONTINUOUS,
127  TMP117_MODE_SHUTDOWN,
128  TMP117_MODE_ONE_SHOT = 3, // skipping 0x2 which is a duplicate CONTINUOUS
129 } tmp117_mode_t;
130 
136 public:
137  Adafruit_TMP117();
139 
140  bool begin(uint8_t i2c_addr = TMP117_I2CADDR_DEFAULT, TwoWire *wire = &Wire,
141  int32_t sensor_id = 117);
142  void reset(void);
143  void interruptsActiveLow(bool active_low);
144  bool interruptsActiveLow(void);
145 
146  bool getEvent(sensors_event_t *temp);
147  bool getAlerts(tmp117_alerts_t *alerts);
148 
149  bool thermAlertModeEnabled(bool therm_enabled);
150  bool thermAlertModeEnabled(void);
151 
154 
155  float getOffset(void);
156  bool setOffset(float offset);
157 
158  float getLowThreshold(void);
159  bool setLowThreshold(float low_threshold);
160 
161  float getHighThreshold(void);
162  bool setHighThreshold(float high_threshold);
163 
165  bool setReadDelay(tmp117_delay_t delay);
166 
169 
170 private:
171  // void _read(void);
172  bool _init(int32_t sensor_id);
173  uint16_t _sensorid_temp;
174 
176  alert_drdy_flags;
177  float unscaled_temp;
178 
179  Adafruit_I2CDevice *i2c_dev = NULL;
180  Adafruit_BusIO_Register *config_reg =
181  NULL;
182  Adafruit_BusIO_Register *temp_reg =
183  NULL;
184 
185  void readAlertsDRDY(void);
186  bool getDataReady(void);
187  void waitForData(void);
188 };
189 
190 #endif
bool setLowThreshold(float low_threshold)
Set a new low temperature threshold.
Definition: Adafruit_TMP117.cpp:191
tmp117_mode_t
Options to set the measurement mode of the sensor.
Definition: Adafruit_TMP117.h:125
Class that stores state and functions for interacting with the TMP117 High-Accuracy Temperature Senso...
Definition: Adafruit_TMP117.h:135
bool data_ready
Status of the data_ready alert.
Definition: Adafruit_TMP117.h:72
Adafruit_TMP117()
Construct a new Adafruit_TMP117::Adafruit_TMP117 object.
Definition: Adafruit_TMP117.cpp:45
tmp117_delay_t getReadDelay(void)
Get current setting for the minimum delay between calculated temperature reads.
Definition: Adafruit_TMP117.cpp:354
bool setAveragedSampleCount(tmp117_average_count_t count)
Set the number of raw measurements that are averaged into the reported temperature.
Definition: Adafruit_TMP117.cpp:341
tmp117_rate_t
Allowed values for setDataRate.
Definition: Adafruit_TMP117.h:59
#define TMP117_I2CADDR_DEFAULT
TMP117 default i2c address.
Definition: Adafruit_TMP117.h:26
bool begin(uint8_t i2c_addr=TMP117_I2CADDR_DEFAULT, TwoWire *wire=&Wire, int32_t sensor_id=117)
Sets up the hardware and initializes I2C.
Definition: Adafruit_TMP117.cpp:70
tmp117_mode_t getMeasurementMode(void)
Read the active measurement mode.
Definition: Adafruit_TMP117.cpp:378
bool interruptsActiveLow(void)
Get the polarity of the INT pin.
Definition: Adafruit_TMP117.cpp:245
bool thermAlertModeEnabled(void)
Get the current enable status of the "THERM" alert mode.
Definition: Adafruit_TMP117.cpp:310
float getHighThreshold(void)
Read the current high temperature threshold.
Definition: Adafruit_TMP117.cpp:203
bool low
Status of the low temperature alert.
Definition: Adafruit_TMP117.h:71
bool getEvent(sensors_event_t *temp)
Gets the pressure sensor and temperature values as sensor events.
Definition: Adafruit_TMP117.cpp:130
bool getAlerts(tmp117_alerts_t *alerts)
Get the current state of the alert flags.
Definition: Adafruit_TMP117.cpp:161
void reset(void)
Performs a software reset initializing registers to their power on state.
Definition: Adafruit_TMP117.cpp:113
tmp117_delay_t
Options to specify the minimum delay between new measurements.
Definition: Adafruit_TMP117.h:90
A struct to hold alert state information.
Definition: Adafruit_TMP117.h:69
float getLowThreshold(void)
Read the current low temperature threshold.
Definition: Adafruit_TMP117.cpp:176
bool setReadDelay(tmp117_delay_t delay)
Set a new minimum delay between calculated reads.
Definition: Adafruit_TMP117.cpp:367
tmp117_average_count_t getAveragedSampleCount(void)
Read the current number of samples that are averaged to calculate the reported temperature.
Definition: Adafruit_TMP117.cpp:322
bool setOffset(float offset)
Write a new temperature offset.
Definition: Adafruit_TMP117.cpp:269
bool setHighThreshold(float high_threshold)
Set a new high temperature threshold.
Definition: Adafruit_TMP117.cpp:218
bool setMeasurementMode(tmp117_mode_t mode)
Set a new measurement mode.
Definition: Adafruit_TMP117.cpp:392
bool high
Status of the high temperature alert.
Definition: Adafruit_TMP117.h:70
~Adafruit_TMP117()
Destroy the Adafruit_TMP117::Adafruit_TMP117 object.
Definition: Adafruit_TMP117.cpp:51
tmp117_average_count_t
Options for setAveragedSampleCount.
Definition: Adafruit_TMP117.h:79
float getOffset(void)
Read the current temperature offset.
Definition: Adafruit_TMP117.cpp:256