Does anyone have an idea what's going on with this code?

#include <DS3231.h>

#include <LiquidCrystal.h>
int Contrast = 100;

DS3231 rtc(SDA, SCL);
LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
void setup() {
  rtc.begin();
  lcd.begin(16, 2);
}
void loop() {
  lcd.setCursor(0, 0);
  lcd.print("Time:  ");
  lcd.print(rtc.getTimeStr());

  lcd.setCursor(0, 1);
  lcd.print("Date: ");
  lcd.print(rtc.getDateStr());

  delay(1000);
}


image

The sketch looks like it is intended to print the date and time provided by a DS3231 Real Time Clock (RTC) on a 2 line Liquid Crystal Display (LCD) once a second

What is it that you do not understand about it ?

Anything is not working at the moment

"no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'" in the output

There are many RTC libraries, some with the same names. The one you included apparently does not match the code and doesn't have the functions called. Figure out what library you actually have and what it supports.

As suggested, you are probably using code not supported by the library that you have. Try looking at the examples that came with the library to see how the rtc instance is created in your case

Hi @1von ,

as already mentioned above there are several libraries existing with identical names.

You are quite likely using an example made for this lib:

http://www.rinkydinkelectronics.com/library.php?id=73

that uses SDA, SCL as parameters.

If you download the zip file you will find this example:

// DS3231_Serial_Easy
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS3231-library to 
// quickly send time and date information over a serial link
//
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// the pins as follows:
//
// Arduino Uno/2009:
// ----------------------
// DS3231:  SDA pin   -> Arduino Analog 4 or the dedicated SDA pin
//          SCL pin   -> Arduino Analog 5 or the dedicated SCL pin
//
// Arduino Leonardo:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 2 or the dedicated SDA pin
//          SCL pin   -> Arduino Digital 3 or the dedicated SCL pin
//
// Arduino Mega:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 20 (SDA) or the dedicated SDA pin
//          SCL pin   -> Arduino Digital 21 (SCL) or the dedicated SCL pin
//
// Arduino Due:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
//          SCL pin   -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
//
// The internal pull-up resistors will be activated when using the 
// hardware I2C interfaces.
//
// You can connect the DS3231 to any available pin but if you use any
// other than what is described above the library will fall back to
// a software-based, TWI-like protocol which will require exclusive access 
// to the pins used, and you will also have to use appropriate, external
// pull-up resistors on the data and clock signals.
//

#include <DS3231.h>

// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);

void setup()
{
  // Setup Serial connection
  Serial.begin(115200);
  // Uncomment the next line if you are using an Arduino Leonardo
  //while (!Serial) {}
  
  // Initialize the rtc object
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating :)
  delay (1000);
}

that uses the same functions as in your sketch.

Good luck!
ec2021

I already tried this and didn't change anything and still I get the same error. Maybe it's the rtc that is not functioning properly

the rtc lights up tho

Have you tried the examples that came with each of the libraries ?

I followed everything and still shows the same error which I don't understand

Then you are still using the wrong library.

@jremington Okay I already did use and there are no errors but it won't show in the serial monitor

EDIT: i already set the Serial.begin(9600) and still nothing shows in the serial monitor

Does your last post mean you do not get any compile errors?

And which sketch are you talking about?

Obsolete ????

You can try this:

  • Open the Library Manager in the Arduino IDE

  • Type "DS3231" in the search field

  • Choose Type "Installed"

  • Assuming you use Version 2.3.2 you should see something like this
    image

  • Remove all "DS321" libraries

  • Reinstall the specific lib from the link above (from a zip file):
    image

  • And try to compile one of the examples that come with this library

image

If you still have trouble we (you) might have to check the "libraries" directory ...

But let's give it a chance ...

Good luck!

Which code are you referring to?

Your original code in post #1 doesn't output anything to the serial monitor.

Are you referring to the example that @ec2021 showed in post #6 which does output to the serial monitor?

yes

yes

I already found the sketch. thanks

If you have questions about code, post that code, using code tags.

You have a bad habit (here and other unfinished topics) of not reading (listening), not trying, not learning, and expecting your work to be done by someone other than you.

Before you answer anyone, forever; (1) read the suggestion, (2) understand the suggestion by asking questions or reading on your own, (3) try the suggestion, (4) report what you find and (5) learn from the experience.

I appreciate for calling me out on that, I am aware of that habit of mine too, I have been asking a lot of questions. I'm just kind of stress out right now since this was handed out to me for our school research and I only have the smallest time left (not trying to make any excuses).

My apologies, I'm gonna take a break from asking these questions and try to do this on my own.

I'm really thankful to you all for helping me out on this.

Noted:)

If one wants quick and successful support the most important issue is

  • to give clear and sufficient information about the situation
    • software environment
    • wiring
    • sketch
    • error description (!)

If you still have problems don't give in but take care of this list when posting.

The number of members who can read minds or have clairvoyant abilities is very limited ,,,, (Where it looks like that it's mostly "professional guesswork" ...)

:wink: