0.1.4 MCP9808_RT

This commit is contained in:
rob tillaart 2021-11-08 20:21:36 +01:00
parent 59715e6d17
commit bebe48d7d9
17 changed files with 232 additions and 108 deletions

View File

@ -2,6 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560

View File

@ -4,10 +4,14 @@ name: Arduino CI
on: [push, pull_request]
jobs:
arduino_ci:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -1,16 +1,20 @@
[![Arduino CI](https://github.com/RobTillaart/MCP9808_RT/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/MCP9808_RT/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MCP9808_RT/actions/workflows/arduino-lint.yml)
[![Arduino-lint](https://github.com/RobTillaart/MCP9808_RT/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MCP9808_RT/actions/workflows/arduino-lint.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/MCP9808_RT/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/MCP9808_RT.svg?maxAge=3600)](https://github.com/RobTillaart/MCP9808_RT/releases)
# MCP9808_RT
Arduino library for I2C MCP9808 temperature sensor
Arduino library for I2C MCP9808 temperature sensor.
## Description
The MCP9808 is a temperature sensor that measures typically in 1/16th == 0.0625 of a degree celsius.
What makes this sensor interesting is the ALERT pin, which allows triggering of any piece
The MCP9808 is a temperature sensor that measures typically in 1/16th == 0.0625 ° Celsius.
What makes this sensor interesting is the **ALERT** pin, which allows triggering of any piece
of electronics if the temperature hits a predefined value or zone.
@ -38,24 +42,27 @@ of electronics if the temperature hits a predefined value or zone.
### Constructor
- **MCP9808(const uint8_t addr)** constructor for e.g. UNO
- **MCP9808(const uint8_t addr, const uint8_t dataPin = 255, const uint8_t clockPin = 255)** constructor for ESP32 and ESP8266
- **setAddress(const uint8_t address, TwoWire \*wire)** if multiple I2C busses are present one can choose.
- **MCP9808(const uint8_t address)** constructor for e.g. UNO.
- **MCP9808(const uint8_t address, const uint8_t dataPin = 255, const uint8_t clockPin = 255)** constructor for ESP32 and ESP8266.
- **bool setAddress(const uint8_t address, TwoWire \*wire = &Wire)** if multiple I2C buses are present one can choose.
Default I2C bus is Wire.
**Address**
max 8 sensors on one I2C bus
#### Address
There ar max 8 sensors on one I2C bus.
Normal address = 0011xxx where xxx = A2, A1, A0
| Address | HEX | A2 | A1 | A0 |
|:----:|:----:|:----:|:----:|:----:|
| 24 | 0x18 | 0 | 0 | 0 |
| 25 | 0x19 | 0 | 0 | 1 |
| 26 | 0x1A | 0 | 1 | 0 |
| 27 | 0x1B | 0 | 1 | 1 |
| 28 | 0x1C | 1 | 0 | 0 |
| 29 | 0x1D | 1 | 0 | 1 |
| 30 | 0x1E | 1 | 1 | 0 |
| 31 | 0x1F | 1 | 1 | 1 |
| Address | HEX | A2 | A1 | A0 |
|:-------:|:------:|:----:|:----:|:----:|
| 24 | 0x18 | 0 | 0 | 0 |
| 25 | 0x19 | 0 | 0 | 1 |
| 26 | 0x1A | 0 | 1 | 0 |
| 27 | 0x1B | 0 | 1 | 1 |
| 28 | 0x1C | 1 | 0 | 0 |
| 29 | 0x1D | 1 | 0 | 1 |
| 30 | 0x1E | 1 | 1 | 0 |
| 31 | 0x1F | 1 | 1 | 1 |
On request manufacturer will provide 1001xxx as base address
allowing up to 16 temp sensors on one bus.
@ -63,80 +70,87 @@ allowing up to 16 temp sensors on one bus.
### Temperature and status
- **setOffset(float offset)** set an offset to calibrate or to correct for self heating. The value of offset is not validated to keep footprint small.
- **getOffset()** return value of offset (default 0);
- **getTemperature()** read the ambient temperature.
- **getStatus()** returns the status bits of the last call to **getTemperature()**
- **void setOffset(float offset = 0.0)** set an offset to calibrate or to correct for self heating.
The value of offset is not validated to keep footprint small.
- **float getOffset()** return value of offset (default 0).
- **float getTemperature()** read the ambient temperature.
- **uint8_t getStatus()** returns the status bits of the last call to **getTemperature()**
The value returned by **getStatus()** is the last value read by the call to **GetTemperature()**. There are three bits, see table below. A value of 6 means that TA is above the upper and above the critical temp.
The value returned by **getStatus()** is the last value read by the call to **GetTemperature()**.
There are three bits, see table below.
A value of 6 == mask == 110 means that TA is above the upper and above the critical temperature.
| Bit | Mask | Description | Notes |
|:----:|:----:|:----|:----|
| 0 | 0x01 | TA < TLOWER | lower |
| 1 | 0x02 | TA > TUPPER | larger |
| 2 | 0x04 | TA ≥ TCRIT | **larger or equal** |
| Bit | Mask | Description | Notes |
|:----:|:------:|:------------|:----------------|
| 0 | 0x01 | TA < TLOWER | lower |
| 1 | 0x02 | TA > TUPPER | larger |
| 2 | 0x04 | TA ≥ TCRIT | larger or equal |
### Resolution
- **setResolution(uint8_t res)** set the resolution, if res > 3, it is not set.
- **getResolution()** returns the resolution set
- **void setResolution(uint8_t resolution = 3)** set the resolution, if resolution > 3, it is not set.
- **uint8_t getResolution()** returns the resolution set.
| Value | Resolution | Conv time (ms) | Samples/s | Notes |
|:----:|:----|:----:|:----:|:----:|
| 0 | 0.5°C | 30 | 33 ||
| 1 | 0.25°C | 65 | 15 ||
| 2 | 0.125°C | 130 | 7 ||
| 3 | 0.0625°C | 250 | 4 | **default** |
| Value | Resolution | Conv time (ms) | Samples/s | Notes |
|:------:|:-----------|:--------------:|:---------:|:-------:|
| 0 | 0.5°C | 30 | 33 | |
| 1 | 0.25°C | 65 | 15 | |
| 2 | 0.125°C | 130 | 7 | |
| 3 | 0.0625°C | 250 | 4 | default |
### Config
Note: for the same resolution it is about 3x faster than a DS18B20.
- **setConfigRegister(uint16_t cfg)**
- **getConfigRegister()**
| Bit | Mask | Name | Description | Value |
|:----:|:----:|:----|:----|:----|
| 0 | 0x0001 | ALT MOD | alert mode | **0 = comparator output**, 1 = interrupt output |
| 1 | 0x0002 | ALT POL | alert polarity | **0 = active low**, 1 = active high|
| 2 | 0x0004 | ALT SEL | alert select | **0 = upper+lower+crit**, 1 = crit only|
| 3 | 0x0008 | ALT CNT | alert control | **0 = OFF**, 1 = ON |
| 4 | 0x0010 | ALT STAT | alert status | **0 = OFF**, 1 = ON (read!) |
| 5 | 0x0020 | INT CLR | interrupt clear | **0 = none**, 1 = clear interrupt |
| 6 | 0x0040 | WIN LOC | lock Tup + Tlow | **0 = unlocked**, 1 = Lock |
| 7 | 0x0080 | CRT LOC | lock Tcritical | **0 = unlocked**, 1 = Lock |
| 8 | 0x0100 | SHDN | shutdown, | **0 = continuous mode**, 1 = low power |
| 9-10 | 0x0600 | Hysteresis | Thysteresis | **00 = 0°C**, 01 = 1.5°C, 10 = 3°C, 11 = 6°C |
| 11-15 | | always 0 | |
### Configuration
- **void setConfigRegister(uint16_t configuration)** see table below + read datasheet.
- **uint16_t getConfigRegister()** return set value.
| Bit | Mask | Name | Description | Value |
|:-----:|:------:|:-----------|:----------------|:-------|
| 0 | 0x0001 | ALT MOD | alert mode | **0 = comparator output**, 1 = interrupt output
| 1 | 0x0002 | ALT POL | alert polarity | **0 = active low**, 1 = active high
| 2 | 0x0004 | ALT SEL | alert select | **0 = upper+lower+crit**, 1 = crit only
| 3 | 0x0008 | ALT CNT | alert control | **0 = OFF**, 1 = ON
| 4 | 0x0010 | ALT STAT | alert status | **0 = OFF**, 1 = ON (read!)
| 5 | 0x0020 | INT CLR | interrupt clear | **0 = none**, 1 = clear interrupt
| 6 | 0x0040 | WIN LOC | lock Tup + Tlow | **0 = unlocked**, 1 = Lock
| 7 | 0x0080 | CRT LOC | lock Tcritical | **0 = unlocked**, 1 = Lock
| 8 | 0x0100 | SHDN | shutdown, | **0 = continuous mode**, 1 = low power
| 9-10 | 0x0600 | Hysteresis | Thysteresis | **00 = 0°C**, 01 = 1.5°C, 10 = 3°C, 11 = 6°C
| 11-15 | | always 0 | |
Check datasheet for the details...
### Temperature limits / thresholds
- **setTupper(float temp)** write upper register, accuracy 0.25°C
- **getTupper()** idem
- **setTlower(float temp)** write lower register, accuracy 0.25°C
- **getTlower()** idem
- **setTcritical(float temp)** write critical register, accuracy 0.25°C
- **getTcritical()** idem
- **void setTupper(float temp)** write upper register, accuracy 0.25°C.
- **float getTupper()** idem.
- **void setTlower(float temp)** write lower register, accuracy 0.25°C.
- **float getTlower()** idem.
- **void setTcritical(float temp)** write critical register, accuracy 0.25°C.
- **float getTcritical()** idem.
The values written in these registers, are the trigger values for the status
read with getStatus. Note that the Hysteresis temperature delta affects the
value of these triggers.
The values set are not validated to keep footprint small.
The values set are not validated to keep footprint of the library small.
### Miscelaneous
### Miscellaneous
- **getManufacturerID()** returns 84 (my version)
- **getDeviceID()** returns 0 (my version)
- **getRevision()** returns 84 (my version)
- **getRFU()** returns 29 (my version). Reserved for future use.
- **uint16_t getManufacturerID()** returns 84 (my version).
- **uint8_t getDeviceID()** returns 0 (my version).
- **uint8_t getRevision()** returns 84 (my version).
- **uint16_t getRFU()** returns 29 (my version). Reserved for future use.
### Hidden registers
The MCP9808 has hidden registers mentioned only on p.16 of the datasheet.
These are for testing and calibration.
The library prevents reading / writing them to keep sensors working.
@ -145,3 +159,12 @@ The library prevents reading / writing them to keep sensors working.
## Operation
See examples
## Future
- update documentation
- do unit test
- add more examples for the **ALERT**
-

View File

@ -5,20 +5,25 @@
// PURPOSE: demo
// DATE: 2020-11-12
#include "mcp9808.h"
MCP9808 ts(24);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
}
void loop()
{
delay(2000);
Serial.println(ts.getTemperature(), 4);
}
// -- END OF FILE --

View File

@ -5,16 +5,19 @@
// PURPOSE: demo
// DATE: 2020-11-13
#include "mcp9808.h"
MCP9808 ts(24);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
}
void loop()
{
delay(500);
@ -25,4 +28,6 @@ void loop()
Serial.println(ts.getTemperature(), 4);
}
// -- END OF FILE --

View File

@ -5,12 +5,14 @@
// PURPOSE: demo
// DATE: 2020-11-13
#include "mcp9808.h"
MCP9808 ts(24);
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
@ -36,8 +38,11 @@ void setup()
Serial.println();
}
void loop()
{
}
// -- END OF FILE --

View File

@ -5,16 +5,19 @@
// PURPOSE: demo
// DATE: 2020-11-13
#include "mcp9808.h"
MCP9808 ts(24);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
}
void loop()
{
for (int res = 0; res < 4; res++)
@ -27,4 +30,6 @@ void loop()
}
}
// -- END OF FILE --

