Suspected DS3231.h library clash problem?

Good day,

I would like to ask for some guidance, please.

I have a setup. When loading the code for each component separately, they work fine (independently). However, I tried to combine the three codes together (WIP) which produces the following error:

C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1206:11: warning: extra tokens at end of #endif directive [-Wendif-labels]
     #endif;
           ^
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp: In member function 'char* DS3231::dateFormat(const char*, RTCDateTime)':
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:173:10: warning: address of local variable 'buffer' returned [-Wreturn-local-addr]
     char buffer[255];
          ^~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp: In member function 'char* DS3231::dateFormat(const char*, RTCAlarmTime)':
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:301:10: warning: address of local variable 'buffer' returned [-Wreturn-local-addr]
     char buffer[255];
          ^~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp: In member function 'char* DS3231::strDayOfWeek(uint8_t)':
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:960:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "Monday";
                    ^~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:963:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "Tuesday";
                    ^~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:966:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "Wednesday";
                    ^~~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:969:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "Thursday";
                    ^~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:972:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "Friday";
                    ^~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:975:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "Saturday";
                    ^~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:978:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "Sunday";
                    ^~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:981:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "Unknown";
                    ^~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp: In member function 'char* DS3231::strMonth(uint8_t)':
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:989:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "January";
                    ^~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:992:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "February";
                    ^~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:995:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "March";
                    ^~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:998:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "April";
                    ^~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1001:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "May";
                    ^~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1004:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "June";
                    ^~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1007:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "July";
                    ^~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1010:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "August";
                    ^~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1013:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "September";
                    ^~~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1016:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "October";
                    ^~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1019:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "November";
                    ^~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1022:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "December";
                    ^~~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1025:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "Unknown";
                    ^~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp: In member function 'char* DS3231::strAmPm(uint8_t, bool)':
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1035:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "AM";
                    ^~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1038:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "am";
                    ^~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1044:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "PM";
                    ^~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1047:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             return "pm";
                    ^~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp: In member function 'char* DS3231::strDaySufix(uint8_t)':
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1056:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
         return "st";
                ^~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1060:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
         return "nd";
                ^~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1064:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
         return "rd";
                ^~~~
C:\Program Files (x86)\Arduino\libraries\DS3231\DS3231.cpp:1067:12: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
     return "th";
            ^~~~
Sketch uses 5520 bytes (17%) of program storage space. Maximum is 32256 bytes.
Global variables use 490 bytes (23%) of dynamic memory, leaving 1558 bytes for local variables. Maximum is 2048 bytes.

The upload still completes, but the components do not function.

Here is the code:

// CLOCK
    // SEMI-FINAL_RTC Clock. WORKS WHEN SECONDARY ARDUINO SDA/SCL NOT CONNECTED, OR SDA/SCL CONNECTED WITH POWER.
    // DOES NOT WORK WHEN SDA/SCL FROM SECONDARY ARDUINO CONNECTED WITHOUT POWER TO SECOND ARDUINO.

//////////////////////////////////////////// HEADERS ///////////////////////////////////////////////////////////
#include <Wire.h>           // CLOCK 
#include <DS3231.h>         // CLOCK 
#include <LiquidCrystal.h>  // LCD 

//////////////////////////////////////// GLOBAL VARIABLES ///////////////////////////////////////////////////////////
// CLOCK 
 DS3231 clock;
 RTCDateTime dt;
// PIR 
int pirLED = 13; 
int pirPin = 2;  
int pirValue;
// LCD
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // initialize the library with the numbers of the interface pins


void setup()
{
    // PIR 
    pinMode(pirLED, OUTPUT); // only required if 13
    pinMode(pirPin, INPUT);
    digitalWrite(pirLED, LOW);
    Serial.begin(9600);

    // CLOCK
     Serial.println("Initialize RTC module");      
     clock.begin();                                // Initialize DS3231

    // LCD
    lcd.begin(16, 2);                               // LCD: set up the LCDs number of columns and rows:
    lcd.print("Hello, World!");                     // Print a message to the LCD.  
}

