# Will DS3231 work in Uno Rev2?

I can't find out from google and I am getting a zillion errors trying to compile it.

A DS3231 is an i2c device so it will work on any arduino. Have you tried the simple examples that come with the library?

I can't find out from google and I am getting a zillion errors trying to compile it.

We can't help with code that we can't see. Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

A photo showing your wiring is often helpful, as is a schematic.

Wiring is power SDA SCL ground as required. I hope I got the code tags right.

I was unable to include all the errors because of the 9000 byte limit. but here are some. If I tell the IDE i am using a nodemcu it doesn't get these errors which is why i doubt DS3231 will work

Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h: In member function 'void DS3231::begin()':
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:7: error: 'TWSR' was not declared in this scope
cbi(TWSR, TWPS0);
^
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:3: note: in expansion of macro 'cbi'
cbi(TWSR, TWPS0);
^~~
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:7: note: suggested alternative: 'TWI0'
cbi(TWSR, TWPS0);
^
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:3: note: in expansion of macro 'cbi'
cbi(TWSR, TWPS0);
^~~
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:13: error: 'TWPS0' was not declared in this scope
cbi(TWSR, TWPS0);
^
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:3: note: in expansion of macro 'cbi'
cbi(TWSR, TWPS0);
^~~
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:13: note: suggested alternative: 'TWI0'
cbi(TWSR, TWPS0);
^
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:3: note: in expansion of macro 'cbi'
cbi(TWSR, TWPS0);
^~~
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:13:13: error: 'TWPS1' was not declared in this scope
cbi(TWSR, TWPS1);
^
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:13:3: note: in expansion of macro 'cbi'
cbi(TWSR, TWPS1);
^~~
In file included from /Users/billbee/Documents/Arduino/libraries/DS3231/DS3231.cpp:26:0:
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:14:3: error: 'TWBR' was not declared in this scope
TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;
^~~~
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:14:3: note: suggested alternative: 'TWI0'
TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;
^~~~
TWI0
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:17:3: error: 'TWCR' was not declared in this scope
TWCR = _BV(TWEN) | _BV(TWIE)/* | _BV(TWEA)*/;
^~~~
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:17:3: note: suggested alternative: 'TWI0'
TWCR = _BV(TWEN) | _BV(TWIE)/* | _BV(TWEA)*/;
^~~~
TWI0
In file included from /Users/billbee/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
from /Users/billbee/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
from /Users/billbee/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/cores/arduino/api/String.h:31,
from /Users/billbee/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/cores/arduino/api/Print.h:24,
from /Users/billbee/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/cores/arduino/api/Stream.h:25,
from /Users/billbee/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/cores/arduino/api/Client.h:22,
from /Users/billbee/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/cores/arduino/api/ArduinoAPI.h:29,
from /Users/billbee/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/cores/arduino/Arduino.h:23,
from /Users/billbee/Documents/Arduino/libraries/DS3231/DS3231.h:26,
from /Users/billbee/Documents/Arduino/libraries/DS3231/DS3231.cpp:22:
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:17:14: error: 'TWEN' was not declared in this scope
TWCR = _BV(TWEN) | _BV(TWIE)/* | _BV(TWEA)*/;
^
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:17:14: note: suggested alternative: 'TWI0'
/Users/billbee/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:17:26: error: 'TWIE' was not declared in this scope
TWCR = _BV(TWEN) | _BV(TWIE)/* | _BV(TWEA)*/;


You forgot to post your code.

Where did you get the DS3231 library, and is it up to date? The library is trying to directly access registers in the processor, but the UNO WiFi Rev 2 is a megaAVR chip, not an AVR, so the registers are not the same.

Where did you get this DS3231 library? That is a very strange path. Most libraries will simply be under .../libraries/DS3231/DS3231.cpp without all the /hardware/avr/... subdirectories.

david_2018:
Where did you get the DS3231 library, and is it up to date? The library is trying to directly access registers in the processor, but the UNO WiFi Rev 2 is a megaAVR chip, not an AVR, so the registers are not the same.

The OP omitted the "WiFi" portion and only referred to "Uno Rev2" which I thought was the previous revision of an Uno.

If it is the WiFi board, that explains a lot.

I thought all uno rev2s were wifi. sorry. yes i want to use the wifi to get time and store it on the ds3231 as a back up if wifi dies. I can post the code but if you think it's never going to work ok.

About the libraries, boy I wish there were not so circuitous too. Why can't everything be in one place of the users choosing. I have been moving stuff to my iCloud account and still the IDE seems to find stuff everywhere especially the Arduino15 one in that hidden folder. God what a hassle.

You should be able to get it to work, just need to find a library compatible with the atmega4809 processor used in the UNO WiFi Rev 2 and Nano Every.

