Adafruit MCP9808 Arduino Library
Adafruit_MCP9808.h
Go to the documentation of this file.
1 
17 #ifndef _ADAFRUIT_MCP9808_H
18 #define _ADAFRUIT_MCP9808_H
19 
20 #include "Adafruit_BusIO_Register.h"
21 #include "Arduino.h"
22 #include <Adafruit_I2CDevice.h>
23 #include <Adafruit_Sensor.h>
24 
25 #define MCP9808_I2CADDR_DEFAULT 0x18
26 #define MCP9808_REG_CONFIG 0x01
27 
28 #define MCP9808_REG_CONFIG_SHUTDOWN 0x0100
29 #define MCP9808_REG_CONFIG_CRITLOCKED 0x0080
30 #define MCP9808_REG_CONFIG_WINLOCKED 0x0040
31 #define MCP9808_REG_CONFIG_INTCLR 0x0020
32 #define MCP9808_REG_CONFIG_ALERTSTAT 0x0010
33 #define MCP9808_REG_CONFIG_ALERTCTRL 0x0008
34 #define MCP9808_REG_CONFIG_ALERTSEL 0x0004
35 #define MCP9808_REG_CONFIG_ALERTPOL 0x0002
36 #define MCP9808_REG_CONFIG_ALERTMODE 0x0001
37 
38 #define MCP9808_REG_UPPER_TEMP 0x02
39 #define MCP9808_REG_LOWER_TEMP 0x03
40 #define MCP9808_REG_CRIT_TEMP 0x04
41 #define MCP9808_REG_AMBIENT_TEMP 0x05
42 #define MCP9808_REG_MANUF_ID 0x06
43 #define MCP9808_REG_DEVICE_ID 0x07
44 #define MCP9808_REG_RESOLUTION 0x08
45 
46 
50 class Adafruit_MCP9808 : public Adafruit_Sensor {
51 public:
53  bool begin();
54  bool begin(TwoWire *theWire);
55  bool begin(uint8_t addr);
56  bool begin(uint8_t addr, TwoWire *theWire);
57 
58  bool init();
59  float readTempC();
60  float readTempF();
61  uint8_t getResolution(void);
62  void setResolution(uint8_t value);
63 
64  void shutdown_wake(boolean sw);
65  void shutdown();
66  void wake();
67 
68  void write16(uint8_t reg, uint16_t val);
69  uint16_t read16(uint8_t reg);
70 
71  void write8(uint8_t reg, uint8_t val);
72  uint8_t read8(uint8_t reg);
73 
74  /* Unified Sensor API Functions */
75  bool getEvent(sensors_event_t *);
76  void getSensor(sensor_t *);
77 
78 private:
79  uint16_t _sensorID = 9808;
80  Adafruit_I2CDevice *i2c_dev = NULL;
81 };
82 
83 #endif
uint8_t getResolution(void)
Get Resolution Value.
Definition: Adafruit_MCP9808.cpp:167
Class that stores state and functions for interacting with MCP9808 Temp Sensor.
Definition: Adafruit_MCP9808.h:50
void wake()
Wake up MCP9808.
Definition: Adafruit_MCP9808.cpp:158
Adafruit_MCP9808()
Instantiates a new MCP9808 class.
Definition: Adafruit_MCP9808.cpp:35
bool init()
init function
Definition: Adafruit_MCP9808.cpp:79
void setResolution(uint8_t value)
Set Resolution Value.
Definition: Adafruit_MCP9808.cpp:175
float readTempF()
Reads the 16-bit temperature register and returns the Fahrenheit temperature as a float...
Definition: Adafruit_MCP9808.cpp:117
void write16(uint8_t reg, uint16_t val)
Low level 16 bit write procedures.
Definition: Adafruit_MCP9808.cpp:184
void getSensor(sensor_t *)
Gets the overall sensor_t data including the type, range and resulution.
Definition: Adafruit_MCP9808.cpp:254
bool getEvent(sensors_event_t *)
Gets the pressure sensor and temperature values as sensor events.
Definition: Adafruit_MCP9808.cpp:233
float readTempC()
Reads the 16-bit temperature register and returns the Centigrade temperature as a float...
Definition: Adafruit_MCP9808.cpp:98
bool begin()
Setups the HW with default address.
Definition: Adafruit_MCP9808.cpp:73
uint8_t read8(uint8_t reg)
Low level 8 bit read procedure.
Definition: Adafruit_MCP9808.cpp:219
void write8(uint8_t reg, uint8_t val)
Low level 8 bit write procedure.
Definition: Adafruit_MCP9808.cpp:208
void shutdown()
Shutdown MCP9808.
Definition: Adafruit_MCP9808.cpp:153
void shutdown_wake(boolean sw)
Set Sensor to Shutdown-State or wake up (Conf_Register BIT8)
Definition: Adafruit_MCP9808.cpp:137
uint16_t read16(uint8_t reg)
Low level 16 bit read procedure.
Definition: Adafruit_MCP9808.cpp:196