RTC declaration fails with strange error

I have been trying to develop code to run on an UNO with Wifi from jaycar.
Having continually run out of space, I switched to an Arduino UNO WiFi Rev2 from Core.
I have reduced my code to just a few lines:

#include <Wire.h>
#include <RTClib.h>

// Real-time clock object

void setup () { }

void loop() { }

... and I get this error when I try to compile:

expected ')' before '*' token

Have I missed something when switching boards? I have changed the board setting in Tools and have checked the WiFiNINA library (it is at 1.8.13).

I can remember seeing this error once before but I can not remember where. It is possible it was when I first plugged in the new board when it arrived a few weeks back.

A small snippet I should have mentioned. When the compile error occurs the RTC_DS1307 RTC; line is highlighted in pink so I assume that is the source of the problem.

1 Like

The code you have posted won’t create a compile error, so the problem is in one of the libraries. Firstly, check exactly where the referenced libraries are being loaded from, using the compile log that is displayed. Then load that library into the IDE and try the compile again. The error line should then be highlighted.

If that doesn’t identify the problem look into the libraries that are loaded by default - in particular, the library that gets loaded for the board that you have selected in Tools \ Board.

1 Like

The error is probably in a ifdef segment that varies according the board type.

1 Like

Hi Jeff. Thanks for your quick response.
Please help me understand what you mean by: “Then load that library into the IDE and try the compile again”. Do you mean to replace the #include line with all of the code in the referenced file.
Also - FYI - I am sure you are right. The Wire.h file appears in a long and complex path in my \AppData\Local\Arduino15… area whereas the RTClib.h file appears in a sub-directory just below where I was storing my working sketches.

1 Like

Find the library file. There will likely be two for each library - a .cpp and a .h. One of them you have already located. The other should not be particularly complicated - something like My Documents\Arduino\Libraries\RTC_DS1307\RTC_DS1307.h and .cpp, It is important to use the one listed in the compile log, because if there are several it is possible to be working with the wrong one which can waste a lot of time. Just because there is one in the sketch folder doesn’t mean that is the one being used - the IDE has very complex rules about how how it finds libraries. Start with the .h as that will most likely be where the problem is.

When you have the library, select Sketch \ Add file, navigate to the library location, and add it. It will appear in a new tab. If you have to make changes check very carefully which copy is being changed and which copy is being used for the compile. You may have to use Sketch \ Include Library, and include the library (even if it’s already listed in the code) in order to force the IDE to use the one you are working with.


Thanks again Jeff.

I have included RTClib.h, RTClib.cpp, Wire.h and Wire.cpp in the ide.

As far as I can tell from any information on the web, RTClib release version 1.14.1 is meant to work with all boards. I can not find any version of these files anywhere except on my PC C:\Users\Brian\Documents\Arduino\libraries\RTClib\src.

Wire is still at version 1.0 and I can find no info on web that suggests it has ever changed. However, the two file sets under C:\User…\AppData\Local…\avr\1.8.3 and …\megaavr\1.8.7 are markedly different in size but as the compiler has chosen the …megaavr\1.8.7 path I assume that relates to the UNO Wifi Rev2 board (MEGA4809).

Whenever I compile, the error is exactly the same and the highlighted line is in my sketch rather than anywhere else.

Is it possible the board is faulty.

I have compiled dozens of version during the development phase for the Jaycar board and a Wemoss board before that and have never seen this error (Except for one glimpse a few weeks ago which was probably the MEGA board).


What a stupid question !!
It’s happening within the IDE not the board.
Still baffled.


The compiler doesn’t know anything about the board that is actually connected to the machine until the compile is complete, and when it tries to upload. An error at that point would indicate a problem with the bootloader, not an error in the code. So it is unlikely that a faulty board would cause the problem.

If you change the board setting (the board that is connected doesn’t matter) can you get a clean compile? If so then that confirms what I thought - there is some code that is only included in the library for a particular type of board and it has an error - probably a simple syntax error such as a missing bracket. In that case you would need to identify the code path that is different for that board, based on the board type and the various ifdefs that are involved.


Hi again Jeff (or any other interested parties). Jeff - looks like you had started typing your response before I sent an extra message about the stupidity of my board question - sorry to waste your time.

First libraries:
This is the library list when I set the board to “Arduino UNO WiFi Rev2”:

Using library Wire at version 1.0 in folder: C:\Users\Brian\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\libraries\Wire 
Using library RTClib at version 1.14.1 in folder: C:\Users\brian\Documents\Arduino\libraries\RTClib 
Using library SoftwareSerial at version 1.0 in folder: C:\Users\Brian\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\libraries\SoftwareSerial 
Using library SPI at version 1.0 in folder: C:\Users\Brian\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\libraries\SPI 
Using library SD at version 1.2.4 in folder: C:\Program Files (x86)\Arduino\libraries\SD 