Incidentally, there is an internal RTC in the atmega4809, but its accuracy is limited because the board lacks a crystal clock source, and it does not appear to have a lot of support as of yet.

I keep running into these problems. None of the fine MD_ software will run on the wifi rev2 nor will fastled. I like the cheap esp8266 things, but they are 3 volt and yeah you can use a logic level gadget to change that but I want to run light strips and relays etc., wouldn't it be nice if everything worked with everything else.

Thanks to all of you for your help.

david_2018:
Incidentally, there is an internal RTC in the atmega4809, but its accuracy is limited because the board lacks a crystal clock source

The Uno WiFi Rev2 has a 32.768 kHz crystal for the RTC:

david_2018:
it does not appear to have a lot of support as of yet.

There is a fork of the Time library that supports it:

david_2018:
Where did you get the DS3231 library

My research indicates it's the "rinky-dink electronics" library:
http://www.rinkydinkelectronics.com/library.php?id=73
but we could be sure of that if @sevenoutpinball would just answer the question.

blh64:
Where did you get this DS3231 library? That is a very strange path. Most libraries will simply be under .../libraries/DS3231/DS3231.cpp without all the /hardware/avr/... subdirectories.

The library is at /Users/billbee/Documents/Arduino/libraries/DS3231, it just has some subfolders, which is no problem. The reason the library author did this is because they have architecture-specific code for ARM, AVR, and PIC32 architectures and apparently wanted to keep them well separated from each other and the rest of the code.

sevenoutpinball:
About the libraries, boy I wish there were not so circuitous too. Why can't everything be in one place of the users choosing. I have been moving stuff to my iCloud account and still the IDE seems to find stuff everywhere especially the Arduino15 one in that hidden folder. God what a hassle.

This sounds very familiar. Haven't we discussed this at length in a dedicated forum topic you made?

sevenoutpinball:
I can’t find out from google and I am getting a zillion errors trying to compile it.

You seemed to have managed to the worst DS3231 library for the Uno WiFi Rev2. I just compiled every DS3231 library in the Arduino Library Manager for the Uno WiFi Rev2 and they all worked. The only semi-exception is the MD_DS3231 library due to a name conflict. They are aware of the issue and have made the library configurable to avoid the conflict:

/**
* \def ENABLE_RTC_INSTANCE
* Set to 1 (default) to create a default instance when the library is included.
* It can be useful if you want to extend the MD_DS3231 class without wasting
* space (around 60 bytes) because of a variable declaration you do not use.
*
* You can change the default by editing this file directly or using a command
* line tool like sed :
* sed "s/^#define ENABLE_RTC_INSTANCE 1/#define ENABLE_RTC_INSTANCE 0/" -i MD_DS3231.h
*
* \sa setCentury() method.
*
*/
#define ENABLE_RTC_INSTANCE 1 ///< Enable default RTC instance creation


I wasn’t able to actually test these libraries on the board because I don’t happen to own a DS3231, but I think you’ll find that at least one of them will work fine for you if you decide to stick with the DS3231.

sevenoutpinball:
nor will fastled

It sounds like there is some level of support possible with some minor modifications to the library described here:

pert:
This sounds very familiar. Haven't we discussed this at length in a dedicated forum topic you made?

yes, but I still have not read any plan to make a one library only arduino system. When I look up one of these .h files to see what is in it, I have as many as 15 choices. good luck figuring out which is the correct one to look at.

Even if I could collect them all in one directory, other stuff will come along and start populating directories that it creates etc. You would have to have a sweeper program to find anything arduino related and move it to the one directory that you want.

PERT: program evaluation review technique as i recall. Do they still use that?

 * \def ENABLE_RTC_INSTANCE
* Set to 1 (default) to create a default instance when the library is included.
* It can be useful if you want to extend the MD_DS3231 class without wasting
* space (around 60 bytes) because of a variable declaration you do not use.
*
* You can change the default by editing this file directly or using a command
* line tool like sed :
* sed "s/^#define ENABLE_RTC_INSTANCE 1/#define ENABLE_RTC_INSTANCE 0/" -i MD_DS3231.h
*
* \sa setCentury() method.
*
*/
#define ENABLE_RTC_INSTANCE 1 ///< Enable default RTC instance creation


I don’t know what the command line tool sed is but I tried compiling with a 1 and with a 0 and neither worked.

'

 Users/billbee/Documents/Arduino/libraries/MD_DS3231/src/MD_DS3231.h:763:18: error: expected ')' before '*' token