View File

@ -7,10 +7,12 @@
// (c) : MIT
//
#include "mcp9808.h"
MCP9808 ts(24);
void setup()
{
Serial.begin(115200);
@ -22,6 +24,7 @@ void setup()
test_3();
}
void test_0()
{
Serial.println();
@ -45,11 +48,12 @@ void test_0()
Serial.println(ts.getDeviceID());
Serial.print("Revision: ");
Serial.println(ts.getRevision());
Serial.print("RFU: ");
Serial.print("RFU: ");
Serial.println(ts.getRFU());
Serial.println();
}
void test_1()
{
Serial.println();
@ -65,6 +69,7 @@ void test_1()
}
}
void test_2()
{
Serial.println();
@ -113,6 +118,7 @@ void test_2()
Serial.println();
}
void test_3()
{
Serial.println();
@ -131,6 +137,10 @@ void test_3()
}
void loop() {}
void loop()
{
}
// -- END OF FILE --

View File

@ -21,10 +21,12 @@
// +----------+
//
#include "mcp9808.h"
MCP9808 ts(24);
void setup()
{
Serial.begin(115200);
@ -33,6 +35,7 @@ void setup()
// SET TEMPERATURE WINDOW FOR COMPERATOR MODE °C
ts.setTlower(21);
ts.setTupper(23);
// SET AUTO RESET (p32 datasheet)
// same value as Tupper to have auto reset in comparator mode.
// note no hysteresis set
@ -55,6 +58,7 @@ void setup()
ts.setConfigRegister(cfg);
}
void loop()
{
Serial.print(ts.getConfigRegister() & 0x0010);
@ -68,3 +72,4 @@ void loop()
// -- END OF FILE --

View File

@ -21,6 +21,7 @@
// +----------+
//
#include "mcp9808.h"
MCP9808 ts(24);
@ -28,11 +29,13 @@ MCP9808 ts(24);
const uint8_t ALERTPIN = 2; // ADJUST IF NEEDED
volatile bool flag = false;
// interrupt routine
void detectAlert()
{
flag = true;
}
void setup()
{
Serial.begin(115200);
@ -57,6 +60,7 @@ void setup()
pinMode(ALERTPIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ALERTPIN), detectAlert, RISING); // CHANGE
// SET ALERT PARAMETERS
uint16_t cfg = ts.getConfigRegister();
cfg &= ~0x0001; // set comparator mode
@ -67,6 +71,7 @@ void setup()
ts.setConfigRegister(cfg);
}
void loop()
{
if (flag)
@ -85,3 +90,4 @@ void loop()
// -- END OF FILE --

View File

@ -21,6 +21,7 @@
// +----------+
//
#include "mcp9808.h"
MCP9808 ts(24);
@ -61,6 +62,7 @@ void setup()
ts.setConfigRegister(cfg);
}
void loop()
{
// will keep on alerting until pin = LOW again

View File

@ -1,29 +1,36 @@
# Syntax Coloring Map For MCP9808
# Syntax Colouring Map For MCP9808
# Datatypes (KEYWORD1)
# Data types (KEYWORD1)
MCP9808 KEYWORD1
# Methods and Functions (KEYWORD2)
setAddress KEYWORD2
setConfigRegister KEYWORD2
getConfigRegister KEYWORD2
setTupper KEYWORD2
getTupper KEYWORD2
setTlower KEYWORD2
getTlower KEYWORD2
setTcritical KEYWORD2
getTcritical KEYWORD2
getTemperature KEYWORD2
getStatus KEYWORD2
setOffset KEYWORD2
getOffset KEYWORD2
setResolution KEYWORD2
getResolution KEYWORD2
getManufacturerID KEYWORD2
getDeviceID KEYWORD2
getRevision KEYWORD2
# Constants (LITERAL1)
MCP9808_LIB_VERSION LITERAL1
MCP9808_THYSTERESIS LITERAL1
MCP9808_SHUTDOWN LITERAL1
MCP9808_CRIT_LOCK LITERAL1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/MCP9808_RT.git"
},
"version": "0.1.3",
"version": "0.1.4",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"