When I compile for Arduino UNO WiFi (successfully), the three that appear in the … megaavr\1.8.7… path are also in the list except they are in the … avr\1.8.3… path. The RTCLib and SD are unchanged.

If I try to compile with the RTC declaration line included in the sketch, I get the error in my first note: “expected ‘)’ before ‘*’ token” with the declaration line highlighted.

If I comment out the declaration line, I then get a number of errors in the log but the IDE seems to conclude it was successfully compiled.

The errors point to the following:
it seems this function in RTClib.cpp is one end of the problem:

static uint8_t read_i2c_register(uint8_t addr, uint8_t reg,
                                 TwoWire *wireInstance) {

  wireInstance->requestFrom(addr, (byte)1);
  return wireInstance->_I2C_READ();


The 1.8.3 version of Wire.h has these five varieties of “requestFrom”:

    uint8_t requestFrom(uint8_t, uint8_t);
    uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
    uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
    uint8_t requestFrom(int, int);
    uint8_t requestFrom(int, int, int);

… and the 1.8.7 only has 4 and several instances of the data type uint8_t have been replaced with size_t.

Any thoughts. I am struggling here. I can upload logs or anything else if someone needs more detail to be able to assist.


Sorry. Should have included the 1.8.7 varieties of “requestFrom”

    size_t requestFrom(uint8_t, size_t);
    size_t requestFrom(uint8_t, size_t, bool);
    size_t requestFrom(int, int);
    size_t requestFrom(int, int, int);
1 Like

Hi Brian,

I know this doesn’t solve your problem, and I’m still looking into it (just a bit stumped) but apparently the Uno Wifi Rev 2 has an internal RTC, which can conflict according to this thread:

Have a quick read and determine if it relates to the library you are using, if not, try and look into the inbuilt RTC.

Keen to see this working!

1 Like

I have 1.8.7 installed so I should be able to select UNO WiFi Rev2 and see if I can get the error, even without a board connected. So far no joy, but I will keep looking.

There is a size incompatibility between the function call and the function definiton, but as a byte will always be promoted to a size_t (the size_t is bigger) then it should not be a problem.


The basic problem is that the RTC library duplicates a lot of stuff already in the 4809 board definitions. The specific problem is that the variable ‘RTC’ is already defined. Change that variable to something else, and the error messages make a lot more sense.

I can’t try that code, but it seems that since all the required definitions are already there, the library you want is:
GitHub - goodchip/Time: Time library for Arduino
“Use Internal RTC circuit of ATMEL MegaAVR 0 series (ex: Arduino Uno WiFi rev 2) for clocking (if detected).”


Thanks Jeff. I got part of the way there with my own research. Downloaded the Time-master library earlier today. Haven’t tested all functions yet but progress so far is good.


Thank you Jeff and James.
I have got this project up and running and will post some more details soon.
Built-in clock on UNO WiFi Rev 2 works fine. I re-sync it from the PC periodically and I only see corrections of one second occasionally - much the same as I was seeing with DS1307.
The other challenge I had was the SD card. I was dumbfounded to learn that pins 11, 12 & 13 are not available for use by an SD card shield as they are on standard UNO boards. I had already bought the shield and also cut a hole in the case through which to replace the card. (It carries config for WiFi and PC so I wanted to be able to replace it without having to unscrew the lid).
I cut these three pins off the bottom of the shield and then (being a woodworker) used a band-saw to cut a space in the shield over the top of the ICSP header and then ran wires to connect from the ISCP header pins to the sockets at 11,12 & 13 on top of the shield board and it worked perfectly. (I may have been able to buy socket/pin combos to avoid cutting the board but I couldn’t see any online with long enough pins).


Hi Brian,

I don’t think I’ve heard of someone sawing into a board like this, but if you didn’t cut any traces, I don’t see why not!

Any chance you feel like posting a picture of what you’ve got so far? I’d be interested to see what it looks like…



Hi James.
I will be at the club tomorrow so will take the lid of the box and take a picture.
The shield is one with an SD slot and an RTC near the connection end of the board. Then from about half way to the other end through to the end, there is a matrix of holes that are not connected to each other and are not connected to anything else so I though it was pretty safe to cut a hole and - being in the middle sideways - I was well away from any traces that may have been running down the sides of the board. I would not dream of doing so on a more complex board.


Hi James.

Exterior view. Nitrile glove is to keep dust out of box - particularly the SD card socket.

Interior view. Shows cut-out in shield to connect ICSP header to pins 11, 12 & 13 on top of shield. Related pins below have been cut off.


Hey Brian,

That should be fine, a creative solution to get access to that ICSP header on the Uno below rather than running some connections soldered to the board through the bottom of it which is the trick that is usually used here. Make sure to let us know if you have any questions in regards to setting up your project. All the best with it!

1 Like