Added a method to get temperature of the module
This commit is contained in:
parent
34769ac251
commit
36f87a27a8
@ -506,3 +506,16 @@ void RTC_DS3231::writeSqwPinMode(Ds3231SqwPinMode mode) {
|
||||
|
||||
//Serial.println( read_i2c_register(DS3231_ADDRESS, DS3231_CONTROL), HEX);
|
||||
}
|
||||
|
||||
float RTC_DS3231::getTemperature()
|
||||
{
|
||||
//Lets tell which register we want to read
|
||||
Wire.beginTransmission(DS3231_ADDRESS);
|
||||
Wire._I2C_WRITE((byte)DS3231_TEMPREG);
|
||||
Wire.endTransmission();
|
||||
//Lets read it :
|
||||
Wire.requestFrom((uint8_t)DS3231_ADDRESS, (uint8_t)2);
|
||||
uint8_t upper = Wire._I2C_READ(), lower = Wire._I2C_READ();
|
||||
|
||||
return (float) upper + (lower >> 6) * 0.25;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Code by JeeLabs http://news.jeelabs.org/code/
|
||||
// Released to the public domain! Enjoy!
|
||||
// Added a real begin verification for the ds3231 01/05/2019 Th3maz1ng
|
||||
// Adding DS3231 internal temp sensor reading
|
||||
|
||||
#ifndef _RTCLIB_H_
|
||||
#define _RTCLIB_H_
|
||||
@ -20,6 +21,7 @@ class TimeSpan;
|
||||
#define DS3231_ADDRESS 0x68
|
||||
#define DS3231_CONTROL 0x0E
|
||||
#define DS3231_STATUSREG 0x0F
|
||||
#define DS3231_TEMPREG 0x11
|
||||
|
||||
#define SECONDS_PER_DAY 86400L
|
||||
|
||||
@ -104,6 +106,7 @@ public:
|
||||
static DateTime now();
|
||||
static Ds3231SqwPinMode readSqwPinMode();
|
||||
static void writeSqwPinMode(Ds3231SqwPinMode mode);
|
||||
float getTemperature();
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user