Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KC868-A6 DS1307 Issue
#16
(10-23-2022, 06:50 AM)Senapsys Wrote: Hi there

I'm having an issue with getting the KC868-A6 RTC working.

I've taken the example code in the A6 thread as per below, and it returns an error of "Couldn't find RTC".

I've made sure that the I2C SDA and SCL pins are set correctly in the NodeMCU-32S config file.

The RTClib I've used is the Adafruit library below:
https://github.com/adafruit/RTClib

The battery has been installed into the socket on the board.  I've successfully coded up things so that the PCF8574 outputs and inputs to work so I know that the I2C SDA and SCL are working.

The comments in the example code mention the Wire lib, so I've tried including this as well, but it didn't fix the problem.

Any thoughts would be appreciated.


/*KC868-A6 DS1307 CODE*/
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include "RTClib.h"

RTC_DS1307 rtc;

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

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

#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.isrunning()) {
    Serial.println("RTC is NOT running, 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, 12 hours, 30 minutes, and 6 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));

    Serial.print(" now + 7d + 12h + 30m + 6s: ");
    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.println();
    delay(3000);
}
Smile
Reply


Messages In This Thread
KC868-A6 DS1307 Issue - by Senapsys - 10-23-2022, 06:50 AM
RE: KC868-A6 DS1307 Issue - by admin - 10-23-2022, 10:39 AM
RE: KC868-A6 DS1307 Issue - by Senapsys - 10-24-2022, 02:24 AM
RE: KC868-A6 DS1307 Issue - by admin - 10-24-2022, 06:53 AM
RE: KC868-A6 DS1307 Issue - by Senapsys - 10-24-2022, 11:10 AM
RE: KC868-A6 DS1307 Issue - by admin - 10-24-2022, 11:28 AM
RE: KC868-A6 DS1307 Issue - by Senapsys - 10-24-2022, 12:05 PM
RE: KC868-A6 DS1307 Issue - by admin - 10-24-2022, 12:28 PM
RE: KC868-A6 DS1307 Issue - by admin - 10-25-2022, 06:05 AM
RE: KC868-A6 DS1307 Issue - by Senapsys - 10-25-2022, 07:49 AM
RE: KC868-A6 DS1307 Issue - by admin - 10-25-2022, 08:47 AM
RE: KC868-A6 DS1307 Issue - by Senapsys - 10-25-2022, 10:02 AM
RE: KC868-A6 DS1307 Issue - by admin - 10-25-2022, 11:34 AM
RE: KC868-A6 DS1307 Issue - by Djoii - 01-03-2023, 09:32 PM
RE: KC868-A6 DS1307 Issue - by admin - 01-04-2023, 12:49 AM
RE: KC868-A6 DS1307 Issue - by Fridays - 09-24-2023, 09:30 AM
RE: KC868-A6 DS1307 Issue - by admin - 09-24-2023, 11:07 AM
RE: KC868-A6 DS1307 Issue - by Adriano - 09-24-2024, 11:03 AM
RE: KC868-A6 DS1307 Issue - by admin - 09-24-2024, 12:40 PM
RE: KC868-A6 DS1307 Issue - by Adriano - 09-24-2024, 01:46 PM
RE: KC868-A6 DS1307 Issue - by admin - 09-25-2024, 01:46 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)