DS3231_Simple library. Print date and time to lcd

Hi all,

I have the sensor DS3231 and I am using the library DS3231_Simple.

Does anyone know any command or line of code to just print the date and time to an lcd?

I do not think that posting the code is necessary for this question.

Ideal would be to find similar commands as the ones to print the date and time on the serial:
Clock.printDateTo_DMY(Serial);
Serial.print(", ");

Clock.printTimeTo_HMS(Serial);
Serial.print(", ");

The reason for using this library was only to be able to easily modify the code to my liking (arduino where via joystick you can change the year, month, ...), with the info printed in an lcd.

I already tried the typical DS3231 library with rtc commands but I was not able to create the code as I have managed with the "simple library".

I have searched for such commands, trying to convert the binary data obtained from the sensor and convert it to decimal to print it, but with no success.

Source for library:

https://cdn.rawgit.com/sleemanj/DS3231_Simple/31d0dac/docs/html/functions.html

I appreciate any help provided :slight_smile:

Ideal would be to find similar commands as the ones to print the date and time on the serial

If your LCD supports the Stream interface (many do, but you keep your model and library secret) you can use the same commands, just replace Serail by the LCD object.

did you look at the example code? it looks like it's all laid out for you

Hi Geek Emeritus and pylon,

Thank you for your pieces of advice and fast reply

pylon:
If your LCD supports the Stream interface (many do, but you keep your model and library secret) you can use the same commands, just replace Serail by the LCD object.

I did some tests like this before posting. Your comment gave me more ideas but I still get an error. Any other ideas?

These are my LCD libraries:
<LiquidCrystal_I2C.h>
<LCD.h>

Screen model:
2004 204 20x4 Character LCD Display Module HD44780 (purchased on ebay)

Tests:

Test 1:
Clock.printDateTo_DMY(LiquidCrystal_I2C);
Clock.printTimeTo_HMS(LiquidCrystal_I2C);

Error 1:

exit status 1
expected primary-expression before ')' token

Test 2:
Clock.printDateTo_DMY(LCD);
Clock.printTimeTo_HMS(LCD);
Error 2:
exit status 1
expected primary-expression before ')' token

Test 3:
Clock.printDateTo_DMY(lcd);
Clock.printTimeTo_HMS(lcd);
Error 3:
exit status 1
no matching function for call to 'DS3231_Simple::printDateTo_DMY(LiquidCrystal_I2C&)'

Test 4:
printDateTo_DMY(LiquidCrystal_I2C&);
printTimeTo_DMY(LiquidCrystal_I2C&);
Error 4:
exit status 1
expected primary-expression before '&' token

Thanks, I did. All the example codes are unfortunately with "Serial". Different forms of displaying data but no example where the data is displayed in an LCD or anything different than "Serial".

just change Serial.print to lcd.print

The author of DS3231_Simple did a bad choice by using the Stream class as the Print class would be a much better choice.

You can fix the library by replacing every occurrence of "Stream" by "Print" except for the method promptForTimeAndDate() (in both DS3231_Simple.h and DS3231_Simple.cpp). Then use version "Test 3".

pylon:
The author of DS3231_Simple did a bad choice by using the Stream class as the Print class would be a much better choice.

You can fix the library by replacing every occurrence of "Stream" by "Print" except for the method promptForTimeAndDate() (in both DS3231_Simple.h and DS3231_Simple.cpp). Then use version "Test 3".

This solution worked like a charm. For people with this problem, open the mentioned files with wordpad to be able to search "Stream" and replace it with "Print" more easily with the search function.

I thank you pylon for solving my issue in such an straightforward manner!! I have been trying things for days unsuccessfully. I really can not thank you enough!

I have never seen "Stream" in coding before. Is there any link you recommend to further understand this?

In this particular case there is not Serial.print or lcd.print in the code. That is what blocked me in the first case. Thanks nonetheless for your suggestions and effort :slight_smile:

I have never seen "Stream" in coding before. Is there any link you recommend to further understand this?

It's part of the IDE source code. Usually it's in the same directory as the Arduino.h file, on Linux systems it's in hardware/arduino/avr/cores/arduino/ inside the IDE folder, I guess on other operating systems it's at a similar location. Many of the base library classes are based on Print and Stream, which makes it much easier to write hardware independent classes.