No output in Serial Monitor for example program: ds3231 date and time functions

Here is the original repo: https://github.com/adafruit/RTClib/blob/master/examples/ds3231/ds3231.ino

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include "RTClib.h"

RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
  Serial.begin(57600);

#ifndef ESP8266
  while (!Serial); // wait for serial port to connect. Needed for native USB
#endif

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  // When time needs to be re-set on a previously configured device, the
  // following line sets the RTC to the date & time this sketch was compiled
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // January 21, 2014 at 3am you would call:
  // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}

void loop () {
    DateTime now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");

    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));

    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();

    Serial.print("Temperature: ");
    Serial.print(rtc.getTemperature());
    Serial.println(" C");

    Serial.println();
    delay(3000);
}

Serial monitor set to 9600 baud. RTC connected to Arduino Mega: gnd-gnd, aref-Vcc, sda-sda and scl-scl. Red LED on RTC is fluctuating (not a constant).

So I unplug the RTC and plug it back in: The first time, the Serial Monitor says "Couldn't find RTC". This makes sense. How do I know if the RTC is set to the right time though?

Arduino Mega pinout: https://static-assets.imageservice.cloud/2762945/arduino-mega-2560-pinout-arduino-projects-in-2019-arduino.png

  Serial.begin(57600);

Serial monitor set to 9600 baud.

Oh, the program I have from the example file loaded on my computer has 9600 baud.

UKHeliBob:  Serial.begin(57600);

So I just copy/pasted the github version, and switched to 57600 and still no Serial Monitor output.

So please post the github version

So, just to clear, you now have

Serial.begin(57600);

in the code and the Serial monitor is set to 57600 baud

Which Arduino board are you using ?

Print a message from setup(). Is it visible ?

Try this

Serial.begin(57600);
while(!Serial);  //wait for the Serial object to become available
Serial.println("Now in setup()");

Red LED on RTC is fluctuating (not a constant).

Unless you have an unusual module, this is a bad sign. The led is a power indicator and not a communication indicator. It should be steadily illuminated.

the Serial Monitor says “Couldn’t find RTC”.

Another bad sign.

Try running this sketch, and see if the RTC is seen on the i2c bus. What addresses does it report.

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

To be clear, yes I have that now.

Still using the Arduino Mega 2560.


I tried running the I2C Scanner, but it's running on the I2C. So it just prints, "I2C scanner. Scanning ..." until the DS3231 RTC is removed.

Mega pinouts: gnd-gnd, aref-Vcc, sda-sda and scl-scl. Red LED on RTC goes off.

aref-Vcc

?

Aref of the Mega shouldn't be connected to anything, and certainly shouldn't be used to power external modules. Better upload a picture of the setup (as requested in the "how to post" guide).

You did of course use pin 20,21 or the pins by the USB socket for I2C, not pin A4,A5. Leo..

aref-Vcc

Connect Vcc to 5V.

Wawa: aref-Vcc

?

Aref of the Mega shouldn't be connected to anything, and certainly shouldn't be used to power external modules.

That was it. Thanks a bunch everyone! (I think I looked this up before and came to the incorrect conclusion that using Aref as power works. Now is the time to resolder a Vcc pin...either 3v3 or 5V...)