No matching function call error

I am working on making a countdown timer for the birth of a baby. I found all the requisite information on Thingiverse for a 3d printable baby bottle with a small LCD that counts down the days, hours and minutes until the due date. The fileset also included the code. The hardware I am using is the same as the source files, namely an Arduino Nano, a I2C RTC DS1307 AT24C32 Real Time Clock Module, a KY-040 rotary encoder module, and a 0.96 Inch OLED Module. When I attempt to verify the included code I get the an error message: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)' . So I contacted the person who wrote the code, seeing if there was an update. He said there was none needed, and thought the problem was in the inclusion of required libraries. I double checked, and found all required libraries have been included in my sketch. So I continued to do some digging. I have been told that the problem lies in the fact that the current version of the DS3231 library doesn't have a constructor that accepts parameters such as SDA & SCL, which are in the code. Now that I know what the potential problem is, I still don't know how to fix it.

Any assistance will be greatly appreciated.

Here is the wiring diagram:

Here is the link to the Thingiverse files
https://www.thingiverse.com/thing:6049409/comments

Here is the code I am attempting to use:


#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DS3231.h>

// Etats de la machine d'état
#define ETAT_DECOMPTE    10
#define ETAT_JOURS_CEN   20
#define ETAT_JOURS_DIZ   21
#define ETAT_JOURS_UNI   22
#define ETAT_HEURES_DIZ  30
#define ETAT_HEURES_UNI  31
#define ETAT_MINUTES_DIZ 40
#define ETAT_MINUTES_UNI 41
#define ETAT_FINAL       99
int etatMachine = ETAT_DECOMPTE;
int nbJour = 0;
int nbHeure = 0;
int nbMinute = 0;
int nbSeconde = 0;

#define OLED_LARGEUR 128
#define OLED_HAUTEUR  64

// Declaration SSD1306 I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define OLED_ADRESSE 0x3C // Voir derriere l'ecran
Adafruit_SSD1306 display(OLED_LARGEUR, OLED_HAUTEUR, &Wire, OLED_RESET);

// Switch
int pinSwitch = 8;
int valSwitch;
int valSwitchDernier;
int pinDt = 9;
int valDt;
int valDtDernier;
int pinClk = 10;
int valClk;
int valClkDernier;
int dernierEnfonce;
int dureeEnfonce;

// Horloge
DS3231 horloge(SDA, SCL);

void GestionSwitch() {
  valSwitch = digitalRead(pinSwitch);
  valDt = digitalRead(pinDt);
  valClk = digitalRead(pinClk);

  // Rotation du bouton
  if (valClk != valClkDernier && valClk == 1) {
    if (etatMachine == ETAT_JOURS_CEN)
      nbJour = (nbJour + 100) % 1000;
    if (etatMachine == ETAT_JOURS_DIZ)
      nbJour = nbJour / 100 * 100 + ((nbJour / 10 + 1) % 10) * 10 + nbJour % 10;
    if (etatMachine == ETAT_JOURS_UNI)
      nbJour = 10 * (nbJour / 10) + (nbJour + 1) % 10;

    if (etatMachine == ETAT_HEURES_DIZ)
      nbHeure = (nbHeure + 10) < 24 ? nbHeure + 10 : 0;
    if (etatMachine == ETAT_HEURES_UNI)
      nbHeure = 10 * (nbHeure / 10) + (((nbHeure % 10) + 1) % 10);

    if (etatMachine == ETAT_MINUTES_DIZ)
      nbMinute = (nbMinute + 10) < 60 ? nbMinute + 10 : 0;
    if (etatMachine == ETAT_MINUTES_UNI)
      nbMinute = 10 * (nbMinute / 10) + (((nbMinute % 10) + 1) % 10);
  }

  // Click du bouton
  if (valSwitch != valSwitchDernier) {
    if (valSwitch == LOW) {
      // Le bouton vient d'être enfoncé
      dernierEnfonce = millis();
    } else {
      // Bouton vient d'être relâché
      dureeEnfonce = millis() - dernierEnfonce;

      if (dureeEnfonce >= 100) {
        if (etatMachine == ETAT_FINAL) {
          etatMachine = ETAT_JOURS_CEN;
        } else if (etatMachine == ETAT_DECOMPTE) {
          etatMachine = ETAT_JOURS_CEN;
          DifferenceMinute();
        } else if (etatMachine == ETAT_JOURS_CEN) {
          etatMachine = ETAT_JOURS_DIZ;
        } else if (etatMachine == ETAT_JOURS_DIZ) {
          etatMachine = ETAT_JOURS_UNI;
        } else if (etatMachine == ETAT_JOURS_UNI) {
          etatMachine = ETAT_HEURES_DIZ;
        } else if (etatMachine == ETAT_HEURES_DIZ) {
          etatMachine = ETAT_HEURES_UNI;
        } else if (etatMachine == ETAT_HEURES_UNI) {
          etatMachine = ETAT_MINUTES_DIZ;
        } else if (etatMachine == ETAT_MINUTES_DIZ) {
          etatMachine = ETAT_MINUTES_UNI;
        } else if (etatMachine == ETAT_MINUTES_UNI) {
          etatMachine = ETAT_DECOMPTE;
          AjusteDateHeure();
        }
      }
    }

    valSwitchDernier = valSwitch;
  }

  valSwitchDernier = valSwitch;
  valDtDernier = valDt;
  valClkDernier = valClk;
}

