1

I have a rp2040 board using Earl E. Philhower core. I would like to use the rtc functions just like the one mentioned in the sdk. Especially the alarm function which is critical in my project.

Supposedly from what i know you have access to all the functions in the sdk on the arduino IDE but when i tried out the example in the sdk it would not compile saying that rtc functions are not declared

char datetime_buf[256];
char *datetime_str = &datetime_buf[0];

    datetime_t t = {
            .year  = 2020,
            .month = 06,
            .day   = 05,
            .dotw  = 5, // 0 is Sunday, so 5 is Friday
            .hour  = 15,
            .min   = 45,
            .sec   = 00
    };
    
void setup() {
    Serial.begin(9600);
    Serial.println("Hello RTC!");

    rtc_init();
    rtc_set_datetime(&t);
}

// the loop function runs over and over again forever
void loop() {
        rtc_get_datetime(&t);
        
        Serial.println(datetime_str);
        sleep_ms(100);             // wait for a second
}

Earl E. Philhower comes with a Time sketch example but problem is i could not find a documentation if a alarm like function exist

/* Simple demonstration of setting and printing the current time */
/* The initial time will need to come from an RTC, NTP, or user */

/* Released to the public domain by Earle F. Philhower, III <[email protected]> */

#include <time.h>
#include <sys/time.h>

void setup() {
  Serial.begin(115200);
  delay(5000);
  struct timeval tv;

  tv.tv_sec = 1611198855; // Jan 21, 2021  3:14:15AM ...RPi Pico Release;
  tv.tv_usec = 0;
  settimeofday(&tv, nullptr);
}

void loop() {
  time_t now;
  char buff[80];

  time(&now);
  strftime(buff, sizeof(buff), "%c", localtime(&now));
  Serial.println(buff);
  delay(1000);
}
2
  • Did you #include "hardware/rtc.h" when trying to use the RTC from the SDK?
    – Majenko
    Commented Nov 15, 2021 at 13:42
  • @Majenko Yes, it could not find the library. fatal error: hardware/rtc.h: No such file or directoryResolveLibrary(hardware/rtc.h)
    – Jack
    Commented Nov 15, 2021 at 13:44

1 Answer 1

3

You can try to use my RP2040_RTC Library, especially this RP2040_RTC_Alarm example.

Both ArduinoCore-mbed and Earle Philhower arduino-pico cores are supported.

7
  • This looks nice, it even has example on how to get time via, ethernet which is one of the reason for the alarm, i need to update the time every 6 hours.
    – Jack
    Commented Nov 15, 2021 at 14:57
  • by the way , is this a hardware implementation of RTC?
    – Jack
    Commented Nov 15, 2021 at 15:38
  • Yes. It's the RP2040 hardware RTC, as mentioned in section 4.1.21. hardware_rtc of Raspberry Pi Pico-C/C++ SDK
    – khoih-prog
    Commented Nov 15, 2021 at 18:31
  • Cool, thank you for making the library :)
    – Jack
    Commented Nov 15, 2021 at 19:02
  • I have a question about alarms, if the alarm goes off it triggers an interrupt right? and just like how standard interrupts work, it will stop whatever its doing and process that interrupt right?
    – Jack
    Commented Nov 17, 2021 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.