/var/folders/4b/sjd5y8t54zxdzx1q5vrk8lwm0000gn/T/arduino_modified_sketch_911912/MD_DS3231_LCD_Time.ino: In function 'void printTime()':
MD_DS3231_LCD_Time:59:28: error: 'RTC_t {aka struct RTC_struct}' has no member named 'dow'
lcd.print(dow2String(RTC.dow));
^~~
MD_DS3231_LCD_Time:61:17: error: 'RTC_t {aka struct RTC_struct}' has no member named 'yyyy'
lcd.print(RTC.yyyy);
^~~~
MD_DS3231_LCD_Time:63:13: error: 'RTC_t {aka struct RTC_struct}' has no member named 'mm'
p2dig(RTC.mm);
^~
MD_DS3231_LCD_Time:65:13: error: 'RTC_t {aka struct RTC_struct}' has no member named 'dd'
p2dig(RTC.dd);
^~
MD_DS3231_LCD_Time:68:13: error: 'RTC_t {aka struct RTC_struct}' has no member named 'h'
p2dig(RTC.h);
^
MD_DS3231_LCD_Time:70:13: error: 'RTC_t {aka struct RTC_struct}' has no member named 'm'
p2dig(RTC.m);
^
MD_DS3231_LCD_Time:72:13: error: 'RTC_t {aka struct RTC_struct}' has no member named 's'
p2dig(RTC.s);
^
MD_DS3231_LCD_Time:73:11: error: 'RTC_t {aka struct RTC_struct}' has no member named 'status'
if (RTC.status(DS3231_12H) == DS3231_ON)
^~~~~~
MD_DS3231_LCD_Time:74:19: error: 'RTC_t {aka struct RTC_struct}' has no member named 'pm'
lcd.print(RTC.pm ? " pm" : " am");
^~
/var/folders/4b/sjd5y8t54zxdzx1q5vrk8lwm0000gn/T/arduino_modified_sketch_911912/MD_DS3231_LCD_Time.ino: In function 'void displayUpdate()':
MD_DS3231_LCD_Time:80:7: error: 'RTC_t {aka struct RTC_struct}' has no member named 'readTime'
^~~~~~~~
/var/folders/4b/sjd5y8t54zxdzx1q5vrk8lwm0000gn/T/arduino_modified_sketch_911912/MD_DS3231_LCD_Time.ino: In function 'void setup()':
MD_DS3231_LCD_Time:104:7: error: 'RTC_t {aka struct RTC_struct}' has no member named 'setAlarm1Callback'
RTC.setAlarm1Callback(alarmICB);
^~~~~~~~~~~~~~~~~
MD_DS3231_LCD_Time:119:7: error: 'RTC_t {aka struct RTC_struct}' has no member named 'setAlarm1Type'
RTC.setAlarm1Type(DS3231_ALM_SEC);
^~~~~~~~~~~~~
/var/folders/4b/sjd5y8t54zxdzx1q5vrk8lwm0000gn/T/arduino_modified_sketch_911912/MD_DS3231_LCD_Time.ino: In function 'void loop()':
MD_DS3231_LCD_Time:128:7: error: 'RTC_t {aka struct RTC_struct}' has no member named 'checkAlarm1'
RTC.checkAlarm1();
^~~~~~~~~~~
Using library LiquidCrystal at version 1.0.7 in folder: /Users/billbee/Desktop/Arduino.app/Contents/Java/libraries/LiquidCrystal
Using library MD_DS3231 at version 1.3.1 in folder: /Users/billbee/Documents/Arduino/libraries/MD_DS3231
Using library Wire at version 1.0 in folder: /Users/billbee/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/libraries/Wire
exit status 1
'RTC_t {aka struct RTC_struct}' has no member named 'dow


sevenoutpinball:
When I look up one of these .h files to see what is in it, I have as many as 15 choices. good luck figuring out which is the correct one to look at.

Enable "Show verbose output during > compilation" in File > Preferences, then check the contents of the black console pane at the bottom of the Arduino IDE window and it will tell you which library was used and its location.

I'm happy to provide more assistance on that subject. We can continue the discussion on the dedicated forum thread. If I miss it, you can PM me with a reminder.

sevenoutpinball:
PERT: program evaluation review technique as i recall. Do they still use that?

I had never heard of it before now. My first name is Per and my last name starts with a "T", thus my dumb user name. "per" was already taken, so I threw on the "t" and that worked. If I had known I would be using it so much, I would have put more thought into it. I think I originally created it just so I could fix some error in the now dead Arduino Playground wiki, with no intention of ever posting on the Arduino forum. So much for that! I don't seem to be very good at clever user names. When I signed up for GitHub, "pert" was also taken, so I ended up with the even more idiotic user name "per1234". The one good thing about that user name is it's proof I can count to 4, which is a reasonable indicator of my abilities in technical matters.