void loop()
{
    int time = getTime();           // CLOCK Time in seconds (can change using function below)
    checkPir();                     // PIR
    setLCD();
}


// CLOCK
int getTime()
{
    dt = clock.getDateTime();

  // For leading zero look to DS3231_dateformat example
    delay(1000);
    Serial.println(dt.second);           // CLOCK
    return (dt.second);
}


void checkPir()
{   
    pirValue = digitalRead(pirPin);
    digitalWrite(pirLED, pirValue);

    if (pirValue == 1)
        Serial.println(pirValue);
    else if (pirValue == 0)
        Serial.println(pirValue);
    else 
        Serial.println("No reading");
    delay(200);
}

void setLCD()
{
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    //lcd.print("Hello, World!");
    lcd.setCursor(0, 1);
    // print the number of seconds since reset:
    lcd.print(millis() / 1000);
}    

Here is a sketch of my setup (the second Arduino and its connections are currently not connected) and the components not mentioned in the code are not of importance/in-use for now:

I looked at the forums for similar problems, and I found this link:

which gave direction, but is not exactly the same. I took a quick look at the DS3231.cpp and DS3231.h files and found the references to char, but wasn't sure how to find the string relevant part or how to correct it. Also, I don't know if this is actually the problem, otherwise what I am actually looking for? I'm significantly out of my depth here - any assistance would be highly appreciated.

The error message literally pointed directly at the problem, and described it.

The tokens? I don't know what these are. Should I google how to get rid of extra tokens?

Or are you referring to ISO forbidding the conversion from strings to chars? If so, should I change
DS3231::dateFormat(const char*, RTCAlarmTime)':
to
DS3231::dateFormat(const String*, RTCAlarmTime)':

or maybe:
DS3231::strDayOfWeek(uint8_t)
to a string somehow?

Please be understanding that I am not familiar with C++ at that depth. I am out of my depth here and don't understand the provided header code properly. I would not know what to change and am rather hesitant to just go changing things in well-defined provided header files that I don't fully understand, without guidance. It is hopefully not necessary to tell me exactly what to do, but as mentioned, some guidance/assurance would be appreciated.

Hi @csfitzgerald
What are you using? Arduino uno, mega......?
Which release of your <DS3231.h> library?
I have compiled your code here with the arduino mini, and it didn't fail.
RV mineirin

1 Like

As @anon73444976 says, the compiler literally pointed to the problem. You should not have a ";" at the end of #endif.

Hi @ruilviana, thank you for your response.

I am using an Uno.

The library version for the DS3231 is v1.0.7.

That is very interesting. I thought it was strange that it worked on yours and not mine, so I restarted my computer. Now it seems to work! I updated VSCode a shortwhile before, maybe that changed something somehow?

I restarted my computer and tried to load it. The first time after restart it threw the same error, but then I reloaded it again and now it seems to work (for now)! I find that strange though that it threw the same error the first time after restart before working again now.

I'm concerned that the error comes back. It would be nice to know a long term solution to the issue if it is not solely related to the restart?

Okay, thank you @markd833. Now that you point it out it makes sense. Why would they refer to it as a token and not a "semi-colon" or a "character"? I just assumed that a token was some complex coding structure that I would not know. Also, the error is so incredibly long I did not know what exactly to focus on.

Its interesting then, that the code didn't work first time trying to load after restart, but then worked the second time.

Regardless, I will make the change to the header file and inform the original coder of the library.

Thank you and kind regards,
Connor

That link has nothing to do with your problem :wink: The problem in that thread was (.text+0x0): multiple definition of __vector_7'`

1 Like

@sterretje Your solution to that post had to do with a component header file and timing, and mine has to do with a component header file and a clock. Haha :stuck_out_tongue:

1 Like

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