RTClib reading hours only

Using the following code:

#include <Wire.h>;
#include "RTClib.h"

RTC_DS3231 rtc;


void setup() {
  Serial.begin(9600);
  delay(3000);

}

void loop() {
  DateTime now = rtc.now();
    Serial.println(now.hour(), DEC);
  delay(3000);
}

The hours being printed always return a number 165.
I am not sure why other than perhaps I am reading the wrong location for hours. I can’t find much info on the RTClib like a language reference might show other than examples using this library.
I could use some enlightenment as to where I went wrong in just trying to read the hours.
Oh I am using a DS3231 and using the example “ds3231” code it reads the clock ok giving the correct time and day but all I need are hours. The ds3231 is setup for 24 hour mode.
Thanks,
Bruce

(deleted)

Ok thanks and that did the trick.

So I need to use the rtc.begin()? What does this do other than "begin" does have some meaning.

I keep running into things that I can't find with good explanations. Again I say where
is the reference page for RTClib that might explain the syntax?

Bruce

(deleted)

The begin function sets up the RTC and starts it communicating and sets up the pins on the Arduino to communicate with it. Without that line there's no telling what you'll read from it. It is very much needed.

Serial.println(now.hour(), DEC);

And get rid of the DEC in there. That's the default when it is needed so you don't have to put it, but if you put it when you don't need it then it will give you a different output than you expect. Just do:

Serial.println(now.hour());

Actually the code i posted is just a subset of the "DS3231" example code and that used the
DEC and in reading the language reference I did see it isn't needed.

Thanks to you both for your help.

So in finding another example on RTClib begin() function I noticed that in the wire.h library there is a
begin() listed yet I am not using that and most of the examples don't use the begin()
initialization for wire.h, will this cause issues later?

Now as an example if you look at the library "wire" page there is a whole list of functions
that tell you what they do with proper syntax. So this can't be done with RTClib?

It seems I spend a lot of time looking for these tidbits if they are not written up to help with
programming and understanding of the functions.

Bruce

7b_w:
It seems I spend a lot of time looking for these tidbits if they are not written up to help with
programming and understanding of the functions.

The thing is that the Wire library is part of the core libraries. So the Arduino site will have documentation on it. The libraries like the ones for RTC and such are not part of the core. They're written by other users and made available on the internet for you by them. They're not really part of the Arduino project proper. So you can't really expect the folks at Arduino to go find and document all those, although it seems like they've actually done that for a few. Some users write libraries and document them well. Most write libraries and don't do any documentation at all. Go look where you downloaded that library from and see if it is documented there.

If the RTC uses Wire, it may be that the begin function in the RTC library calls the begin function from the wire library. Maybe you could post a copy of the particular RTC library you are using (there are several) and we can look at it and see. Either way, I think you should probably be calling begin if it has a begin.

(deleted)

It seems I spend a lot of time looking for these tidbits if they are not written up to help with
programming and understanding of the functions.

The best place to go to understand a library is to the source code for the library itself. It's on your computer. You can use any text editor, but I like to use Notepad++ as it has a function list.

When you look at the begin() for the DS3231 implementation you find

boolean RTC_DS3231::begin(void) {
  Wire.begin();
  return true;
}

That being said, any time you use an i2c device you can't go wrong calling Wire.begin() in setup.

Thanks for the info.
Still a beginner with some knowledge of programming from the past, assembly language was my
thing using the MCS51 family but no more. These Arduino's are fun to use and program and I am
learning more as time goes by.
73's
Bruce W7BCW