PCF8523 Stemma/QT doesn't work with Feather ESP32 v2 out of the box

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
emmby
 
Posts: 5
Joined: Sun Feb 05, 2023 8:49 pm

PCF8523 Stemma/QT doesn't work with Feather ESP32 v2 out of the box

Post by emmby »

I'm trying to get the PCF8523 working. I've got a pretty simple setup:
Code:
  • Adafruit RTClib example for PCF8523, Examples->RTClib->pcf8523
  • Adafruit v2.1.1 fork of RTClib
When I compile the example code and run it, the PCF8523 breakout powers up and the green LED turns on, but I just see "Couldn't find RTC" in the serial output. I've tried two different feathers, two different usb cables, two different computers. Just one PCF8523 though since I only have one, although I did try using the other QT connector on the board.

I suspect the problem may be related to the re-numbering of the I2C pins in the Feather ESP32 v2, but I don't know for sure. Where are the pins configured?

User avatar
emmby
 
Posts: 5
Joined: Sun Feb 05, 2023 8:49 pm

Re: PCF8523 Stemma/QT doesn't work with Feather ESP32 v2 out of the box

Post by emmby »

Actually, just seems to be a startup race condition.

I changed the example from:

Code: Select all

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);
  }
(what is that infinite while loop for, anyway?)

to

Code: Select all

  bool begin;
  do {
    begin = rtc.begin();
    Serial.printf("RTC begin=%d\n",begin);
    Serial.flush();
    delay(10);  
  } while(!begin);
and it now finds the RTC by the second iteration.

Are the examples hosted on github somewhere? I'd be happy to submit a PR if people think this change is valuable.

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: PCF8523 Stemma/QT doesn't work with Feather ESP32 v2 out of the box

Post by adafruit_support_carter »

Yep, examples are hosted with the library:
https://github.com/adafruit/RTClib

Here's the PCF8523 example:
https://github.com/adafruit/RTClib/blob ... cf8523.ino

The infinite loop is to stop things if the PCF8523 does not initialize, i.e. the call to begin() fails. In general, begin() should only be called once. It's working with your looping call, but sort of a hack.

If it's a power on race condition, try adding a delay before that code block:

Code: Select all

  delay(500);  // POR delay
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);
  }

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”