Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 13ba847

Browse files
author
Jim Lindblom
committedOct 28, 2015
initial commit of library
1 parent 4b34591 commit 13ba847

File tree

8 files changed

+836
-2
lines changed

8 files changed

+836
-2
lines changed
 

‎.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Ignore list for Eagle, a PCB layout tool
2+
3+
# Backup files
4+
*.s#?
5+
*.b#?
6+
*.l#?
7+
8+
# Eagle project file
9+
# It contains a serial number and references to the file structure
10+
# on your computer.
11+
# comment the following line if you want to have your project file included.
12+
eagle.epf
13+
14+
# CAM files
15+
*.$$$
16+
*.cmp
17+
*.ly2
18+
*.l15
19+
*.sol
20+
*.plc
21+
*.stc
22+
*.sts
23+
*.crc
24+
*.crs
25+
26+
*.dri
27+
*.drl
28+
*.gpi
29+
*.pls
30+
31+
*.drd
32+
*.drd.*
33+
34+
*.info
35+
36+
*.eps

‎README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
1-
# SparkFun_MLX90614_Arduino_Library
2-
Arduino library for the MLX90614 Infrared Thermometer.
1+
SparkFun MLX90614 Arduino Library
2+
========================================
3+
4+
![SparkFun Infrared Thermometer Evaluation Board](https://cdn.sparkfun.com//assets/parts/5/6/4/6/10740-01a.jpg)
5+
6+
[*SparkFun Infrared Thermometer Evaluation Board (SEN-10740)*](https://www.sparkfun.com/products/10740)
7+
8+
An Arduino library that interfaces with the MLX90614 non-contact infrared thermometer over a 2-wire, I2C-like interface (SMBus).
9+
10+
Repository Contents
11+
-------------------
12+
13+
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
14+
* * **/src** - Source files for the library (.cpp, .h).
15+
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
16+
* **library.properties** - General library properties for the Arduino package manager.
17+
18+
Documentation
19+
--------------
20+
21+
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
22+
* **[Product Repository](https://github.com/sparkfun/IR_Thermometer_Evaluation_Board-MLX90614)** - Main repository (including hardware files) for the Infrared Thermometer Evaluation Board.
23+
* **[Hookup Guide](https://learn.sparkfun.com/tutorials/mlx90614-ir-thermometer-hookup-guide)** - Basic hookup guide for the Infrared Thermometer Evaluation Board.
24+
25+
Products that use this Library
26+
---------------------------------
27+
28+
* [Infrared Thermometer Evaluation Board - MLX90614](https://www.sparkfun.com/products/10740)- A Arduino-compatible evaluation board for the MLX90614.
29+
* [Infrared Thermometer - MLX90614 ](https://www.sparkfun.com/products/9570) -- The MLX90614 IC itself
30+
31+
Version History
32+
---------------
33+
* [V 1.0.0](https://github.com/sparkfun/SparkFun_MLX90614_Arduino_Library/tree/V_1.0.0) - Initial release
34+
35+
License Information
36+
-------------------
37+
38+
This product is _**open source**_!
39+
40+
The **code** is released under the MIT license. See the included LICENSE file for more information.
41+
42+
Distributed as-is; no warranty is given.
43+
44+
- Your friends at SparkFun.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/******************************************************************************
2+
MLX90614_Serial_Demo.ino
3+
Serial output example for the MLX90614 Infrared Thermometer
4+
5+
This example reads from the MLX90614 and prints out ambient and object
6+
temperatures every half-second or so. Open the serial monitor and set the
7+
baud rate to 9600.
8+
9+
Hardware Hookup (if you're not using the eval board):
10+
MLX90614 ------------- Arduino
11+
VDD ------------------ 3.3V
12+
VSS ------------------ GND
13+
SDA ------------------ SDA (A4 on older boards)
14+
SCL ------------------ SCL (A5 on older boards)
15+
16+
An LED can be attached to pin 8 to monitor for any read errors.
17+
18+
Jim Lindblom @ SparkFun Electronics
19+
October 23, 2015
20+
https://github.com/sparkfun/SparkFun_MLX90614_Arduino_Library
21+
22+
Development environment specifics:
23+
Arduino 1.6.5
24+
SparkFun IR Thermometer Evaluation Board - MLX90614
25+
******************************************************************************/
26+
27+
#include <Wire.h> // I2C library, required for MLX90614
28+
#include <SparkFunMLX90614.h> // SparkFunMLX90614 Arduino library
29+
30+
IRTherm therm; // Create an IRTherm object to interact with throughout
31+
32+
const byte LED_PIN = 8; // Optional LED attached to pin 8 (active low)
33+
34+
void setup()
35+
{
36+
Serial.begin(9600); // Initialize Serial to log output
37+
therm.begin(); // Initialize thermal IR sensor
38+
therm.setUnit(TEMP_F); // Set the library's units to Farenheit
39+
// Alternatively, TEMP_F can be replaced with TEMP_C for Celsius or
40+
// TEMP_K for Kelvin.
41+
42+
pinMode(LED_PIN, OUTPUT); // LED pin as output
43+
setLED(LOW); // LED OFF
44+
}
45+
46+
void loop()
47+
{
48+
setLED(HIGH); //LED on
49+
50+
// Call therm.read() to read object and ambient temperatures from the sensor.
51+
if (therm.read()) // On success, read() will return 1, on fail 0.
52+
{
53+
// Use the object() and ambient() functions to grab the object and ambient
54+
// temperatures.
55+
// They'll be floats, calculated out to the unit you set with setUnit().
56+
Serial.print("Object: " + String(therm.object(), 2));
57+
Serial.write('°'); // Degree Symbol
58+
Serial.println("F");
59+
Serial.print("Ambient: " + String(therm.ambient(), 2));
60+
Serial.write('°'); // Degree Symbol
61+
Serial.println("F");
62+
Serial.println();
63+
}
64+
setLED(LOW);
65+
delay(500);
66+
}
67+
68+
void setLED(bool on)
69+
{
70+
if (on)
71+
digitalWrite(LED_PIN, LOW);
72+
else
73+
digitalWrite(LED_PIN, HIGH);
74+
}

‎extras/MLX90614_rev001.pdf

1.18 MB
Binary file not shown.

‎keywords.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#######################################
2+
# Syntax Coloring Map For SFE_MicroOLED
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
IRTherm KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
begin KEYWORD2
16+
setUnit KEYWORD2
17+
read KEYWORD2
18+
object KEYWORD2
19+
ambient KEYWORD2
20+
readEmissivity KEYWORD2
21+
setEmissivity KEYWORD2
22+
readAddress KEYWORD2
23+
setAddress KEYWORD2
24+
readID KEYWORD2
25+
getIDH KEYWORD2
26+
getIDL KEYWORD2
27+
readRange KEYWORD2
28+
minimum KEYWORD2
29+
maximum KEYWORD2
30+
setMax KEYWORD2
31+
setMin KEYWORD2
32+
sleep KEYWORD2
33+
wake KEYWORD2
34+
35+
#######################################
36+
# Constants (LITERAL1)
37+
#######################################
38+
TEMP_RAW LITERAL1
39+
TEMP_K LITERAL1
40+
TEMP_C LITERAL1
41+
TEMP_F LITERAL1

‎library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=SparkFun MLX90614
2+
version=1.0.0
3+
author=SparkFun Electronics <techsupport@sparkfun.com>
4+
maintainer=SparkFun Electronics <sparkfun.com>
5+
sentence=Library for the SparkFun IR Thermometer Evaluation Board and the MLX90614 IR thermometer.
6+
paragraph=Library for the SparkFun IR Thermometer Evaluation Board and the MLX90614 IR thermometer.
7+
category=Sensors
8+
url=https://github.com/sparkfun/SparkFun_MLX90614_Arduino_Library
9+
architectures=*

‎src/SparkFunMLX90614.cpp

Lines changed: 442 additions & 0 deletions
Large diffs are not rendered by default.

‎src/SparkFunMLX90614.h

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/******************************************************************************
2+
SparkFunMLX90614.h
3+
Header file for the SparkFun IR Thermometer Library
4+
5+
Jim Lindblom @ SparkFun Electronics
6+
October 23, 2015
7+
https://github.com/sparkfun/SparkFun_MLX90614_Arduino_Library
8+
9+
This file defines the SMBus hardware interface(s) for the MLX90614 IR thermometer
10+
and abstracts temperature measurments and other features of the MLX90614
11+
12+
Development environment specifics:
13+
Arduino 1.6.5
14+
SparkFun IR Thermometer Evaluation Board - MLX90614
15+
******************************************************************************/
16+
17+
#ifndef SPARKFUNMLX90164_H
18+
#define SPARKFUNMLX90164_H
19+
20+
#include <Arduino.h>
21+
#include <Wire.h>
22+
23+
//////////////////////////////////
24+
// MLX90614 Default I2C Address //
25+
//////////////////////////////////
26+
#define MLX90614_DEFAULT_ADDRESS 0x5A
27+
28+
///////////////////////////////////////
29+
// MLX90614 RAM and EEPROM Addresses //
30+
///////////////////////////////////////
31+
#define MLX90614_REGISTER_TA 0x06
32+
#define MLX90614_REGISTER_TOBJ1 0x07
33+
#define MLX90614_REGISTER_TOBJ2 0x08
34+
#define MLX90614_REGISTER_TOMAX 0x20
35+
#define MLX90614_REGISTER_TOMIN 0x21
36+
#define MLX90614_REGISTER_PWMCTRL 0x22
37+
#define MLX90614_REGISTER_TARANGE 0x23
38+
#define MLX90614_REGISTER_KE 0x24
39+
#define MLX90614_REGISTER_CONFIG 0x25
40+
#define MLX90614_REGISTER_ADDRESS 0x2E
41+
#define MLX90614_REGISTER_ID0 0x1C
42+
#define MLX90614_REGISTER_ID1 0x1D
43+
#define MLX90614_REGISTER_ID2 0x1E
44+
#define MLX90614_REGISTER_ID3 0x1F
45+
#define MLX90614_REGISTER_SLEEP 0xFF // Not really a register, but close enough
46+
47+
#define I2C_READ_TIMEOUT 1000
48+
49+
typedef enum temperature_units {
50+
TEMP_RAW,
51+
TEMP_K,
52+
TEMP_C,
53+
TEMP_F
54+
};
55+
56+
class IRTherm
57+
{
58+
public:
59+
// Default constructor, does very little besides setting class variable
60+
// initial values.
61+
IRTherm();
62+
63+
// begin(<address>) initializes the Wire library, and prepares
64+
// communication with an MLX90614 device at the specified 7-bit I2C
65+
// address.
66+
// If no parameter is supplied, the default MLX90614 address is used.
67+
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
71+
// units the setMin() and setMax() functions should expect.
72+
// <unit> can be either:
73+
// - TEMP_RAW: No conversion, just the raw 12-bit ADC reading
74+
// - TEMP_K: Kelvin
75+
// - TEMP_C: Celsius
76+
// - TEMP_F: Farenheit
77+
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
81+
// can result from either a timed out I2C transmission, or an incorrect
82+
// checksum value).
83+
uint8_t read(void);
84+
85+
// object() returns the MLX90614's most recently read object temperature
86+
// after the read() function has returned successfully. The float value
87+
// returned will be in the units specified by setUnit().
88+
float object(void);
89+
90+
// ambient() returns the MLX90614's most recently read ambient temperature
91+
// after the read() function has returned successfully. The float value
92+
// returned will be in the units specified by setUnit().
93+
float ambient(void);
94+
95+
// readEmissivity() reads the MLX90614's emissivity setting. It will
96+
// return a value between 0.1 and 1.0.
97+
float readEmissivity(void);
98+
99+
// setEmissivity(<emis>) can set the MLX90614's configured emissivity
100+
// EEPROM value.
101+
// The <emis> parameter should be a value between 0.1 and 1.0.
102+
// The function will return either 1 on success or 0 on failure.
103+
uint8_t setEmissivity(float emis);
104+
105+
// readAddress() returns the MLX90614's configured 7-bit I2C bus address.
106+
// A value between 0x01 and 0x7F should be returned.
107+
uint8_t readAddress(void);
108+
109+
// setAddress(<newAdd>) can set the MLX90614's 7-bit I2C bus address.
110+
// The <newAdd> parameter should be a value between 0x01 and 0x7F.
111+
// The function returns 1 on success and 0 on failure.
112+
// The new address won't take effect until the device is reset.
113+
uint8_t setAddress(uint8_t newAdd);
114+
115+
// readID() reads the 64-bit ID of the MLX90614.
116+
// Return value is either 1 on success or 0 on failure.
117+
uint8_t readID(void);
118+
119+
// After calling readID() getIDH() and getIDL() can be called to read
120+
// the upper 4 bytes and lower 4-bytes, respectively, of the MLX90614's
121+
// identification registers.
122+
uint32_t getIDH(void);
123+
uint32_t getIDL(void);
124+
125+
// readRange() pulls the object maximum and minimum values stored in the
126+
// MLX90614's EEPROM.
127+
// It will return either 1 on success or 0 on failure.
128+
uint8_t readRange(void);
129+
130+
// minimum() and maximum() return the MLX90614's minimum and maximum object
131+
// sensor readings.
132+
// The float values returned will be in the units specified by setUnit().
133+
float minimum(void);
134+
float maximum(void);
135+
136+
// setMax(<maxTemp>) and setMin(<minTemp>) configure the MLX90614's
137+
// maximum and minimum object sensor temperatures.
138+
uint8_t setMax(float maxTemp);
139+
uint8_t setMin(float minTemp);
140+
141+
// sleep() sets the MLX90614 into a low-power sleep mode.
142+
uint8_t sleep(void);
143+
144+
// wake() should revive the MLX90614 from low-power sleep mode.
145+
uint8_t wake(void);
146+
147+
private:
148+
uint8_t _deviceAddress; // MLX90614's 7-bit I2C address
149+
temperature_units _defaultUnit; // Keeps track of configured temperature unit
150+
151+
// These keep track of the raw temperature values read from the sensor:
152+
int16_t _rawAmbient, _rawObject, _rawObject2, _rawMax, _rawMin;
153+
154+
uint16_t id[4]; // Keeps track of the 64-bit ID value
155+
156+
// These functions individually read the object, object2, and ambient
157+
// temperature values from the MLX90614's RAM:
158+
uint8_t readObject(void);
159+
uint8_t readObject2(void);
160+
uint8_t readAmbient(void);
161+
162+
// These functions individually read the min and mx temperatures in
163+
// the MLX90614's EEPROM:
164+
uint8_t readMax(void);
165+
uint8_t readMin(void);
166+
167+
// calcTemperature converts a raw ADC temperature reading to the
168+
// set unit.
169+
float calcTemperature(int16_t rawTemp);
170+
171+
// calcRawTemperature converts a set unit temperature to a
172+
// raw ADC value:
173+
int16_t calcRawTemp(float calcTemp);
174+
175+
// Abstract function to write 16-bits to an address in the MLX90614's
176+
// EEPROM
177+
uint8_t writeEEPROM(byte reg, int16_t data);
178+
179+
// Abstract functions to read and write 16-bit values from a RAM
180+
// or EEPROM address in the MLX90614
181+
uint8_t I2CReadWord(byte reg, int16_t * dest);
182+
uint8_t I2CWriteWord(byte reg, int16_t data);
183+
184+
// crc8 returns a calculated crc value given an initial value and
185+
// input data.
186+
// It's configured to calculate the CRC using a x^8+x^2+x^1+1 poly
187+
uint8_t crc8 (uint8_t inCrc, uint8_t inData);
188+
};
189+
190+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.