View File

@ -1,5 +1,5 @@
name=MCP9808_RT
version=0.1.3
version=0.1.4
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for I2C MCP9808 temperature sensor

View File

@ -1,7 +1,7 @@
//
// FILE: mcp9808.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.3
// VERSION: 0.1.4
// PURPOSE: Arduino Library for I2C mcp9808 temperature sensor
// DATE: 2020-05-03
// URL: https://github.com/RobTillaart/MCP9808_RT
@ -12,6 +12,10 @@
// 0.1.2 2020-11-16 removed hasAlert, removed setAlertPin,
// added 2 alert examples, refactor low level
// 0.1.3 2021-01-01 arduino-ci + unit test
// 0.1.4 2021-11-08 update build-CI, badges
// default offset for offset
// default Wire for I2C bus - setAddress()
#include "mcp9808.h"
@ -25,6 +29,7 @@
#define MCP9808_DID 0x07
#define MCP9808_RES 0x08
/*
0000 = RFU, Reserved for Future Use (Read-Only register)
0001 = Configuration register (CONFIG)
@ -38,6 +43,7 @@
1xxx = Reserved(1)
*/
#if defined(ESP8266) || defined(ESP32)
MCP9808::MCP9808(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin)
{
@ -59,6 +65,7 @@ MCP9808::MCP9808(const uint8_t address)
}
#endif
bool MCP9808::setAddress(const uint8_t address, TwoWire *wire)
{
if ((address < 24) || (address > 31)) return false;
@ -68,97 +75,116 @@ bool MCP9808::setAddress(const uint8_t address, TwoWire *wire)
return true;
}
bool MCP9808::isConnected()
{
Wire.beginTransmission(_address);
return (Wire.endTransmission() == 0);
}
void MCP9808::setConfigRegister(uint16_t config)
void MCP9808::setConfigRegister(uint16_t configuration)
{
writeReg16(MCP9808_CONFIG, config);
writeReg16(MCP9808_CONFIG, configuration);
}
uint16_t MCP9808::getConfigRegister()
{
return readReg16(MCP9808_CONFIG);
}
void MCP9808::setTupper(float temp)
void MCP9808::setTupper(float temperature)
{
writeFloat(MCP9808_TUPPER, temp);
writeFloat(MCP9808_TUPPER, temperature);
}
float MCP9808::getTupper()
{
return readFloat(MCP9808_TUPPER);
}
void MCP9808::setTlower(float temp)
void MCP9808::setTlower(float temperature)
{
writeFloat(MCP9808_TLOWER, temp);
writeFloat(MCP9808_TLOWER, temperature);
}
float MCP9808::getTlower()
{
return readFloat(MCP9808_TLOWER);
}
void MCP9808::setTcritical(float temp)
void MCP9808::setTcritical(float temperature)
{
writeFloat(MCP9808_TCRIT, temp);
writeFloat(MCP9808_TCRIT, temperature);
}
float MCP9808::getTcritical()
{
return readFloat(MCP9808_TCRIT);
}
void MCP9808::setOffset(float offset)
{
_offset = offset;
};
float MCP9808::getOffset()
{
return _offset;
};
float MCP9808::getTemperature()
{
return readFloat(MCP9808_TA) + _offset;
}
uint8_t MCP9808::getStatus()
{
return _status;
}
uint16_t MCP9808::getManufacturerID()
{
return readReg16(MCP9808_MID);
}
uint8_t MCP9808::getDeviceID()
{
return readReg16(MCP9808_DID) >> 8;
}
uint8_t MCP9808::getRevision()
{
return readReg16(MCP9808_DID) & 0xFF;
}
void MCP9808::setResolution(uint8_t res)
void MCP9808::setResolution(uint8_t resolution)
{
if (res < 4) writeReg8(MCP9808_RES, res);
if (resolution < 4) writeReg8(MCP9808_RES, resolution);
}
uint8_t MCP9808::getResolution()
{
return readReg8(MCP9808_RES);
}
uint16_t MCP9808::getRFU()
{
return readReg16(MCP9808_RFU);
@ -178,6 +204,7 @@ void MCP9808::writeFloat(uint8_t reg, float f)
writeReg16(reg, val);
}
float MCP9808::readFloat(uint8_t reg)
{
uint16_t val = readReg16(reg);
@ -192,6 +219,7 @@ float MCP9808::readFloat(uint8_t reg)
return (val & 0x0FFF) * 0.0625;
}
void MCP9808::writeReg8(uint8_t reg, uint8_t value)
{
if (reg > MCP9808_RES) return; // see p.16
@ -201,6 +229,7 @@ void MCP9808::writeReg8(uint8_t reg, uint8_t value)
Wire.endTransmission();
}
uint8_t MCP9808::readReg8(uint8_t reg)
{
if (reg > MCP9808_RES) return 0; // see p.16
@ -211,6 +240,7 @@ uint8_t MCP9808::readReg8(uint8_t reg)
return Wire.read();
}
void MCP9808::writeReg16(uint8_t reg, uint16_t value)
{
if (reg > MCP9808_RES) return; // see p.16
@ -221,6 +251,7 @@ void MCP9808::writeReg16(uint8_t reg, uint16_t value)
Wire.endTransmission();
}
uint16_t MCP9808::readReg16(uint8_t reg)
{
if (reg > MCP9808_RES) return 0; // see p.16
@ -233,4 +264,6 @@ uint16_t MCP9808::readReg16(uint8_t reg)
return val;
}
// -- END OF FILE --

