Trying to make a very simple 4 digit clock.

Im a beginner and using Arduino for the first time. Im trying to follow a premade project (link) to make a RTC 4 digit 7-segment clock that shows hours and minutes on the display.
Instead of the Catalex Digital Tube display im using 4 digit 7 segment display from Qifei and an RTC module with an DS1307
If i try to run the code it starts giving me this error

Arduino: 1.8.1 (Windows 10), TD: 1.35, Board: "Arduino/Genuino Uno"

In file included from C:\Users\User\Documents\Arduino\sketch_mar05a\sketch_mar05a.ino:12:0:

C:\Users\User\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:19:22: error: 'tmElements_t' has not been declared

     static bool read(tmElements_t &tm);

                      ^

C:\Users\User\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:20:23: error: 'tmElements_t' has not been declared

     static bool write(tmElements_t &tm);

                       ^

C:\Users\User\Documents\Arduino\sketch_mar05a\sketch_mar05a.ino: In function 'void loop()':

sketch_mar05a:36: error: 'tmElements_t' was not declared in this scope

   tmElements_t tm;

   ^

sketch_mar05a:38: error: expected primary-expression before ')' token

                if (RTC.read(tm)) {

                               ^

sketch_mar05a:40: error: expected primary-expression before '.' token

     print2digits(tm.Hour);

                    ^

sketch_mar05a:42: error: expected primary-expression before '.' token

     print2digits(tm.Minute);

                    ^

sketch_mar05a:44: error: expected primary-expression before '.' token

     print2digits(tm.Second);

                    ^

sketch_mar05a:46: error: expected primary-expression before '.' token

     Serial.print(tm.Day);

                    ^

sketch_mar05a:48: error: expected primary-expression before '.' token

     Serial.print(tm.Month);

                    ^

sketch_mar05a:50: error: expected primary-expression before '.' token

     Serial.print(tmYearToCalendar(tm.Year));

                                     ^

sketch_mar05a:50: error: 'tmYearToCalendar' was not declared in this scope

     Serial.print(tmYearToCalendar(tm.Year));

                                          ^

sketch_mar05a:53: error: expected primary-expression before '.' token

     horas = tm.Hour;

               ^

sketch_mar05a:54: error: expected primary-expression before '.' token

     minutos = tm.Minute;

                 ^

exit status 1
'tmElements_t' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Can anyone help me out with the error to make this 'clock' work?

Hi,
Welcome to the Forum.

Please post your entire code so we can correlate it to your list of errors.

Thanks.. Tom.. :slight_smile:

Have a look at the beginning of DS1307RTC.h. If it contains this line:

#include <Time.h>

change it to:

#include <TimeLib.h>

Same thing for your sketch too.

Pete

I successfully uploaded the code, but the LED module shows H.H. instead of the time.

In that case, like @TomGeorge says, now you need to post all your code.

Pete

// Reloj digital mostrado a través de un display de 4 dígitos (digitaltube), y con el tiempo
// proporcionado por un Tiny RTC de Catalex.

// Software programado por PentiumCadiz 7-1-17, basado en el ejemplo de la librería DS1307RTC 
// y en el ejemplo de uso del display de Prometec  http://www.prometec.net/display-con-interface/ 

#include <TM1637.h>

#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>

#define CLK 9
#define DIO 8

TM1637 Display1(CLK, DIO);
  int8_t Digitos[] = {0,1,2,3};
  int horas;
  int minutos;
  boolean alterna;

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for serial
  delay(200);
  Serial.println("DS1307RTC Read Test");
  Serial.println("-------------------");

  Display1.set();
  Display1.init();
  
}

void loop() {
  tmElements_t tm;

  if (RTC.read(tm)) {
    Serial.print("Ok, Time = ");
    print2digits(tm.Hour);
    Serial.write(':');
    print2digits(tm.Minute);
    Serial.write(':');
    print2digits(tm.Second);
    Serial.print(", Date (D/M/Y) = ");
    Serial.print(tm.Day);
    Serial.write('/');
    Serial.print(tm.Month);
    Serial.write('/');
    Serial.print(tmYearToCalendar(tm.Year));
    Serial.println();

    horas = tm.Hour;
    minutos = tm.Minute;
    CalculaDigitos(horas, minutos);
    if (alterna)
      {
        Display1.point(POINT_OFF);
        alterna = false;
      }
      else
      {
        Display1.point(POINT_ON);
        alterna = true;
      }
    
  } else {
    if (RTC.chipPresent()) {
      Serial.println("The DS1307 is stopped.  Please run the SetTime");
      Serial.println("example to initialize the time and begin running.");
      Serial.println();
    } else {
      Serial.println("DS1307 read error!  Please check the circuitry.");
      Serial.println();
    }
    delay(9000);
  }
  delay(1000);
}

