Problem with code for Arduino using an RTC

Hi,
I am working on a code to create a moving clock system. I have an RTC1302 to keep the time and the plan is to use that time keeping system to move servo motors at designated times.
I don't have much experience with Arduino code yet, but attached is what I currently have
sketch_feb24a.ino (5.0 KB)
.
The top section of the code is the virtuabotixRTC program which did not show up in the possible library downloads so I just found it online. If anyone has any help regarding how to fix these errors I will be very grateful.

Error messages -

Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"

C:\Users\agkos\AppData\Local\Temp\ccNz4bDJ.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_sketch_feb24a.ino.cpp.o.1901':

:(.text.startup+0x8e): undefined reference to `virtuabotixRTC::virtuabotixRTC(unsigned char, unsigned char, unsigned char)'

C:\Users\agkos\AppData\Local\Temp\ccNz4bDJ.ltrans0.ltrans.o: In function `setup':

C:\Users\agkos\OneDrive\Documents\Arduino\sketch_feb24a/sketch_feb24a.ino:64: undefined reference to `virtuabotixRTC::setDS1302Time(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, int)'

C:\Users\agkos\AppData\Local\Temp\ccNz4bDJ.ltrans0.ltrans.o: In function `loop':

C:\Users\agkos\OneDrive\Documents\Arduino\sketch_feb24a/sketch_feb24a.ino:68: undefined reference to `virtuabotixRTC::updateTime()'

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Uno.

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

Please, in the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.

if you follow instruction on youtube then follow it to the end.

#include <virtuabotixRTC.h>
// Creation of the Real Time Clock Object
virtuabotixRTC myRTC(6, 7, 8);

void setup()  {
  Serial.begin(9600);
  // Set the current date, and time in the following format:
  // seconds, minutes, hours, day of the week, day of the month, month, year
  myRTC.setDS1302Time(18, 10, 10, 7, 18, 9, 2020);
}

void loop()  {
  // This allows for the update of variables for time or accessing the individual elements.
  myRTC.updateTime();

  // Start printing elements as individuals
  Serial.print("Current Date / Time: ");
  Serial.print(myRTC.dayofmonth);
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print("  ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);

  // Delay so the program doesn't print non-stop
  delay(500);
}

It looks like you may have a .h installed for the library, but no source.

Hard to tell.

#include <RtcDS1302.h>


//virtuabotixRTC code starts here
#include "stdio.h"
#ifndef virtuabotixRTC_H                                                                                 //|
#define virtuabotixRTC_H                                                                                 //|
//|
#include <stddef.h>                                                                                      //|
#include <string.h>                                                                                    //|
//|
#if defined(ARDUINO) && ARDUINO >= 100                                                                   //|
#include "Arduino.h"                                                                                   //|
#else                                                                                                  //|
#include "WProgram.h"                                                                                //|
#include <pins_arduino.h>                                                                            //|
#endif

#define DS1302_ENABLE            0x8E                                                                    //|
#define DS1302_TRICKLE           0x90

class virtuabotixRTC  {                                                                                  //|
  public:
    virtuabotixRTC(uint8_t inSCLK, uint8_t inIO, uint8_t inC_E);
    void initRTC(uint8_t CLK, uint8_t IO, uint8_t ENABLE);     // Sets the pins and enable them          //|
    void DS1302_clock_burst_read( uint8_t *p);                 // Reads clock data, and sets pinmode     //|
    void DS1302_clock_burst_write( uint8_t *p);                // Writes clcok data, and sets pinmode    //|
    uint8_t DS1302_read(int address);                          // Reads a byte from DS1302, sets pinmode //|
    void DS1302_write( int address, uint8_t data);             // Writes a byte to DS1302, sets pinmode  //|
    void _DS1302_start( void);                                 // Function to help setup start condition //|
    void _DS1302_stop(void);                                   // Function to help stop the communication//|
    uint8_t _DS1302_toggleread( void);                         // Function to help read byte with bit    //|
    void _DS1302_togglewrite( uint8_t data, uint8_t release);  // Function to help wrtie byte with bit   //|
    void setDS1302Time(uint8_t seconds, uint8_t minutes,       // This function sets the time on the     //|
                       uint8_t hours, uint8_t dayofweek,       // DS1302                                 //|
                       uint8_t dayofmonth, uint8_t month,                                                //|
                       int year);                                                                        //|
    void updateTime();                                         // This function simply updates the time  //|
    uint8_t SCLK;                                                                                        //|
    uint8_t IO;                                                                                          //|
    uint8_t C_E;                                                                                         //|
    uint8_t seconds;                                                                                     //|
    uint8_t minutes;                                                                                     //|
    uint8_t hours;                                                                                       //|
    uint8_t dayofweek;                                                                                   //|
    uint8_t dayofmonth;                                                                                  //|
    uint8_t month;                                                                                       //|
    int year;                                                                                            //|
};
#endif

//end of virtuaboticRTC code

virtuabotixRTC myRTC(6, 7, 8); //set pins of RTC to CLK 6, IO 7, CE 8

#include <Servo.h>

Servo servo1; //define test servo

void setup() {
  Serial.begin(9600);
  servo1.attach(3); //attach servo to pin 3

  myRTC.setDS1302Time(00, 28, 21, 4, 24, 2, 2022); //set the current time
}

void loop() {
  myRTC.updateTime();

  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.print(myRTC.seconds); //prints the minutes and seconds on serial monitor for checks
  delay(5000);

  if ((myRTC.seconds) == 10);
  servo1.write(180); //when seconds hit 10 the servo moves by 180*

  if ((myRTC.seconds) == 20);
  servo1.write(0); //when seconds hit 20 the servo moves back to start position

}
#include <virtuabotixRTC.h>
virtuabotixRTC myRTC(6, 7, 8);

#include <Servo.h>

Servo servo1; //define test servo

void setup() {
  Serial.begin(9600);
  servo1.attach(3); //attach servo to pin 3

  // myRTC.setDS1302Time(00, 28, 21, 4, 24, 2, 2022); //set the current time
}

void loop() {
  myRTC.updateTime();

  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.print(myRTC.seconds); //prints the minutes and seconds on serial monitor for checks

  if ((myRTC.seconds) == 10);
  servo1.write(180); //when seconds hit 10 the servo moves by 180*

  if ((myRTC.seconds) == 20);
  servo1.write(0); //when seconds hit 20 the servo moves back to start position

  delay(5000);
}

here yor programm without unnesecery text. not forget to install the lib from github.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.