Hi,
I’m trying to use “DS1307 Real Time Clock breakout board kit” with an i2c temperature sensor. The serial monitor returns floating/too high temperature values when I add a line of code to read date/time from RTC. This is the line that i causing the problem:
DateTime now = rtc.now(); // there is a problem in this line of code
I’m using libraries for both devices which work well individually. How do I need to transition from reading RTC to reading temperature somehow?
#include <SoftWire.h>
#include <HIH61XX.h>
#include <AsyncDelay.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
HIH61xx hih;
AsyncDelay samplingInterval;
void setup(void)
{
Serial.begin(9600);
hih.initialise(20, 21);
samplingInterval.start(3000, AsyncDelay::MILLIS);
while (!Serial){
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2016, 10, 13, 11, 23, 0));
}
}
}
bool printed = true;
void loop()
{
DateTime now = rtc.now(); // there is a problem in this line of code
if (samplingInterval.isExpired() && !hih.isSampling()) {
hih.start();
printed = false;
samplingInterval.repeat();
Serial.println("Sampling started");
}
hih.process();
if (hih.isFinished() && !printed) {
printed = true;
// Print saved values
Serial.print("RH: ");
Serial.print(hih.getRelHumidity() / 100.0);
Serial.println(" %");
Serial.print("Ambient: ");
Serial.print(hih.getAmbientTemp() / 100.0);
Serial.println(" deg C");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
delay(3000);
}
But why is the part that initialized the RTC inside the while(!Serial). The RTC must be initialized and depending on what type of Arduino you have that code may not be run inside there.
This part:
while (!Serial){
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Delta_G, RTC now works! problem half solved. Thank you! you're right that line is only for certain arduino models. Now only if I can figure out why temp readings are constant (seem to be floating). The output is like this:
RH: 655.35 %
Ambient: 327.67 deg C
2016/10/17 (Monday) 10:58:59
The numbers you get back are a clue. 65535 is the max value for unsigned int and 32767 is max value for a signed int. I don't know that sensor but those particular values look like a sensor that isn't working or isn't connected properly.
The sensor works fine using the sketch below, which is what i used. In the sensor library it states that status5, which is what i’m getting, is statusTimeout error.