View File

@ -2,12 +2,13 @@
//
// FILE: mcp9808.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.3
// VERSION: 0.1.4
// PURPOSE: Arduino Library for I2C mcp9808 temperature sensor
// DATE: 2020-05-03
// URL: https://github.com/RobTillaart/MCP9808_RT
//
#include "Arduino.h"
#include "Wire.h"
@ -16,18 +17,21 @@
// 24..31 == 0x18..0x1F
// CONFIG REGISTER MASKS
#define MCP9808_LIB_VERSION (F("0.1.4"))
// CONFIGURATION REGISTER MASKS
// check the datasheet for exact usage
#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
#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
class MCP9808
@ -40,27 +44,28 @@ public:
MCP9808(const uint8_t address);
#endif
bool setAddress(const uint8_t address, TwoWire *wire);
bool setAddress(const uint8_t address, TwoWire *wire = &Wire);
bool isConnected();
void setConfigRegister(uint16_t config);
void setConfigRegister(uint16_t configuration);
uint16_t getConfigRegister();
void setTupper(float temp);
void setTupper(float temperature);
float getTupper();
void setTlower(float temp);
void setTlower(float temperature);
float getTlower();
void setTcritical(float temp);
void setTcritical(float temperature);
float getTcritical();
void setOffset(float offset);
void setOffset(float offset = 0.0);
float getOffset();
float getTemperature();
// getStatus() returns 0..7
// to get latest status, getTemperature() must be called first
uint8_t getStatus();
uint8_t getStatus();
void setResolution(uint8_t res);
void setResolution(uint8_t resolution = 3);
uint8_t getResolution();
uint16_t getManufacturerID();
@ -86,4 +91,6 @@ private:
uint16_t readReg16(uint8_t reg);
};
// -- END OF FILE --

View File

@ -29,6 +29,7 @@
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)
#include <ArduinoUnitTests.h>
@ -49,13 +50,14 @@ unittest_teardown()
unittest(test_constructor)
{
fprintf(stderr, "VERSION: %s\n", "-");
fprintf(stderr, "VERSION: %s\n", (char *) MCP9808_LIB_VERSION);
MCP9808 ts(24);
assertTrue(ts.setAddress(24, &Wire) );
assertTrue(ts.isConnected());
}
unittest(test_offset)
{
MCP9808 ts(24);
@ -67,6 +69,7 @@ unittest(test_offset)
}
}
unittest_main()
// --------