void DifferenceMinute() {
  Time debut = horloge.getTime();
  long difHeure = (long)86400 - ((long)(debut.hour) * 3600 + (long)(debut.min) * 60 + (long)debut.sec);
  nbSeconde = difHeure % 60;
  nbMinute = (difHeure / 60) % 60;
  nbHeure = difHeure / 3600;
  nbJour = 0;

  if (debut.year < 2020) {
    // Parcours les jours.
    while (2020 > debut.year) {
      nbJour++;

      // Change d'annee
      if (debut.mon == 12 && debut.date == 31) {
        debut.date = 1;
        debut.mon = 1;
        debut.year = debut.year + 1;

        // Change de mois
      } else if ((debut.mon == 1 && debut.date == 31) ||
                 (debut.mon == 2 && debut.date == 28 && debut.year % 4 != 0) ||
                 (debut.mon == 2 && debut.date == 29 && debut.year % 4 == 0) ||
                 (debut.mon == 3 && debut.date == 31) || (debut.mon == 4 && debut.date == 30) ||
                 (debut.mon == 5 && debut.date == 31) || (debut.mon == 6 && debut.date == 30) ||
                 (debut.mon == 7 && debut.date == 31) || (debut.mon == 8 && debut.date == 31) ||
                 (debut.mon == 9 && debut.date == 30) || (debut.mon == 10 && debut.date == 31) ||
                 (debut.mon == 11 && debut.date == 30)) {
        debut.date = 1;
        debut.mon = debut.mon + 1;
      }
      else { // Change de jour
        debut.date = debut.date + 1;
      }
    }
  }
}

void AffichageTexte(String texte, int taille, int posX, int posY, bool isAllume) {
  display.setTextSize(taille);
  display.setCursor(posX, posY);
  display.print(isAllume ? texte : "");
}

