Added a method to get temperature of the module

This commit is contained in:
anschrammh 2019-10-31 21:45:45 +01:00
parent 34769ac251
commit 36f87a27a8
2 changed files with 16 additions and 0 deletions

View File

@ -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;
}

View File

@ -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();
};