2021-01-29 06:31:58 -05:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: mcp9808.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-10-04 09:50:10 -04:00
|
|
|
// VERSION: 0.4.0
|
2021-01-29 06:31:58 -05:00
|
|
|
// PURPOSE: Arduino Library for I2C mcp9808 temperature sensor
|
|
|
|
// DATE: 2020-05-03
|
|
|
|
// URL: https://github.com/RobTillaart/MCP9808_RT
|
|
|
|
//
|
|
|
|
|
2021-11-08 14:21:36 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
#include "Arduino.h"
|
|
|
|
#include "Wire.h"
|
|
|
|
|
2022-11-17 08:21:33 -05:00
|
|
|
// VALID ADDRESSES,
|
|
|
|
// max 8 sensors on one bus
|
|
|
|
// 24..31 == 0x18..0x1F
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
2023-10-04 09:50:10 -04:00
|
|
|
#define MCP9808_LIB_VERSION (F("0.4.0"))
|
2021-11-08 14:21:36 -05:00
|
|
|
|
|
|
|
|
2022-11-17 08:21:33 -05:00
|
|
|
// CONFIGURATION REGISTER MASKS
|
|
|
|
// check the datasheet for exact usage
|
2021-12-21 11:44:18 -05:00
|
|
|
#define MCP9808_THYSTERESIS 0x0600
|
|
|
|
#define MCP9808_SHUTDOWN 0x0100
|
|
|
|
#define MCP9808_CRIT_LOCK 0x0080
|
|
|
|
#define MCP9808_WIN_LOCK 0x0040
|
|
|
|
#define MCP9808_INT_CLEAR 0x0020
|
|
|
|
#define MCP9808_ALERT_STATUS 0x0010
|
|
|
|
#define MCP9808_ALERT_CTRL 0x0008
|
|
|
|
#define MCP9808_ALERT_SELECT 0x0004
|
|
|
|
#define MCP9808_ALERT_POLAR 0x0002
|
|
|
|
#define MCP9808_ALERT_MODE 0x0001
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
class MCP9808
|
|
|
|
{
|
|
|
|
public:
|
2023-10-04 09:50:10 -04:00
|
|
|
MCP9808(const uint8_t address, TwoWire *wire = &Wire);
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
bool isConnected();
|
|
|
|
|
2021-11-08 14:21:36 -05:00
|
|
|
void setConfigRegister(uint16_t configuration);
|
2021-01-29 06:31:58 -05:00
|
|
|
uint16_t getConfigRegister();
|
|
|
|
|
2021-11-08 14:21:36 -05:00
|
|
|
void setTupper(float temperature);
|
2021-01-29 06:31:58 -05:00
|
|
|
float getTupper();
|
2021-11-08 14:21:36 -05:00
|
|
|
void setTlower(float temperature);
|
2021-01-29 06:31:58 -05:00
|
|
|
float getTlower();
|
2021-11-08 14:21:36 -05:00
|
|
|
void setTcritical(float temperature);
|
2021-01-29 06:31:58 -05:00
|
|
|
float getTcritical();
|
|
|
|
|
2021-11-08 14:21:36 -05:00
|
|
|
void setOffset(float offset = 0.0);
|
2021-01-29 06:31:58 -05:00
|
|
|
float getOffset();
|
|
|
|
float getTemperature();
|
2021-11-08 14:21:36 -05:00
|
|
|
|
2022-11-17 08:21:33 -05:00
|
|
|
// getStatus() returns 0..7
|
2023-09-23 10:15:15 -04:00
|
|
|
// to get latest status, getTemperature() must be called first
|
2021-11-08 14:21:36 -05:00
|
|
|
uint8_t getStatus();
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-11-08 14:21:36 -05:00
|
|
|
void setResolution(uint8_t resolution = 3);
|
2021-01-29 06:31:58 -05:00
|
|
|
uint8_t getResolution();
|
|
|
|
|
|
|
|
uint16_t getManufacturerID();
|
|
|
|
uint8_t getDeviceID();
|
|
|
|
uint8_t getRevision();
|
|
|
|
|
2022-11-17 08:21:33 -05:00
|
|
|
// Reserved Register, not used
|
2021-01-29 06:31:58 -05:00
|
|
|
uint16_t getRFU();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
float _offset = 0;
|
2022-11-17 08:21:33 -05:00
|
|
|
uint8_t _status = 0; // 0..7
|
2021-01-29 06:31:58 -05:00
|
|
|
uint8_t _address;
|
|
|
|
TwoWire* _wire;
|
|
|
|
|
|
|
|
void writeFloat(uint8_t reg, float f);
|
|
|
|
float readFloat(uint8_t reg);
|
|
|
|
|
|
|
|
void writeReg8(uint8_t reg, uint8_t value);
|
|
|
|
uint8_t readReg8(uint8_t reg);
|
|
|
|
void writeReg16(uint8_t reg, uint16_t value);
|
|
|
|
uint16_t readReg16(uint8_t reg);
|
|
|
|
};
|
|
|
|
|
2021-11-08 14:21:36 -05:00
|
|
|
|
2023-02-03 03:07:19 -05:00
|
|
|
// -- END OF FILE --
|
2021-11-08 14:21:36 -05:00
|
|
|
|