BayEOSArduino Library
MLX90614.h
1 /***************************************************
2  This is a library for the MLX90614 Temp Sensor
3 
4  Designed specifically to work with the MLX90614 sensors in the
5  adafruit shop
6  ----> https://www.adafruit.com/products/1748
7  ----> https://www.adafruit.com/products/1749
8 
9  These sensors use I2C to communicate, 2 pins are required to
10  interface
11  Adafruit invests time and resources providing this open source code,
12  please support Adafruit and open-source hardware by purchasing
13  products from Adafruit!
14 
15  Written by Limor Fried/Ladyada for Adafruied in any redistribution
16  ****************************************************/
17 
18 
19 #if (ARDUINO >= 100)
20  #include "Arduino.h"
21 #else
22  #include "WProgram.h"
23 #endif
24 #include "Wire.h"
25 
26 
27 #define MLX90614_I2CADDR 0x5A
28 
29 // RAM
30 #define MLX90614_RAWIR1 0x04
31 #define MLX90614_RAWIR2 0x05
32 #define MLX90614_TA 0x06
33 #define MLX90614_TOBJ1 0x07
34 #define MLX90614_TOBJ2 0x08
35 // EEPROM
36 #define MLX90614_TOMAX 0x20
37 #define MLX90614_TOMIN 0x21
38 #define MLX90614_PWMCTRL 0x22
39 #define MLX90614_TARANGE 0x23
40 #define MLX90614_EMISS 0x24
41 #define MLX90614_CONFIG 0x25
42 #define MLX90614_ADDR 0x0E
43 #define MLX90614_ID1 0x3C
44 #define MLX90614_ID2 0x3D
45 #define MLX90614_ID3 0x3E
46 #define MLX90614_ID4 0x3F
47 
48 //SLEEP mode
49 #define MLX90614_SLEEP_MODE 0xff
50 
51 class MLX90614 {
52  public:
53  MLX90614(uint8_t addr = MLX90614_I2CADDR);
54  boolean begin();
55  uint32_t readID(void);
56 
57  double readObjectTempC(uint8_t tries=3);
58  double readAmbientTempC(uint8_t tries=3);
59  double readObjectTempF(uint8_t tries=3);
60  double readAmbientTempF(uint8_t tries=3);
61  void enterSleepMode(void);
62 
63 
64  /* *******************************************************
65  * Note: Exiting sleep mode may not work for all arduinos
66  * We had to use some low level Register functions
67  * Testet from ATMEGA328
68  *
69  * *******************************************************/
70  void exitSleepMode(int t_delay=100);
71  uint8_t crc8 (uint8_t inCrc, uint8_t inData);
72 
73  private:
74  float readTemp(uint8_t reg, uint8_t tries=3);
75 
76  uint8_t _addr;
77  uint16_t read16(uint8_t addr);
78  void write16(uint8_t addr, uint16_t data);
79 };
80 
Definition: MLX90614.h:51