void print2digits(int number) {
  if (number >= 0 && number < 10) {
    Serial.write('0');
  }
  Serial.print(number);
}

void CalculaDigitos( int hor, int minu)
   {
      int8_t Digit0 = minu %10 ;
      int8_t Digit1 = (minu % 100) / 10 ;
      int8_t Digit2 = hor % 10 ;
      int8_t Digit3 = (hor % 100) / 10 ;

      Digitos[3] = Digit0 ;
      Digitos[2] = Digit1 ;
      Digitos[1] = Digit2 ;
      Digitos[0] = Digit3 ;

      Display1.display(Digitos);
   }

This is the code i tried to upload

the Catalex Digital Tube display using the TM1637 chip using i2c

4 digit 7 segment display from Qifei using 2 cascaded 74HC595 shift registers

so, the code is difference

/*                        Digital Clock
     Digital Clock with LED Display - 4 Digits x 7 Segments
       Display Time, Temperature and Relative Humidity
                        V1.1 - 10.Fev.2016

 *** Notes of revision V1.1 ***
     - Translated the remarks/comments into English
     - Added optional statements to show the Temperature in Fahrenheit Degrees (F)

*/

#include <Time.h>        //Time Library
#include <DS1307RTC.h>   //Real Time Clock Library
#include <Wire.h>        //Auxiliary Library for DS1307RTC (Real-Time Clock) - Pins to Arduino UNO: A4 (SDA), A5 (SCL)
#include <dht11.h>       //Temperature and Humidity Library
dht11 DHT;               //Define the name DHT for the sensor of Temperature and Humidity
#define DHT11_PIN 11     //Sensor DHT11 conected to the pin 11 on Arduino

int clockPin = 8; // Pin 8 of Arduino connected in the pin 11 of 74HC595 (Clock)
int latchPin = 9; // Pin 9 of Arduino connected in the pin 12 of 74HC595 (Latch)
int dataPin = 10; // Pin 10 of Arduino connected in the pin 14 of 74HC595 (Data)

int hora, minuto, temp, umid;
int unidadeHora, unidadeMinuto, dezenaHora, dezenaMinuto;
int unidadeTemp, dezenaTemp, unidadeUmid, dezenaUmid;
unsigned long ti;
int chk; //Variable to read the sensor DHT11

//Digits Matrix - 0 a 9
byte num[] = {

  B01111110, // Zero
  B00110000, // One
  B01101101, // Two
  B01111001, // Three
  B00110011, // Four
  B01011011, // Five
  B01011111, // Six
  B01110000, // Seven
  B01111111, // Eight
  B01111011, // Nine

};


void setup() {

  pinMode(latchPin, OUTPUT); // Define the 3 digital pins as output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  setSyncProvider(RTC.get);   // Update the time with data of RTC (Real Time Clock)

  //setTime(15, 05, 00, 13, 02, 2016);

}


