1
- /* *****************************************************************************
1
+ /* *****************************************************************************
2
2
SparkFunMLX90614.h
3
3
Header file for the SparkFun IR Thermometer Library
4
4
@@ -20,6 +20,16 @@ SparkFun IR Thermometer Evaluation Board - MLX90614
20
20
#include < Arduino.h>
21
21
#include < Wire.h>
22
22
23
+ // /////////////////////////////////////////
24
+ // Default I2C PIN for non Atmega Boards //
25
+ // /////////////////////////////////////////
26
+ #ifndef SDA
27
+ #define SDA (digitalPinToPinName(PIN_WIRE_SDA))
28
+ #endif
29
+ #ifndef SCL
30
+ #define SCL (digitalPinToPinName(PIN_WIRE_SCL))
31
+ #endif
32
+
23
33
// ////////////////////////////////
24
34
// MLX90614 Default I2C Address //
25
35
// ////////////////////////////////
@@ -53,134 +63,134 @@ typedef enum {
53
63
TEMP_F
54
64
} temperature_units;
55
65
56
- class IRTherm
66
+ class IRTherm
57
67
{
58
68
public:
59
69
// Default constructor, does very little besides setting class variable
60
70
// initial values.
61
71
IRTherm ();
62
-
63
- // begin(<address>) initializes the Wire library, and prepares
64
- // communication with an MLX90614 device at the specified 7-bit I2C
72
+
73
+ // begin(<address>) initializes the Wire library, and prepares
74
+ // communication with an MLX90614 device at the specified 7-bit I2C
65
75
// address.
66
76
// If no parameter is supplied, the default MLX90614 address is used.
67
77
uint8_t begin (uint8_t address = MLX90614_DEFAULT_ADDRESS);
68
-
69
- // setUnit(<unit>) configures the units returned by the ambient(),
70
- // object(), minimum() and maximum() functions, and it determines what
78
+
79
+ // setUnit(<unit>) configures the units returned by the ambient(),
80
+ // object(), minimum() and maximum() functions, and it determines what
71
81
// units the setMin() and setMax() functions should expect.
72
82
// <unit> can be either:
73
83
// - TEMP_RAW: No conversion, just the raw 12-bit ADC reading
74
84
// - TEMP_K: Kelvin
75
85
// - TEMP_C: Celsius
76
86
// - TEMP_F: Farenheit
77
87
void setUnit (temperature_units unit);
78
-
79
- // read() pulls the latest ambient and object temperatures from the
80
- // MLX90614. It will return either 1 on success or 0 on failure. (Failure
88
+
89
+ // read() pulls the latest ambient and object temperatures from the
90
+ // MLX90614. It will return either 1 on success or 0 on failure. (Failure
81
91
// can result from either a timed out I2C transmission, or an incorrect
82
92
// checksum value).
83
93
uint8_t read (void );
84
-
85
- // object() returns the MLX90614's most recently read object temperature
94
+
95
+ // object() returns the MLX90614's most recently read object temperature
86
96
// after the read() function has returned successfully. The float value
87
97
// returned will be in the units specified by setUnit().
88
98
float object (void );
89
-
90
- // ambient() returns the MLX90614's most recently read ambient temperature
99
+
100
+ // ambient() returns the MLX90614's most recently read ambient temperature
91
101
// after the read() function has returned successfully. The float value
92
102
// returned will be in the units specified by setUnit().
93
103
float ambient (void );
94
-
95
- // readEmissivity() reads the MLX90614's emissivity setting. It will
104
+
105
+ // readEmissivity() reads the MLX90614's emissivity setting. It will
96
106
// return a value between 0.1 and 1.0.
97
107
float readEmissivity (void );
98
-
99
- // setEmissivity(<emis>) can set the MLX90614's configured emissivity
108
+
109
+ // setEmissivity(<emis>) can set the MLX90614's configured emissivity
100
110
// EEPROM value.
101
111
// The <emis> parameter should be a value between 0.1 and 1.0.
102
112
// The function will return either 1 on success or 0 on failure.
103
113
uint8_t setEmissivity (float emis);
104
-
114
+
105
115
// readAddress() returns the MLX90614's configured 7-bit I2C bus address.
106
116
// A value between 0x01 and 0x7F should be returned.
107
117
uint8_t readAddress (void );
108
-
118
+
109
119
// setAddress(<newAdd>) can set the MLX90614's 7-bit I2C bus address.
110
120
// The <newAdd> parameter should be a value between 0x01 and 0x7F.
111
121
// The function returns 1 on success and 0 on failure.
112
122
// The new address won't take effect until the device is reset.
113
123
uint8_t setAddress (uint8_t newAdd);
114
-
124
+
115
125
// readID() reads the 64-bit ID of the MLX90614.
116
126
// Return value is either 1 on success or 0 on failure.
117
127
uint8_t readID (void );
118
-
128
+
119
129
// After calling readID() getIDH() and getIDL() can be called to read
120
130
// the upper 4 bytes and lower 4-bytes, respectively, of the MLX90614's
121
131
// identification registers.
122
132
uint32_t getIDH (void );
123
133
uint32_t getIDL (void );
124
-
134
+
125
135
// readRange() pulls the object maximum and minimum values stored in the
126
136
// MLX90614's EEPROM.
127
137
// It will return either 1 on success or 0 on failure.
128
138
uint8_t readRange (void );
129
-
139
+
130
140
// minimum() and maximum() return the MLX90614's minimum and maximum object
131
141
// sensor readings.
132
142
// The float values returned will be in the units specified by setUnit().
133
143
float minimum (void );
134
144
float maximum (void );
135
-
136
- // setMax(<maxTemp>) and setMin(<minTemp>) configure the MLX90614's
145
+
146
+ // setMax(<maxTemp>) and setMin(<minTemp>) configure the MLX90614's
137
147
// maximum and minimum object sensor temperatures.
138
148
uint8_t setMax (float maxTemp);
139
149
uint8_t setMin (float minTemp);
140
-
150
+
141
151
// sleep() sets the MLX90614 into a low-power sleep mode.
142
152
uint8_t sleep (void );
143
-
153
+
144
154
// wake() should revive the MLX90614 from low-power sleep mode.
145
155
uint8_t wake (void );
146
-
156
+
147
157
private:
148
158
uint8_t _deviceAddress; // MLX90614's 7-bit I2C address
149
159
temperature_units _defaultUnit; // Keeps track of configured temperature unit
150
-
160
+
151
161
// These keep track of the raw temperature values read from the sensor:
152
162
int16_t _rawAmbient, _rawObject, _rawObject2, _rawMax, _rawMin;
153
-
163
+
154
164
uint16_t id[4 ]; // Keeps track of the 64-bit ID value
155
-
165
+
156
166
// These functions individually read the object, object2, and ambient
157
167
// temperature values from the MLX90614's RAM:
158
168
uint8_t readObject (void );
159
169
uint8_t readObject2 (void );
160
170
uint8_t readAmbient (void );
161
-
171
+
162
172
// These functions individually read the min and mx temperatures in
163
173
// the MLX90614's EEPROM:
164
174
uint8_t readMax (void );
165
175
uint8_t readMin (void );
166
-
176
+
167
177
// calcTemperature converts a raw ADC temperature reading to the
168
178
// set unit.
169
179
float calcTemperature (int16_t rawTemp);
170
-
180
+
171
181
// calcRawTemperature converts a set unit temperature to a
172
182
// raw ADC value:
173
183
int16_t calcRawTemp (float calcTemp);
174
-
184
+
175
185
// Abstract function to write 16-bits to an address in the MLX90614's
176
186
// EEPROM
177
187
uint8_t writeEEPROM (byte reg, int16_t data);
178
-
188
+
179
189
// Abstract functions to read and write 16-bit values from a RAM
180
190
// or EEPROM address in the MLX90614
181
191
uint8_t I2CReadWord (byte reg, int16_t * dest);
182
192
uint8_t I2CWriteWord (byte reg, int16_t data);
183
-
193
+
184
194
// crc8 returns a calculated crc value given an initial value and
185
195
// input data.
186
196
// It's configured to calculate the CRC using a x^8+x^2+x^1+1 poly
0 commit comments