0

This is my first time here and I hope someone can be of help! I'll try to keep it as concise as possible.

So I have two sensors/modules, 1 is an LCD screen from elecrow and another is the DS1307. Both are connected through analog 4 and 5. I tried hooking them up with the help of my breadboard but I've stumbled upon the following issue with the libraries (I don't even know if what I'm trying to achieve is possible but I'm trying nevertheless(and failing horribly while at it))

In file included from C:\Users\c\Documents\Arduino\Sketches\IC2_Checker\BME280_LCD_Time\BME280_LCD_Time.ino:22:0:

    C:\Users\c\Documents\Arduino\libraries\RTClib/RTClib.h:79:31: error: redeclaration of 'OFF'

     enum Ds1307SqwPinMode { OFF = 0x00, ON = 0x80, SquareWave1HZ = 0x10, SquareWave4kHz = 0x11, SquareWave8kHz = 0x12, SquareWave32kHz = 0x13 };

                                   ^ 
In file included from C:\Users\c\Documents\Arduino\Sketches\IC2_Checker\BME280_LCD_Time\BME280_LCD_Time.ino:21:0:

    C:\Users\c\Documents\Arduino\libraries\I2C_LCD/I2C_LCD.h:457:5: note: previous declaration 'LCD_SwitchState OFF'    
         OFF=0x00,

         ^    
    In file included from C:\Users\c\Documents\Arduino\Sketches\IC2_Checker\BME280_LCD_Time\BME280_LCD_Time.ino:22:0:

    C:\Users\c\Documents\Arduino\libraries\RTClib/RTClib.h:79:42: error: redeclaration of 'ON'

     enum Ds1307SqwPinMode { OFF = 0x00, ON = 0x80, SquareWave1HZ = 0x10, SquareWave4kHz = 0x11, SquareWave8kHz = 0x12, SquareWave32kHz = 0x13 };

                                              ^
In file included from C:\Users\c\Documents\Arduino\Sketches\IC2_Checker\BME280_LCD_Time\BME280_LCD_Time.ino:21:0:

    C:\Users\c\Documents\Arduino\libraries\I2C_LCD/I2C_LCD.h:458:5: note: previous declaration 'LCD_SwitchState ON'

         ON=0x01

         ^

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

What I make out of this, is that the libraries are conflicting with each other on the following:

  • OFF = 0x00
  • ON = 0x80
  • ON= 0x01

Is there anyway to fix this? I know that I have to edit the .h libraries but I don't know what to change and to what it should be changed, here's the library code on the module itself:

// RTC based on the DS1307 chip connected via I2C and the Wire library
enum Ds1307SqwPinMode { OFF = 0x00, ON = 0x80, SquareWave1HZ = 0x10, SquareWave4kHz = 0x11, SquareWave8kHz = 0x12, SquareWave32kHz = 0x13 };

class RTC_DS1307 {
public:
   boolean begin(void);
   static void adjust(const DateTime& dt);
   uint8_t isrunning(void);
   static DateTime now();
   static Ds1307SqwPinMode readSqwPinMode();
   static void writeSqwPinMode(Ds1307SqwPinMode mode);
   uint8_t readnvram(uint8_t address);
   void readnvram(uint8_t* buf, uint8_t size, uint8_t address);
   void writenvram(uint8_t address, uint8_t data);
   void writenvram(uint8_t address, uint8_t* buf, uint8_t size);
};

Thank you for your help!

C.C

EDIT: I think that I might have come a bit closer. I tried implementing one of the answers and that made me get the following error:

    C:\Users\c\Documents\Arduino\libraries\RTClib\RTClib.cpp:284:1: error: 'Ds1307SqwPinMode' does not name a type

 Ds1307SqwPinMode RTC_DS1307::readSqwPinMode() {

 ^

exit status 1
Error compiling for board Arduino/Genuino Uno.

That's a whole lot less than before. I will keep this updated!

EDIT 2:

Meanwhile, I tried something entirely else like changing the name of OFF and ON Throughout the RTClib concerning only the DS1307 module. That however gives me an entirely new line of errors such as:

error: 'enum Ds1307SqwPinMode' is not a class or a namespace

  RTC_DS1307 Ds1307SqwPinMode::readSqwPinMode() {

                                              ^

and:

error: could not convert '(Ds1307SqwPinMode)mode' from 'Ds1307SqwPinMode' to 'RTC_DS1307'

   return static_cast<Ds1307SqwPinMode>(mode);

                                            ^

These errors in particular only take place in the .cpp library This is where I am stuck now at the moment

  • Hint#1: You could for instance move the enum into the context of the class (and reduce the enum name, Ds1307SqwPinMode => SqwPinMode). – Mikael Patel Feb 10 at 12:20
  • @MikaelPatel as example: "DS1307PinMode" ? – CCG Feb 10 at 12:21
  • Hint#2: Why are some member functions "static" and others not? – Mikael Patel Feb 10 at 12:25
  • @MikaelPatel if only I knew, I haven't made this library myself, this is why it's so unnerving for me as well, especially since I'm a beginner with the Arduino. The manufacturer of the code elecrow is responsible for this, I've sent them a message that there's something wrong. Now I'm waiting for a reply.. I will try to implement your solution in the meanwhile, thanks! – CCG Feb 10 at 12:28
  • Hint#3: Uppercase-only symbols are traditionally used for defines (preprocessor symbols, macros, etc) in C/C++. – Mikael Patel Feb 10 at 12:30
0

A general rule is to keep definitions such as enum's within the context of the class (library). Below is a possible refactoring:

class RTC_DS1307 {
public:
   enum SqwPinMode { OFF = 0x00, ON = 0x80, SquareWave1HZ = 0x10, SquareWave4kHz = 0x11, SquareWave8kHz = 0x12, SquareWave32kHz = 0x13 };

   ...
   static SqwPinMode readSqwPinMode();
   static void writeSqwPinMode(SqwPinMode mode);
   ...
};

Cheers!

  • This sure did something! Seems like I have to dig a bit in to the .cpp now! I will try to mess around a bit! Thanks! – CCG Feb 10 at 12:36
  • So I tried some things such as changing the name RTC_DS1307 Ds1307SqwPinMode::readSqwPinMode() { but all that does is give me 'Ds1307SqwPinMode' has not been declared. I'm stuped on this one – CCG Feb 10 at 14:29
  • @CCG Do not forget to accept the answer. – Mikael Patel Feb 10 at 15:45
  • check my upcoming edit! – CCG Feb 10 at 15:51
0

FINAL EDIT WITH SOLUTION:

I finally stumbled upon the last wall of issues before getting it to work,

  1. I redownloaded all the libraries
  2. Went to the .h library file of RTClib
  3. Changed the variable names from OFF to OFF and on to ONN (it's stupid I know but bear with me)
  4. Encounter an entirely new error which seemingly occurs at board version 1.6.23

Error:

In function 'global constructors keyed to BME280_LCD_TIME.o':

lto1.exe: internal compiler error: Segmentation fault

Please submit a full bug report,

with preprocessed source if appropriate.

See http://gcc.gnu.org/bugs.html for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.15.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1 Error compiling for board Arduino/Genuino Uno.

  1. Go to Tools > Board > Boards manager
  2. I personally had to change "Arduino AVR Boards by Arduino version 1.6.23" to version 1.6.21
  3. Compile the code And that should do the trick!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.