Adafruit AMG88xx Library
Adafruit_AMG88xx.h
1 #ifndef LIB_ADAFRUIT_AMG88XX_H
2 #define LIB_ADAFRUIT_AMG88XX_H
3 
4 #if (ARDUINO >= 100)
5 #include "Arduino.h"
6 #else
7 #include "WProgram.h"
8 #endif
9 
10 #include <Adafruit_I2CDevice.h>
11 
12 /*=========================================================================
13  I2C ADDRESS/BITS
14  -----------------------------------------------------------------------*/
15 #define AMG88xx_ADDRESS (0x69)
16 /*=========================================================================*/
17 
18 /*=========================================================================
19  REGISTERS
20  -----------------------------------------------------------------------*/
21 enum {
22  AMG88xx_PCTL = 0x00,
23  AMG88xx_RST = 0x01,
24  AMG88xx_FPSC = 0x02,
25  AMG88xx_INTC = 0x03,
26  AMG88xx_STAT = 0x04,
27  AMG88xx_SCLR = 0x05,
28  // 0x06 reserved
29  AMG88xx_AVE = 0x07,
30  AMG88xx_INTHL = 0x08,
31  AMG88xx_INTHH = 0x09,
32  AMG88xx_INTLL = 0x0A,
33  AMG88xx_INTLH = 0x0B,
34  AMG88xx_IHYSL = 0x0C,
35  AMG88xx_IHYSH = 0x0D,
36  AMG88xx_TTHL = 0x0E,
37  AMG88xx_TTHH = 0x0F,
38  AMG88xx_INT_OFFSET = 0x010,
39  AMG88xx_PIXEL_OFFSET = 0x80
40 };
41 
42 enum power_modes {
43  AMG88xx_NORMAL_MODE = 0x00,
44  AMG88xx_SLEEP_MODE = 0x01,
45  AMG88xx_STAND_BY_60 = 0x20,
46  AMG88xx_STAND_BY_10 = 0x21
47 };
48 
49 enum sw_resets { AMG88xx_FLAG_RESET = 0x30, AMG88xx_INITIAL_RESET = 0x3F };
50 
51 enum frame_rates { AMG88xx_FPS_10 = 0x00, AMG88xx_FPS_1 = 0x01 };
52 
53 enum int_enables { AMG88xx_INT_DISABLED = 0x00, AMG88xx_INT_ENABLED = 0x01 };
54 
55 enum int_modes { AMG88xx_DIFFERENCE = 0x00, AMG88xx_ABSOLUTE_VALUE = 0x01 };
56 
57 /*=========================================================================*/
58 
59 #define AMG88xx_PIXEL_ARRAY_SIZE 64
60 #define AMG88xx_PIXEL_TEMP_CONVERSION .25
61 #define AMG88xx_THERMISTOR_CONVERSION .0625
62 
63 /**************************************************************************/
68 /**************************************************************************/
70 public:
71  // constructors
72  Adafruit_AMG88xx(void){};
73  ~Adafruit_AMG88xx(void);
74 
75  bool begin(uint8_t addr = AMG88xx_ADDRESS, TwoWire *theWire = &Wire);
76 
77  void readPixelsRaw(uint8_t *buf, uint8_t pixels = AMG88xx_PIXEL_ARRAY_SIZE);
78  void readPixels(float *buf, uint8_t pixels = AMG88xx_PIXEL_ARRAY_SIZE);
79  float readThermistor();
80 
81  void setMovingAverageMode(bool mode);
82 
83  void enableInterrupt();
84  void disableInterrupt();
85  void setInterruptMode(uint8_t mode);
86  void getInterrupt(uint8_t *buf, uint8_t size = 8);
87  void clearInterrupt();
88 
89  // this will automatically set hysteresis to 95% of the high value
90  void setInterruptLevels(float high, float low);
91 
92  // this will manually set hysteresis
93  void setInterruptLevels(float high, float low, float hysteresis);
94 
95 private:
96  Adafruit_I2CDevice *i2c_dev = NULL;
97 
98  void write8(byte reg, byte value);
99  void write16(byte reg, uint16_t value);
100  uint8_t read8(byte reg);
101 
102  void read(uint8_t reg, uint8_t *buf, uint8_t num);
103  void write(uint8_t reg, uint8_t *buf, uint8_t num);
104 
105  float signedMag12ToFloat(uint16_t val);
106  float int12ToFloat(uint16_t val);
107 
108  // The power control register
109  struct pctl {
110  // 0x00 = Normal Mode
111  // 0x01 = Sleep Mode
112  // 0x20 = Stand-by mode (60 sec intermittence)
113  // 0x21 = Stand-by mode (10 sec intermittence)
114 
115  uint8_t PCTL : 8;
116 
117  uint8_t get() { return PCTL; }
118  };
119  pctl _pctl;
120 
121  // reset register
122  struct rst {
123  // 0x30 = flag reset (all clear status reg 0x04, interrupt flag and
124  // interrupt table) 0x3F = initial reset (brings flag reset and returns to
125  // initial setting)
126 
127  uint8_t RST : 8;
128 
129  uint8_t get() { return RST; }
130  };
131  rst _rst;
132 
133  // frame rate register
134  struct fpsc {
135 
136  // 0 = 10FPS
137  // 1 = 1FPS
138  uint8_t FPS : 1;
139 
140  uint8_t get() { return FPS & 0x01; }
141  };
142  fpsc _fpsc;
143 
144  // interrupt control register
145  struct intc {
146 
147  // 0 = INT output reactive (Hi-Z)
148  // 1 = INT output active
149  uint8_t INTEN : 1;
150 
151  // 0 = Difference interrupt mode
152  // 1 = absolute value interrupt mode
153  uint8_t INTMOD : 1;
154 
155  uint8_t get() { return (INTMOD << 1 | INTEN) & 0x03; }
156  };
157  intc _intc;
158 
159  // status register
160  struct stat {
161  uint8_t unused : 1;
162  // interrupt outbreak (val of interrupt table reg)
163  uint8_t INTF : 1;
164 
165  // temperature output overflow (val of temperature reg)
166  uint8_t OVF_IRS : 1;
167 
168  // thermistor temperature output overflow (value of thermistor)
169  uint8_t OVF_THS : 1;
170 
171  uint8_t get() {
172  return ((OVF_THS << 3) | (OVF_IRS << 2) | (INTF << 1)) & 0x0E;
173  }
174  };
175  stat _stat;
176 
177  // status clear register
178  // write to clear overflow flag and interrupt flag
179  // after writing automatically turns to 0x00
180  struct sclr {
181  uint8_t unused : 1;
182  // interrupt flag clear
183  uint8_t INTCLR : 1;
184  // temp output overflow flag clear
185  uint8_t OVS_CLR : 1;
186  // thermistor temp output overflow flag clear
187  uint8_t OVT_CLR : 1;
188 
189  uint8_t get() {
190  return ((OVT_CLR << 3) | (OVS_CLR << 2) | (INTCLR << 1)) & 0x0E;
191  }
192  };
193  sclr _sclr;
194 
195  // average register
196  // for setting moving average output mode
197  struct ave {
198  uint8_t unused : 5;
199  // 1 = twice moving average mode
200  uint8_t MAMOD : 1;
201 
202  uint8_t get() { return (MAMOD << 5); }
203  };
204  struct ave _ave;
205 
206  // interrupt level registers
207  // for setting upper / lower limit hysteresis on interrupt level
208 
209  // interrupt level upper limit setting. Interrupt output
210  // and interrupt pixel table are set when value exceeds set value
211  struct inthl {
212  uint8_t INT_LVL_H : 8;
213 
214  uint8_t get() { return INT_LVL_H; }
215  };
216  struct inthl _inthl;
217 
218  struct inthh {
219  uint8_t INT_LVL_H : 4;
220 
221  uint8_t get() { return INT_LVL_H; }
222  };
223  struct inthh _inthh;
224 
225  // interrupt level lower limit. Interrupt output
226  // and interrupt pixel table are set when value is lower than set value
227  struct intll {
228  uint8_t INT_LVL_L : 8;
229 
230  uint8_t get() { return INT_LVL_L; }
231  };
232  struct intll _intll;
233 
234  struct intlh {
235  uint8_t INT_LVL_L : 4;
236 
237  uint8_t get() { return (INT_LVL_L & 0xF); }
238  };
239  struct intlh _intlh;
240 
241  // setting of interrupt hysteresis level when interrupt is generated.
242  // should not be higher than interrupt level
243  struct ihysl {
244  uint8_t INT_HYS : 8;
245 
246  uint8_t get() { return INT_HYS; }
247  };
248  struct ihysl _ihysl;
249 
250  struct ihysh {
251  uint8_t INT_HYS : 4;
252 
253  uint8_t get() { return (INT_HYS & 0xF); }
254  };
255  struct ihysh _ihysh;
256 
257  // thermistor register
258  // SIGNED MAGNITUDE FORMAT
259  struct tthl {
260  uint8_t TEMP : 8;
261 
262  uint8_t get() { return TEMP; }
263  };
264  struct tthl _tthl;
265 
266  struct tthh {
267  uint8_t TEMP : 3;
268  uint8_t SIGN : 1;
269 
270  uint8_t get() { return ((SIGN << 3) | TEMP) & 0xF; }
271  };
272  struct tthh _tthh;
273 
274  // temperature registers 0x80 - 0xFF
275  /*
276  //read to indicate temperature data per 1 pixel
277  //SIGNED MAGNITUDE FORMAT
278  struct t01l {
279  uint8_t TEMP : 8;
280 
281  uint8_t get(){
282  return TEMP;
283  }
284  };
285  struct t01l _t01l;
286 
287  struct t01h {
288  uint8_t TEMP : 3;
289  uint8_t SIGN : 1;
290 
291  uint8_t get(){
292  return ( (SIGN << 3) | TEMP) & 0xF;
293  }
294  };
295  struct t01h _t01h;
296  */
297 };
298 
299 #endif
void getInterrupt(uint8_t *buf, uint8_t size=8)
Read the state of the triggered interrupts on the device. The full interrupt register is 8 bytes in l...
Definition: Adafruit_AMG88xx.cpp:140
void setMovingAverageMode(bool mode)
Set the moving average mode.
Definition: Adafruit_AMG88xx.cpp:50
void readPixelsRaw(uint8_t *buf, uint8_t pixels=AMG88xx_PIXEL_ARRAY_SIZE)
Read Infrared sensor raw values.
Definition: Adafruit_AMG88xx.cpp:180
void readPixels(float *buf, uint8_t pixels=AMG88xx_PIXEL_ARRAY_SIZE)
Read Infrared sensor values.
Definition: Adafruit_AMG88xx.cpp:195
void disableInterrupt()
disable the interrupt pin on the device
Definition: Adafruit_AMG88xx.cpp:114
void setInterruptLevels(float high, float low)
Set the interrupt levels. The hysteresis value defaults to .95 * high.
Definition: Adafruit_AMG88xx.cpp:63
void clearInterrupt()
Clear any triggered interrupts.
Definition: Adafruit_AMG88xx.cpp:151
Class that stores state and functions for interacting with AMG88xx IR sensor chips.
Definition: Adafruit_AMG88xx.h:69
void enableInterrupt()
enable the interrupt pin on the device.
Definition: Adafruit_AMG88xx.cpp:104
bool begin(uint8_t addr=AMG88xx_ADDRESS, TwoWire *theWire=&Wire)
Setups the I2C interface and hardware.
Definition: Adafruit_AMG88xx.cpp:17
float readThermistor()
read the onboard thermistor
Definition: Adafruit_AMG88xx.cpp:162
void setInterruptMode(uint8_t mode)
Set the interrupt to either absolute value or difference mode.
Definition: Adafruit_AMG88xx.cpp:126