RTC & SX1509 Clock Project - Code Previously Working....Now? Kaput

Hey Guys, could use a second set of eyes to see if I've broken my code. My project is a clock (bar graph style) using a DS3231 RTC & SX1509 LED driver. Arduino is a Nano. This is my first time playing with I2C and all was working well yesterday on the breadboard. LED routines working, able to set time of day with pushbuttons, etc. Coincidence or not, things stopped working while I was "cleaning up" setup code last night.

Additional info:
Voltage levels for hardware were checked and are OK (3.3 & 5V).
Swapped Nano and no change.
Running a library-provided 'time of day' example sketch for the RTC works fine.
Running a library-provided LED flashing routine for the SX1509 works fine.
Code below omits my LED driving and such; just trying to get TOD back over serial.

If I run the code below, I get some garbage, or no response at all in the serial monitor, UNLESS I comment out Wire.begin and the Pin Definitions block. Then time of day reports properly over serial. If either are included back, things break.

Thoughts?

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <RTClib.h>
#include <Wire.h>
#include <Adafruit_I2CDevice.h>
#include <SparkFunSX1509.h>
#define DS3231_I2C_ADDRESS 0x68

const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
SX1509 io;

RTC_DS3231 rtc;
int hour;          // holds hour variable
int minn;          // holds minute variable
int minn1;         // holds truncated 1x minute
int minn2;         // holds truncated 10x minute
int sec;           // holds seconds
int j;             // used as interlock for main loop and time set
int L;             // Left switch input
int R;             // right switch input
int X = 1;         //Stores state of left switch
int Y = 0;         //Stores state of right switch
int HrSet;         //hr variable for setting routine
int TMSet;         // 10x min variable for setting routine
int MSet;          // 1x min variable for setting routine
bool bellset = 0;  //if toggled to 1, bell will sound on the hour


// Convert Decimal to BCD
byte decToBcd(byte val) {
  return ((val / 10 * 16) + (val % 10));
}
// Convert BCD to Decimal
byte bcdToDec(byte val) {
  return ((val / 16 * 10) + (val % 16));
}


void setup () {
  Wire.begin();
  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();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    // This line sets the RTC with an explicit date & time, for example to set
    // YEAR : MONTH : DAY : HOUR : MINUTE : SECOND
    rtc.adjust(DateTime(2024, 1, 1, 12, 0, 0));
  }

// Set LED clock to 500kHz (2MHz / (2^(3-1)):
  io.clock(INTERNAL_CLOCK_2MHZ, 3);

  // Pin Definitions Block
  io.pinMode(15, ANALOG_OUTPUT);  // 1x min breathable
  io.pinMode(14, ANALOG_OUTPUT);  // 10x min breathable
  io.pinMode(13, ANALOG_OUTPUT);  // Hrs breathable
  io.pinMode(10, ANALOG_OUTPUT);  // Time Digit Indicators
  io.pinMode(9, ANALOG_OUTPUT);
  io.pinMode(8, ANALOG_OUTPUT);
  io.pinMode(7, ANALOG_OUTPUT);
  io.pinMode(6, ANALOG_OUTPUT);
  io.pinMode(5, ANALOG_OUTPUT);
  io.pinMode(4, ANALOG_OUTPUT);
  io.pinMode(3, ANALOG_OUTPUT);
  io.pinMode(2, ANALOG_OUTPUT);
  io.pinMode(1, ANALOG_OUTPUT);
  pinMode(9, OUTPUT);        // BELL
  pinMode(5, INPUT_PULLUP);  // left button
  pinMode(6, INPUT_PULLUP);  // right button
  io.analogWrite(15, 0);  // Startup with all LEDs OFF
  io.analogWrite(14, 0);
  io.analogWrite(13, 0);
  io.analogWrite(10, 0);
  io.analogWrite(9, 0);
  io.analogWrite(8, 0);
  io.analogWrite(7, 0);
  io.analogWrite(6, 0);
  io.analogWrite(5, 0);
  io.analogWrite(4, 0);
  io.analogWrite(3, 0);
  io.analogWrite(2, 0);
  io.analogWrite(1, 0);
  // End of Pin Definitions Block
}

void loop () {
  DateTime now = rtc.now();
  hour = (now.hour());
  minn = (now.minute());
  sec = (now.second());
  if (hour > 12) {hour = hour - 12;}

  Serial.print(hour);
  Serial.print(':');
  if (minn < 10) Serial.print("0");
  Serial.print(minn);
  Serial.print(':');
  if (sec < 10) Serial.print("0");
  Serial.print(sec);
  Serial.println();
    
}

Post what you get as serial output as a code-section.

What do you mean with "Pin Definitions block"?

setting SX1509-io-pins as output / input?

From where do you power your LEDs / Your SX1509?

If you power them from the an Arduino-Nano pin you might have a power-problem.

Correct, setting the SX1509 IO pins. In my code I commented beginning and end of that "block" for reference.

I had initially been powering the Nano over USB, with 5V and 3.3V outputs feeding the RTC and SX. I also tried a bench supply feeding Vin, thinking sagging output could also be the issue, despite working well all day yesterday. But in both scenarios, the outputs are within 0.1V on my Fluke. The LEDs are sinking current, so anodes are fed with 5V. Still though, they work fine when running an SX example sketch.

And as for serial, I get the diamond-question mark once in a while, sometimes never: �
Looking at the serial stream with a dedicated app, I get "Ä" on power-up.
Delete Wire.begin and the pin definitions and it works fine.

EDIT: I must also "comment out" the io.clock call above the pin definitions in order for it to work.

still a lot of details missing.

Which Io-pins do you use for connecting the I2C-Bus to the SX1509?

Feeding an extra-power-supply into Vin means still powering the LEDs over the 5V-pin of the Arduino-Nano.

My guessing is it is a powering problem.

Supply the LEDs DIRECTLY from an extra 5V power-supply.

Even if you only get a single character you should post the serial output as a code-section.

Additionally I would add more serial output beginning right here

void setup () {
  Serial.begin(57600);
  Serial.println("Setup-Start");
  Wire.begin();
  Serial.println("After wire.begin");


#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();
    while (1) delay(10);
  }

  Serial.println("after if (! rtc.begin())");

  if (rtc.lostPower()) {
    // This line sets the RTC with an explicit date & time, for example to set
    // YEAR : MONTH : DAY : HOUR : MINUTE : SECOND
    rtc.adjust(DateTime(2024, 1, 1, 12, 0, 0));
  }

  Serial.println("after if (rtc.lostPower())");

// Set LED clock to 500kHz (2MHz / (2^(3-1)):

Man. debugging is not speculating for a lucky hit.
Debugging is about analysing and narrowing down.

Additionally disconnect the LEDs from power and run the code again

Are you using any type of level shifter between the Arduino and the SX1509?

Guys, appreciate the responses. Good news is things are working....

For completeness, no level shifting. SDA/SCL pins are the native A4 & A5. I attempted to power the LEDs with off board power, as well as removed. Of course, nothing in my code is calling for them to be ON, and they work just fine with an example sketch as mentioned previously.

After lots of head-scratching, I opened up an example RTC sketch, then methodically copy/pasted my code into it, programming and verifying in functional blocks as I went. When finished, I was left with identical code to my original. And guess what, it works.

All I can conclude is that one of the runtime sources linked to the original sketch must have gotten corrupted.

Feels like a cheat, but I guess I'll take the W.