void Affichage() {
  display.clearDisplay();
  bool isAllume = etatMachine == ETAT_DECOMPTE || ((millis() - dernierEnfonce) % 1500) > 500;

  // Vérifie si on a fini le décompte
  if (etatMachine == ETAT_DECOMPTE)
    etatMachine = nbJour == 0 && nbHeure == 0 && nbMinute == 0 ? ETAT_FINAL : etatMachine;

  if (etatMachine == ETAT_FINAL) {
    AffichageTexte("Youpi!", 3, 15, 20, isAllume);
  } else {
    // Affiche le nombre de jours.
    AffichageTexte(String(nbJour / 100), 4, 14, 10, etatMachine == ETAT_JOURS_UNI ||
                   etatMachine == ETAT_JOURS_DIZ || (etatMachine == ETAT_JOURS_CEN && isAllume) ||
                   (etatMachine != ETAT_JOURS_CEN && nbJour > 99) ||
                   (etatMachine == ETAT_DECOMPTE && nbJour > 99));
    AffichageTexte(String((nbJour % 100) / 10), 4, 39, 10, etatMachine == ETAT_JOURS_UNI ||
                   etatMachine == ETAT_JOURS_CEN || (etatMachine == ETAT_JOURS_DIZ && isAllume) ||
                   (etatMachine != ETAT_JOURS_DIZ && nbJour > 9) ||
                   (etatMachine == ETAT_DECOMPTE && nbJour > 9));
    AffichageTexte(String(nbJour % 10), 4, 64, 10, etatMachine != ETAT_JOURS_UNI ||
                   (etatMachine == ETAT_JOURS_UNI && isAllume));
    AffichageTexte(nbJour > 1 ? "jours" : "jour", 1, 90, 31, true);

    // Affiche HH:MM:SS
    AffichageTexte(String(nbHeure / 10), 2, 15, 46, (etatMachine == ETAT_HEURES_DIZ && isAllume) ||
                   (etatMachine != ETAT_HEURES_DIZ && nbHeure > 9));
    AffichageTexte(String(nbHeure % 10), 2, 27, 46, (etatMachine != ETAT_HEURES_UNI) || isAllume);
    AffichageTexte(":", 2, 39, 46, true);
    AffichageTexte(String(nbMinute / 10), 2, 51, 46, (etatMachine != ETAT_MINUTES_DIZ) || isAllume);
    AffichageTexte(String(nbMinute % 10), 2, 63, 46, (etatMachine != ETAT_MINUTES_UNI) || isAllume);
    AffichageTexte(":", 2, 75, 46, etatMachine == ETAT_DECOMPTE);
    AffichageTexte(String(nbSeconde / 10), 2, 87, 46, etatMachine == ETAT_DECOMPTE);
    AffichageTexte(String(nbSeconde % 10), 2, 99, 46, etatMachine == ETAT_DECOMPTE);

    display.display();
  }
}

// Ajuste la date et l'heure actuelle
void AjusteDateHeure() {
  int annee = 2020;
  int mois = 1;
  int jour = 1;
  int heure = 0;
  int minut = 0;

  // Soustraire heures et minutes
  heure = (1440 - (nbHeure * 60 + nbMinute)) / 60;
  minut = (1440 - (nbHeure * 60 + nbMinute)) % 60;

  // Soustraire les jours
  while (nbJour > 0) {
    annee = (jour == 1 && mois == 1) ? annee - 1 : annee;
    mois = jour == 1 ? (mois == 1 ? 12 : mois - 1) : mois;
    jour = jour == 1 ? joursDansMois(mois, annee) : jour - 1;
    nbJour--;
  }

  horloge.setDate(jour, mois, annee);
  horloge.setTime(heure, minut, 0);

  DifferenceMinute();
}

// Fonction pour déterminer le nombre de jours dans un mois
int joursDansMois(int mois, int annee) {
  if (mois == 2) {
    if (annee % 4 == 0 && (annee % 100 != 0 || annee % 400 == 0)) {
      return 29; // Année bissextile
    } else {
      return 28; // Aannée non-bissextile
    }
  } else if (mois == 4 || mois == 6 || mois == 9 || mois == 11) {
    return 30; // mois de 30 jours
  } else {
    return 31; // mois de 31 jours
  }
}

void setup() {
  Serial.begin(115200);

  // Préparation de l'écran OLED
  if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADRESSE)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }

  // Caracteristiques du texte
  display.setTextSize(3);
  display.setTextColor(SSD1306_WHITE);

  // Switch, Dt et Clk
  pinMode (pinSwitch, INPUT);
  pinMode (pinDt, INPUT);
  pinMode (pinClk, INPUT);
  pinMode (pinSwitch, INPUT_PULLUP);
  pinMode (pinDt, INPUT_PULLUP);
  pinMode (pinClk, INPUT_PULLUP);
  valSwitchDernier = digitalRead(pinSwitch);
  valDtDernier = digitalRead(pinDt);
  valClkDernier = digitalRead(pinClk);

  // Initialise l'horloge
  horloge.begin();
  DifferenceMinute();
  if (nbJour + nbHeure + nbMinute <= 0) {
    horloge.setTime(0, 0, 0);
    horloge.setDate(1, 1, 2020);
  }
}