void loop() {

  ti = millis(); // Initial time for the Timer of Hour/Time

  while ((millis() - ti) < 3000) { //Timer of 3 seconds to show the Hour

    hora = hour();
    minuto = minute();
    unidadeHora = hora % 10;
    dezenaHora = hora / 10;
    unidadeMinuto = minuto % 10;
    dezenaMinuto = minuto / 10;

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1 (top view from left to right)
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaHora]);   //Set the Hour (ten)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 4);                  //Set DISPLAY 2
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeHora]);  //Set the Hour (unit)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 2);                  //Set DISPLAY 3
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaMinuto]); //Set the Minute (ten)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                   //Set DISPLAY 4
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeMinuto]); //Set the Minute (unit)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 4);                  //Set LED of dots
    shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000);         //Set LEDs of double dots
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                  //Set DISPLAY 4
    shiftOut(dataPin, clockPin, LSBFIRST, 255);                //Reset the DISPLAY 4 (to avoid some flicking)
    digitalWrite(latchPin, HIGH);
  }
  delay(500);  //Wait for half second before go ahead to show the next feature


  chk = DHT.read(DHT11_PIN);  //Read data of sensor DHT11

  ti = millis(); //Initial time for the Timer of Temperature
  temp = DHT.temperature; //Reading the Temperature in Celsius degree (C)

  //Optional calculation of Temperature in Fahrenheit degrees (F). Remove the comments ("//") of following statement to use it.
  //temp = (temp*18+5)/10+32;

  while ((millis() - ti) < 3000) { //Timer of 3 seconds for the Temperature

    unidadeTemp = temp % 10;
    dezenaTemp = temp / 10;

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 8);                  //Set DISPLAY 1 (top view from left to right)
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaTemp]);   //Set the Temperature (ten)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 4);                  //Set DISPLAY 2
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeTemp]);  //Set the Temperature (unit)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 2);                  //Set DISPLAY 3
    shiftOut(dataPin, clockPin, LSBFIRST, ~B01100011);         //Set the degree symbol []
    digitalWrite(latchPin, HIGH);

    //Show the Temperature in Celsius degrees (C)
    //Set the following statements as comments with "//" to show the Temperature in Fahrenheit (F)
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                  //Set DISPLAY 4
    shiftOut(dataPin, clockPin, LSBFIRST, ~B01001110);         //Set the symbol of Celsius [C]
    digitalWrite(latchPin, HIGH);

    //Show the Temperature in Fahrenheit degrees (F)
    //Remove the indication of comments "//" on following statements to show the Temperature in Fahrenheit (F)
    //digitalWrite(latchPin, LOW);
    //shiftOut(dataPin, clockPin, LSBFIRST, 1);                 //Set DISPLAY 4
    //shiftOut(dataPin, clockPin, LSBFIRST, ~B01000111);        //Set the symbol of Fahrenheit [F]
    //digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                   //Set DISPLAY 4
    shiftOut(dataPin, clockPin, LSBFIRST, 255);                 //Reset the DISPLAY 4 (to avoid some flicking)
    digitalWrite(latchPin, HIGH);
  }
  delay(500);  //Wait for half second before go ahead to show the next feature

  ti = millis(); //Initial time for the Timer of Humidity
  umid = DHT.humidity; //Reading the Humidity

  while ((millis() - ti) < 3000) { //Timer of 3 seconds for the Humidity

    unidadeUmid = umid % 10;
    dezenaUmid = umid / 10;

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 8);                  //Set DISPLAY 1
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaUmid]);   //Set the Humidity (ten)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 4);                  //Set DISPLAY 2
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeUmid]);  //Set the Humidity (unit)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 2);                  //Set DISPLAY 3
    shiftOut(dataPin, clockPin, LSBFIRST, ~B01100011);         //Set the upper symbol of percentage [%] of Humidity
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                  //Set DISPLAY 4
    shiftOut(dataPin, clockPin, LSBFIRST, ~B00011101);         //Set the lower symbol of percentage [%] of Humidity
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                  //Set Display 4
    shiftOut(dataPin, clockPin, LSBFIRST, 255);                //Reset the DISPLAY 4 (to avoid some flicking)
    digitalWrite(latchPin, HIGH);
  }
  delay(500);  //Wait for half second before to restart

}

I tried to verify the code, but yet again it gives me errors

C:\Users\User\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:19:22: error: 'tmElements_t' has not been declared

     static bool read(tmElements_t &tm);

                      ^

C:\Users\User\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:20:23: error: 'tmElements_t' has not been declared

     static bool write(tmElements_t &tm);

                       ^

sketch_mar11a:17: error: 'dht11' does not name a type

 dht11 DHT;               //Define the name DHT for the sensor of Temperature and Humidity

 ^

C:\Users\User\Documents\Arduino\sketch_mar11a\sketch_mar11a.ino: In function 'void setup()':

sketch_mar11a:53: error: 'setSyncProvider' was not declared in this scope

   setSyncProvider(RTC.get);   // Update the time with data of RTC (Real Time Clock)

                          ^

C:\Users\User\Documents\Arduino\sketch_mar11a\sketch_mar11a.ino: In function 'void loop()':

sketch_mar11a:66: error: 'hour' was not declared in this scope

     hora = hour();

                 ^

sketch_mar11a:67: error: 'minute' was not declared in this scope

     minuto = minute();

                     ^

sketch_mar11a:106: error: 'DHT' was not declared in this scope

   chk = DHT.read(DHT11_PIN);  //Read data of sensor DHT11

         ^

Using library DS1307RTC at version 1.4 in folder: C:\Users\User\Documents\Arduino\libraries\DS1307RTC 
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
Using library DHT11 in folder: C:\Program Files (x86)\Arduino\libraries\DHT11 (legacy)
exit status 1
'dht11' does not name a type

It's the same fix as before. Change Time.h to TimeLib.h in the sketch

Pete

After changing Time.h to TimeLib.h im still getting errors regarding dht11

sketch_mar11a:16: error: 'dht11' does not name a type

 dht11 DHT;               //Define the name DHT for the sensor of Temperature and Humidity

 ^

C:\Users\User\Documents\Arduino\sketch_mar11a\sketch_mar11a.ino: In function 'void loop()':

sketch_mar11a:105: error: 'DHT' was not declared in this scope

   chk = DHT.read(DHT11_PIN);  //Read data of sensor DHT11

         ^

Using library Time-master at version 1.5 in folder: C:\Users\User\Documents\Arduino\libraries\Time-master 
Using library DS1307RTC at version 1.4 in folder: C:\Users\User\Documents\Arduino\libraries\DS1307RTC 
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
Using library DHT11 in folder: C:\Program Files (x86)\Arduino\libraries\DHT11 (legacy)
exit status 1
'dht11' does not name a type

