Missing "Begin" in RTC library?

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Missing "Begin" in RTC library?

Post by spiney »

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

#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);
    
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Missing "Begin" in RTC library?

Post by adafruit_support_bill »

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
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Missing "Begin" in RTC library?

Post by spiney »

Great. Thanks.
Shoud have been obvious - sorry.

User avatar
somewhereinusa
 
Posts: 61
Joined: Thu Nov 21, 2013 11:42 am

Re: Missing "Begin" in RTC library?

Post by somewhereinusa »

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

#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

1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am

Re: Missing "Begin" in RTC library?

Post by 1chicagodave »

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.

User avatar
somewhereinusa
 
Posts: 61
Joined: Thu Nov 21, 2013 11:42 am

Re: Missing "Begin" in RTC library?

Post by somewhereinusa »

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

1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am

Re: Missing "Begin" in RTC library?

Post by 1chicagodave »

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)

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”