void loop() {
  if (etatMachine == ETAT_DECOMPTE)
    DifferenceMinute();

  GestionSwitch();
  Affichage();
  delay(50);
}

There are several different libraries for the DS3231, all with the same or very similar names. You have to choose the one that matches the code. Perhaps the program author can advise which one.

I contacted him and he told me which one he believes it to be. I have that one installed, but still encounter the error. Is there a way to force IDE to only see the correct library, or should I uninstall the others that are similar, but not the same?

One way or another, you must include the library that matches the code. That error message is a clear indicator that you included the wrong one.

Or, change to code to match the library you have. Most libraries have examples that show you how to use them.

This from an example of the DS3231.h that you find if you add arduino and search for ds3232.h:

#include <DS3231.h>
#include <Wire.h>

DS3231 myRTC;

Just use horloge instead of myRTC as the object name.

a7

I have removed all other libraries with DS3231 in the name except for the two that the author specified. Now I get a new new error

Compilation error: DS3231.h: No such file or directory

I am not sure how this is possible. Though I am completely new to coding, and would learn how to start from scratch to do this, except for the fact that its a time sensitive project as there will be no need for it in a few months when the baby is born, and it would likely take me longer to learn. Still plan on learning, but it is complicated for a beginner such as myself.

Where did you put the library?

With this form of include, it should be in your sketchbook/libraries folder. On some PCs/operating systems, file names are case sensitive.

#include <DS3231.h>

That's odd.

You've gone this far, try removing the remaining library. Reinstall one ds3231 library.

a7

@xo-manowar - it is easier to use the library management tools in the IDE. Most ppl never need to know or find out where it places libraries when you install them.

a7

I don't know where they are saved. I am using the manage library options in Arduino IDE.

I have looked into all DS3231-libraries that the Arduino-IDE library-manager offers
Non of these libraries uses parameter in the constructor
which is this line of code

It seems that you are in the unlucky situation of having no knowlegde about C++ yet
trying to use a code that makes use of a rarely used DS3231-library which needs the I2C told as parameters

The ususal way to use I2C is using the standard IO-pins and in case you want to use different pins to specify these different pins in the wire.begin()-function-call not in the rtc-constructor

Your code does it different which is non standard and causes problems like the one you encountered.

The code seems to be french. Is this correct?
If post a picture of how the finished project / the count down-clock looks like
this would be good.

If you can post a picture how the clock looks like the users here can make a suggestion to use a different code or how to adpat the code to make it work.

best regards Stefan

I knew there had to be some sort of mismatch, as I was originally told. Below is what the timer will look like once completed, though I wanted to make it in English, versus French; that much I think I knew how to recode if the original would have worked.

The picture is nice why did you delete your post?

Now the original does not work.

Show number of days ther were counted down and a 24-hour count-down
Is this correct?

I think the library at the link below might be the one the original author used:

Rinky-Dink Electronics: DS3231 Library

Yes. A simple countdown timer that lists days, hours, and minutes. Adjustable through the rotary input so that the timer could be set without having to reconnect to a computer and recoded

I installed the library you suggested, and that seemed to help. I now can get the code to compile correctly, and uploaded it to the Nano. The issue I have now is that the display is not showing what I would anticipate, instead it is what appears to be random pixels, or "static" for lack of a better term on my part. In this picture you can get a better idea of what I mean.

I double and triple checked the wiring and it's spot on. I also thought maybe the display itself was bad since it is partly in yellow and partly in blue. Turns out I ordered a display with two lines of yellow and six of blue. I don't think this is causing my problems though.

Thoughts on anything else to try to resolve the issue?

I usually keep I2C wire lengths down to an inch or two. On a breadboard. Your mileage may vary. Sorry, but that picture just makes me wince.

yeah, I forgot to include the disclaimer warning to overlook the atrocious soldering and wiring skills I currently possess :slight_smile: when I breadboarded it, I used significantly shorter jumper wires, but didn't take a picture like I should have. Same result though, unfortunately.

Are you sure your display uses an SSD1306 controller? If it uses something else that's close but not quite compatible it might explain the static.