Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.0.3 to add simple examples
Browse files Browse the repository at this point in the history
### Releases v1.0.3

1. Add simple examples with manual time input
  • Loading branch information
khoih-prog authored Jun 23, 2021
1 parent ebfd9ce commit 8b53aea
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Please ensure to specify the following:

```
Arduino IDE version: 1.8.15
Arduino-mbed RP2040 v2.1.0
Arduino-mbed RP2040 v2.2.0
NANO_RP2040_CONNECT Module
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.4.0-74-generic #83-Ubuntu SMP Sat May 8 02:35:39 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Expand Down
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* [Currently supported Boards](#currently-supported-boards)
* [Important Notes about ISR](#important-notes-about-isr)
* [Changelog](#changelog)
* [Releases v1.0.3](#releases-v103)
* [Releases v1.0.2](#releases-v102)
* [Releases v1.0.1](#releases-v101)
* [Initial Releases v1.0.0](#initial-releases-v100)
Expand All @@ -41,10 +42,12 @@
* [2.1 Typedef](#21-typedef)
* [2.2 Library Function List](#22-library-function-list)
* [Examples](#examples)
* [ 1. RP2040_RTC_Alarm_Ethernet](examples/Alarm/RP2040_RTC_Alarm_Ethernet)
* [ 2. RP2040_RTC_Alarm_WiFiNINA](examples/Alarm/RP2040_RTC_Alarm_WiFiNINA)
* [ 3. RP2040_RTC_Time_Ethernet](examples/Time/RP2040_RTC_Time_Ethernet)
* [ 4. RP2040_RTC_Time_WiFiNINA](examples/Time/RP2040_RTC_Time_WiFiNINA)
* [ 1. RP2040_RTC_Alarm](examples/Alarm/RP2040_RTC_Alarm)
* [ 2. RP2040_RTC_Alarm_Ethernet](examples/Alarm/RP2040_RTC_Alarm_Ethernet)
* [ 3. RP2040_RTC_Alarm_WiFiNINA](examples/Alarm/RP2040_RTC_Alarm_WiFiNINA)
* [ 4. RP2040_RTC_Time](examples/Time/RP2040_RTC_Time)
* [ 5. RP2040_RTC_Time_Ethernet](examples/Time/RP2040_RTC_Time_Ethernet)
* [ 6. RP2040_RTC_Time_WiFiNINA](examples/Time/RP2040_RTC_Time_WiFiNINA)
* [Example RP2040_RTC_Time_WiFiNINA](#example-rp2040_rtc_time_wifinina)
* [ 1. File RP2040_RTC_Time_WiFiNINA.ino](#1-file-rp2040_rtc_time_wifininaino)
* [ 2. File defines.h](#2-file-definesh)
Expand Down Expand Up @@ -129,6 +132,10 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),

## Changelog

### Releases v1.0.3

1. Add simple examples with manual time input

### Releases v1.0.2

1. Fix bug in display alarm time due to buggy `datetime_to_str()` function
Expand All @@ -148,8 +155,8 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
## Prerequisites

1. [`Arduino IDE 1.8.15+` for Arduino](https://www.arduino.cc/en/Main/Software)
2. [`Arduino mbed_rp2040 core 2.1.0+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
3. [`Earle Philhower's arduino-pico core v1.8.5+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest)
2. [`Arduino mbed_rp2040 core 2.2.0+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
3. [`Earle Philhower's arduino-pico core v1.8.6+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest)

4. [`Timezone_Generic library v1.5.0+`](https://github.com/khoih-prog/Timezone_Generic) to use examples using Timezone. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/Timezone_Generic.svg?)](https://www.ardu-badge.com/Timezone_Generic)
5. [`WiFiNINA_Generic library v1.8.11+`](https://github.com/khoih-prog/WiFiNINA_Generic) to use WiFiNINA modules/shields. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/WiFiNINA_Generic.svg?)](https://www.ardu-badge.com/WiFiNINA_Generic) if using `WiFiNINA_Generic` library for Nano-RP2040-Connect boards.
Expand Down Expand Up @@ -431,10 +438,12 @@ class DateTime

### Examples

1. [RP2040_RTC_Alarm_Ethernet](examples/Alarm/RP2040_RTC_Alarm_Ethernet)
2. [RP2040_RTC_Alarm_WiFiNINA](examples/Alarm/RP2040_RTC_Alarm_WiFiNINA)
3. [RP2040_RTC_Time_Ethernet](examples/Time/RP2040_RTC_Time_Ethernet)
4. [RP2040_RTC_Time_WiFiNINA](examples/Time/RP2040_RTC_Time_WiFiNINA)
1. [RP2040_RTC_Alarm](examples/Alarm/RP2040_RTC_Alarm)
2. [RP2040_RTC_Alarm_Ethernet](examples/Alarm/RP2040_RTC_Alarm_Ethernet)
3. [RP2040_RTC_Alarm_WiFiNINA](examples/Alarm/RP2040_RTC_Alarm_WiFiNINA)
4. [RP2040_RTC_Time](examples/Time/RP2040_RTC_Time)
5. [RP2040_RTC_Time_Ethernet](examples/Time/RP2040_RTC_Time_Ethernet)
6. [RP2040_RTC_Time_WiFiNINA](examples/Time/RP2040_RTC_Time_WiFiNINA)

---
---
Expand Down Expand Up @@ -784,7 +793,7 @@ The following is the sample terminal output when running example [RP2040_RTC_Tim

```
Start RP2040_RTC_Time_Ethernet on RASPBERRY_PI_PICO with W5x00 using EthernetLarge Library
RP2040_RTC v1.0.2
RP2040_RTC v1.0.3
Timezone_Generic v1.5.0
[EWS] =========== USE_ETHERNET_LARGE ===========
[EWS] Default SPI pinout:
Expand Down Expand Up @@ -827,7 +836,7 @@ The following is the sample terminal output when running example [RP2040_RTC_Tim

```
Start RP2040_RTC_Time_Ethernet on RASPBERRY_PI_PICO with W5x00 using EthernetLarge Library
RP2040_RTC v1.0.2
RP2040_RTC v1.0.3
Timezone_Generic v1.5.0
[EWS] =========== USE_ETHERNET_LARGE ===========
[EWS] Default SPI pinout:
Expand Down Expand Up @@ -869,7 +878,7 @@ The following is the sample terminal output when running example [RP2040_RTC_Tim

```
Start RP2040_RTC_Time_WiFiNINA on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
RP2040_RTC v1.0.2
RP2040_RTC v1.0.3
Timezone_Generic v1.5.0
Connecting to WPA SSID: HueNet1
You're connected to the network, IP = 192.168.2.153
Expand All @@ -895,7 +904,7 @@ The following is the sample terminal output when running example [RP2040_RTC_Ala

```
Start RP2040_RTC_Alarm_Ethernet on RASPBERRY_PI_PICO with W5x00 using EthernetLarge Library
RP2040_RTC v1.0.2
RP2040_RTC v1.0.3
Timezone_Generic v1.5.0
[EWS] =========== USE_ETHERNET_LARGE ===========
[EWS] Default SPI pinout:
Expand Down Expand Up @@ -949,7 +958,7 @@ Alarm @

```
Start RP2040_RTC_Alarm_Ethernet on RASPBERRY_PI_PICO with W5x00 using EthernetLarge Library
RP2040_RTC v1.0.2
RP2040_RTC v1.0.3
Timezone_Generic v1.5.0
[EWS] =========== USE_ETHERNET_LARGE ===========
[EWS] Default SPI pinout:
Expand Down Expand Up @@ -1001,7 +1010,7 @@ The following is the sample terminal output when running example [RP2040_RTC_Ala

```
Start RP2040_RTC_Alarm_Ethernet on MBED RASPBERRY_PI_PICO with W5x00 using EthernetLarge Library
RP2040_RTC v1.0.2
RP2040_RTC v1.0.3
Timezone_Generic v1.5.0
[EWS] =========== USE_ETHERNET_LARGE ===========
[EWS] Default SPI pinout:
Expand Down Expand Up @@ -1062,7 +1071,7 @@ Alarm @

```
Start RP2040_RTC_Alarm_Ethernet on RASPBERRY_PI_PICO with W5x00 using EthernetLarge Library
RP2040_RTC v1.0.2
RP2040_RTC v1.0.3
Timezone_Generic v1.5.0
[EWS] =========== USE_ETHERNET_LARGE ===========
[EWS] Default SPI pinout:
Expand Down Expand Up @@ -1115,7 +1124,7 @@ The following is the sample terminal output when running example [RP2040_RTC_Ala

```
Start RP2040_RTC_Alarm_WiFiNINA on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
RP2040_RTC v1.0.2
RP2040_RTC v1.0.3
Timezone_Generic v1.5.0
Connecting to WPA SSID: HueNet1
You're connected to the network, IP = 192.168.2.153
Expand Down Expand Up @@ -1148,7 +1157,7 @@ Alarm @

```
Start RP2040_RTC_Alarm_WiFiNINA on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
RP2040_RTC v1.0.2
RP2040_RTC v1.0.3
Timezone_Generic v1.5.0
Please upgrade the firmware
Connecting to WPA SSID: HueNet1
Expand Down Expand Up @@ -1186,6 +1195,10 @@ Sometimes, the library will only work if you update the board core to the latest

## Releases

### Releases v1.0.3

1. Add simple examples with manual time input

### Releases v1.0.2

1. Fix bug in display alarm time due to buggy `datetime_to_str()` function
Expand Down Expand Up @@ -1219,6 +1232,7 @@ Submit issues to: [RP2040_RTC issues](https://github.com/khoih-prog/RP2040_RTC/i
1. Basic RTC-wrapper library for **RP2040-based boards, such as NANO_RP2040_CONNECT, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, using [**Arduino-mbed RP2040** core](https://github.com/arduino/ArduinoCore-mbed) or [**Earle Philhower's arduino-pico core**](https://github.com/earlephilhower/arduino-pico).
2. Add Version String
3. Add Table of Contents
4. Add simple examples with manual time input

---
---
Expand Down
195 changes: 195 additions & 0 deletions examples/Alarm/RP2040_RTC_Alarm/RP2040_RTC_Alarm.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/****************************************************************************************************************************
RP2040_RTC_Alarm.ino
For RP2040-based boards using internal RTC
with WiFiNINA, ESP8266/ESP32 WiFi, ESP8266-AT, W5x00, ENC28J60, LAN8742A Ethernet modules/shields
Built by Khoi Hoang https://github.com/khoih-prog/RP2040_RTC
Licensed under MIT license
Version: 1.0.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 13/06/2021 Initial release to support RP2040-based boards using internal RTC
1.0.1 K Hoang 14/06/2021 Add mbed_nano architecture to library.properties
1.0.2 K Hoang 16/06/2021 Fix bug in display alarm time
1.0.3 K Hoang 23/06/2021 Add simple example with manual time input
*****************************************************************************************************************************/

// Important notes: Currently, RP2040-based boards RTC has no battery backup. So the time will be lost when power down
// Therefore, NTP client is necessary to get NTP time and update RTC.

#include "defines.h"

#include <Timezone_Generic.h> // https://github.com/khoih-prog/Timezone_Generic

//////////////////////////////////////////

// US Eastern Time Zone (New York, Detroit)
TimeChangeRule myDST = {"EDT", Second, Sun, Mar, 2, -240}; //Daylight time = UTC - 4 hours
TimeChangeRule mySTD = {"EST", First, Sun, Nov, 2, -300}; //Standard time = UTC - 5 hours
Timezone *myTZ;

TimeChangeRule *tcr; //pointer to the time change rule, use to get TZ abbrev

//////////////////////////////////////////

/*
typedef struct
{
int16_t year; ///< 0..4095
int8_t month; ///< 1..12, 1 is January
int8_t day; ///< 1..28,29,30,31 depending on month
int8_t dotw; ///< 0..6, 0 is Sunday
int8_t hour; ///< 0..23
int8_t min; ///< 0..59
int8_t sec; ///< 0..59
} datetime_t;
*/

// Example set at 04:00:00 Wed 23 Jun 2021 UTC or 00:00:00 Wed 23 Jun 2021 EDT

datetime_t currTime = { 2021, 6, 23, 3, 4, 0, 0 };

datetime_t alarmT;
volatile bool alarmTriggered = false;

#define ALARM_AT_SECONDS 5
#define ALARM_REPEAT_FOREVER true

//////////////////////////////////////////

// This is ISR. Be careful. No Serial.print here.
void rtcCallback()
{
alarmTriggered = true;
}

void set_RTC_Alarm(datetime_t *alarmTime)
{
rtc_set_alarm(alarmTime, rtcCallback);
}

void setAlarmOnce(uint8_t alarmSeconds)
{
rtc_get_datetime(&alarmT);

if ( alarmSeconds > alarmT.sec )
alarmT.sec = alarmSeconds;
else
{
// Alarm in next minute
alarmT.sec = alarmSeconds;
alarmT.min += 1;
}

set_RTC_Alarm(&alarmT);

Serial.print("Set One-time Alarm @ alarmSeconds = "); Serial.println(alarmSeconds);
}

void setAlarmRepeat(uint8_t alarmSeconds)
{
// Redundant, but without this, many times alarm not set !!!
rtc_get_datetime(&alarmT);

alarmT.min = alarmT.hour = alarmT.day = alarmT.dotw = alarmT.month = alarmT.year = -1;
alarmT.sec = alarmSeconds;
set_RTC_Alarm(&alarmT);

Serial.print("Set Repeatitive Alarm @ alarmSeconds = "); Serial.println(alarmSeconds);
}

//////////////////////////////////////////

// format and print a time_t value, with a time zone appended.
void printDateTime(time_t t, const char *tz)
{
char buf[32];
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
strcpy(m, monthShortStr(month(t)));
sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);
Serial.println(buf);
}

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

delay(200);

Serial.print(F("\nStart RP2040_RTC_Alarm on ")); Serial.println(BOARD_NAME);
Serial.println(RP2040_RTC_VERSION);
Serial.println(TIMEZONE_GENERIC_VERSION);

myTZ = new Timezone(myDST, mySTD);

// Start the RTC
rtc_init();

rtc_set_datetime(&currTime);
}

bool setAlarmDone = false;

void setAlarm()
{
#if ALARM_REPEAT_FOREVER
setAlarmRepeat(ALARM_AT_SECONDS);
#else
setAlarmOnce(ALARM_AT_SECONDS);
#endif

setAlarmDone = true;
}

void displayTime()
{
rtc_get_datetime(&currTime);

// Display time from RTC
DateTime now = DateTime(currTime);

time_t utc = now.get_time_t();
time_t local = myTZ->toLocal(utc, &tcr);

printDateTime(utc, "UTC");
printDateTime(local, tcr -> abbrev);
}

void displayRTCTime()
{
static unsigned long displayRTCTime_timeout = 0;

#define DISPLAY_RTC_INTERVAL 10000L

// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to display frequently.
if ((millis() > displayRTCTime_timeout) || (displayRTCTime_timeout == 0))
{
Serial.println("============================");
displayTime();

displayRTCTime_timeout = millis() + DISPLAY_RTC_INTERVAL;
}
}

void loop()
{
displayRTCTime();

if (!setAlarmDone)
{
setAlarm();
}

if (alarmTriggered)
{
alarmTriggered = false;

Serial.println("============================");
Serial.println("Alarm @ ");
displayTime();
}
}
Loading

0 comments on commit 8b53aea

Please sign in to comment.