Missing "Begin" in RTC library?
Moderators: adafruit_support_bill, adafruit

Missing "Begin" in RTC library?

by Spiney on Thu Oct 11, 2012 3:56 pm

I am using Adafruit datalogger shield on an Arduino Uno.
I borrowed Sheepdogguides interrupt program and caused the interrupt to print the date and time to the Serial monitor – Yes I know one should not print within interrupts!
A compile error appeared “class RTC_DS1307” has no member named “begin”.
Serendipitously I tried including “include <wire.h>” and that fixed the compile error.
Now why should the RTC need to have the Wire library included?

Code: Select all | TOGGLE FULL SIZE
#include "RTClib.h"

RTC_DS1307 RTC;
#define TEMP_PIN  2 //See Note 1, sheepdogguides..ar3ne1tt.htm
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
#define PIN 3  // the pin for button
volatile byte burp=0;    // a counter to see how many times the pin has changed
byte cmd=0;     // a place to put our serial data

void setup() {
    digitalWrite(TEMP_PIN, LOW);
    pinMode(TEMP_PIN, INPUT);      // sets the digital pin as input (logic 1)
    Serial.begin(9600);
    RTC.begin();
    delay(100);
    Serial.print("PinChangeInt test on pin ");
    Serial.print(PIN);
    Serial.println();
    pinMode(PIN, INPUT);     //set the pin to input
    digitalWrite(PIN, HIGH); //use the internal pullup resistor
    PCintPort::attachInterrupt(PIN, burpcount,FALLING); // attach a PinChange Interrupt to our pin on the rising edge
// (RISING, FALLING and CHANGE all work with this library)
// and execute the function burpcount when that pin changes 
    RTC.adjust(DateTime(__DATE__, __TIME__));
}
void loop(){
}
void burpcount()
{
  burp++;
    Serial.print("burpcount:\t");  //\t means a tabular space.
    Serial.println(burp, DEC);
    interrupts();
    DateTime now = RTC.now();   
   
    Serial.print(now.day(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.year(), DEC);
    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);
   
}
Spiney
 
Posts: 165
Joined: Mon Jul 09, 2012 6:35 am

Re: Missing "Begin" in RTC library?

by adafruit_support_bill on Thu Oct 11, 2012 4:08 pm

Now why should the RTC need to have the Wire library included?

Because the RTC is an I2C device and utilizes the I2C implementation from the wire library.
User avatar
adafruit_support_bill
 
Posts: 31711
Joined: Sat Feb 07, 2009 10:11 am

Re: Missing "Begin" in RTC library?

by Spiney on Thu Oct 11, 2012 5:11 pm

Great. Thanks.
Shoud have been obvious - sorry.
Spiney
 
Posts: 165
Joined: Mon Jul 09, 2012 6:35 am

Re: Missing "Begin" in RTC library?

by somewhereinusa on Thu Feb 06, 2014 5:50 pm

I had the same error, and arrived at this post. I checked to see if I did, in fact have #include <Wire.h>

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>

#include <RTClib.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
//#include <Wire.h>
static const int RXPin = 8, TXPin = 7;
static const unsigned long GPSBaud = 9600;
int ledPin = 13;//for gps fix indicator
LiquidCrystal lcd(0);
RTC_DS1307 rtc;


I commented it out and imported it again from the library and it now compiles Can you explain what the difference is?

I
somewhereinusa
 
Posts: 25
Joined: Thu Nov 21, 2013 11:42 am

Re: Missing "Begin" in RTC library?

by 1chicagodave on Thu Feb 06, 2014 6:14 pm

Due to mysterious inner workings of the compiler, it sometimes matters in which order the "#includes" are listed in the sketch. Apparently, wire.h likes to be on top! :D

....Actually, I could be incorrect, but because the RTC library requires the use of the WIre library...it would kind of make sense to have that one first.
Please forgive my hyperanthropomorphization.
Every answer reveals new questions.
And, yes... there's always a better way to 'do that'.
User avatar
1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am
Location: Chicago

Re: Missing "Begin" in RTC library?

by somewhereinusa on Thu Feb 06, 2014 6:22 pm

Thanks Dave,

Just to try it out I put the new one down where the first one was and again had the problem. It's not that I didn't believe you, just wanted to try it out. :D
somewhereinusa
 
Posts: 25
Joined: Thu Nov 21, 2013 11:42 am

Re: Missing "Begin" in RTC library?

by 1chicagodave on Fri Feb 07, 2014 3:51 pm

somewhereinusa wrote:Thanks Dave,

Just to try it out I put the new one down where the first one was and again had the problem. It's not that I didn't believe you, just wanted to try it out. :D


No, that's great! Always experiment and verify.

I had actually considered adding "....but don't take my word for it" to my signature line. 8)
Please forgive my hyperanthropomorphization.
Every answer reveals new questions.
And, yes... there's always a better way to 'do that'.
User avatar
1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am
Location: Chicago