Problem
I have an Arduino Uno, along with an DS3231 RTC and an SD card reader. I'm setting it up as part of a battery charge/discharge test circuit, with the RTC being used as logging information.
Running the DS3231 example code by itself works fine. However, when I implemented the example code into my battery testing program, I get strange outputs.
For instance, with the example code, I get this output on the serial monitor:
201 1 1 1 0 0 0 24h T=28.00 O-
Alarm 1: 0 Date 0 0 0
Alarm 2: 0 Date 0 0
1/1/1day of the week :1
** 0:0:1**
201 1 1 1 0 0 1 24h T=28.00 O-
Alarm 1: 0 Date 0 0 0
Alarm 2: 0 Date 0 0
** 1/1/1day of the week :1**
** 0:0:2**
201 1 1 1 0 0 2 24h T=28.00 O-
Alarm 1: 0 Date 0 0 0
Alarm 2: 0 Date 0 0
etc...
As intended. However, with the logging code, I get this output:
Initializing SD card...card initialized.
165/85/165 day of the week :165
** 25:165:165**
2.00
165/85/165 day of the week :165
** 25:165:165**
2.00
165/85/165 day of the week :165
** 25:165:165**
1.99
etc...
Note that the '1.99' and '2.00' values are the voltage read through A0. This is essentially an emulation of the battery's voltage; when it reaches certain voltages it lights up either a red or green LED. The voltage is modified using a variable resistor.
Also, note that the format is different; this is the shortened version of the time information. The same wrong numbers are present in the original expanded form.
Code
I am using this library for the DS3231.
I have included the code for the testing program and the battery program.
Already completed tests:
I have already checked to see that the DS3231 is wired correctly and it is. I've also checked to see if initializing the wire used for the voltage read causes the issue by initializing it in the original test program; this is not the case.
Moving the time code around also does nothing.
I will post the wiring if it is desired.
Finally, "setDS3231time(0,0,0,1,1,1,1);" is a holdover from a custom-made library. This is just a simple instruction that sets the DS3231 to 0 time every time it is run.
If someone could please help me with this, it would be greatly appreciated!
SuperTest.zip (2.65 KB)
BatteryProgramSuperNewClock.zip (3.6 KB)