By the way im not using a Humidity and Temp sensor, so do i need it or can i finish the project without the sensor?

Remove the include of dht11.h and all references to DHT.

Pete

I think i deleted everything referring to DHT and and uploaded this code

/*                        Digital Clock
     Digital Clock with LED Display - 4 Digits x 7 Segments
       Display Time, Temperature and Relative Humidity
                        V1.1 - 10.Fev.2016

 *** Notes of revision V1.1 ***
     - Translated the remarks/comments into English
     - Added optional statements to show the Temperature in Fahrenheit Degrees (F)

*/

#include <TimeLib.h>        //Time Library
#include <DS1307RTC.h>   //Real Time Clock Library
#include <Wire.h>        //Auxiliary Library for DS1307RTC (Real-Time Clock) - Pins to Arduino UNO: A4 (SDA), A5 (SCL)
#define DHT11_PIN 11     //Sensor DHT11 conected to the pin 11 on Arduino

int clockPin = 8; // Pin 8 of Arduino connected in the pin 11 of 74HC595 (Clock)
int latchPin = 9; // Pin 9 of Arduino connected in the pin 12 of 74HC595 (Latch)
int dataPin = 10; // Pin 10 of Arduino connected in the pin 14 of 74HC595 (Data)

int hora, minuto, temp, umid;
int unidadeHora, unidadeMinuto, dezenaHora, dezenaMinuto;
int unidadeTemp, dezenaTemp, unidadeUmid, dezenaUmid;
unsigned long ti;
int chk; //Variable to read the sensor DHT11

//Digits Matrix - 0 a 9
byte num[] = {

  B01111110, // Zero
  B00110000, // One
  B01101101, // Two
  B01111001, // Three
  B00110011, // Four
  B01011011, // Five
  B01011111, // Six
  B01110000, // Seven
  B01111111, // Eight
  B01111011, // Nine

};


void setup() {

  pinMode(latchPin, OUTPUT); // Define the 3 digital pins as output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  setSyncProvider(RTC.get);   // Update the time with data of RTC (Real Time Clock)

  //setTime(15, 05, 00, 13, 02, 2016);

}


void loop() {

  ti = millis(); // Initial time for the Timer of Hour/Time

  while ((millis() - ti) < 3000) { //Timer of 3 seconds to show the Hour

    hora = hour();
    minuto = minute();
    unidadeHora = hora % 10;
    dezenaHora = hora / 10;
    unidadeMinuto = minuto % 10;
    dezenaMinuto = minuto / 10;

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1 (top view from left to right)
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaHora]);   //Set the Hour (ten)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 4);                  //Set DISPLAY 2
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeHora]);  //Set the Hour (unit)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 2);                  //Set DISPLAY 3
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaMinuto]); //Set the Minute (ten)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                   //Set DISPLAY 4
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeMinuto]); //Set the Minute (unit)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 4);                  //Set LED of dots
    shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000);         //Set LEDs of double dots
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                  //Set DISPLAY 4
    shiftOut(dataPin, clockPin, LSBFIRST, 255);                //Reset the DISPLAY 4 (to avoid some flicking)
    digitalWrite(latchPin, HIGH);
  }


 
}

Yet again its showing H.H. on the 2 middle digits, not the hours/minutes

When two separate libraries/sketches give the same result it is time to check the hardware. Are you sure that you have the clock and data pins connected correctly?

Pete

Is there any way i can show you guys how the wires are connected?

Draw a circuit diagram or take a photo of the connections. Either way you have to upload an image - there's info on the site about how to do that.

Pete

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Also a clear picture of your project would help too.

Thanks.. Tom.. :slight_smile:

As far as the clock part, if you can get your RTC to make an interrupt once per second, the rest is math and logic.

Perhaps ditching the example with the wrong display unit and starting from examples for the right RTC and display will make the job easier.

Heres the wiring. As i know almost nothing about these kind of stuff i had my friend show do it for me.

As im using some different parts i have f1 on the breadboard wired up to a pin called CLK, c3 wired up to a pin called DAT and c2 wired up to a pin called SCLK.

Heres a picture of the project

Also sorry not not specifying that im using an UNO clone.

The code in message #11 has the clock pin going to pin 8 and the data to pin 10.
Your diagram, which isn't very good because some of the "wires" cross and are difficult to follow because they are all the same colour, appears to probably show the same thing.
However, it appears from that diagram and the photo that you are only using UNO pins 8 (CLK?) and 9 (Data - DIO?) so you need to change the code so that dataPin is defined to be 9. I don't think you have a latchPin on the display so you can ignore latchPin.

Pete

Hi,
Try this first to get your display working properly.

http://www.techmonkeybusiness.com/tm1637-4-digit-display-example-sketch.html

Tom... :slight_smile: