Skip to content

Commit

Permalink
Merge pull request #2298 from arduino/hannes7eicher/GIGA-RTC-M4
Browse files Browse the repository at this point in the history
[PXCT-17] add RTC RPC example
  • Loading branch information
Hannes7eicher authored Dec 5, 2024
2 parents f779453 + ea7db1b commit c23e95e
Showing 1 changed file with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,94 @@ int servoMove(int angle) {
}
```

### RTC RPC

The Real-time Clock (RTC) can be accessed from the M4 core, and using RPC, we can read the values.

In this example, we set the RTC to a specific date (can be adjusted in the example), send it to the M7 via RPC, and finally prints it out in the Serial Monitor using the M7 core.

**M4 sketch:**
```arduino
/**
* Initial author: Henatu (https://forum.arduino.cc/u/henatu/summary)
* modified 03 December 2024
* by Hannes Siebeneicher
*/
#include "mbed.h"
#include <mbed_mktime.h>
#include "RPC.h"
constexpr unsigned long printInterval{ 1000 };
unsigned long printNow{};
void setup() {
if (RPC.begin()) {
RPC.println("M4: Reading the RTC.");
RTCset(); //sets the RTC to start from a specific time & date
}
}
void loop() {
if (millis() > printNow) {
RPC.print("M4 System Clock: ");
RPC.println(getLocaltime());
printNow = millis() + printInterval;
}
}
String getLocaltime() {
char buffer[32];
tm t;
_rtc_localtime(time(NULL), &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT);
strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t);
return String(buffer);
}
void RTCset() // Set cpu RTC
{
tm t;
t.tm_sec = (0); // 0-59
t.tm_min = (58); // 0-59
t.tm_hour = (11); // 0-23
t.tm_mday = (1); // 1-31
t.tm_mon = (9); // 0-11 "0" = Jan, -1
t.tm_year = ((24) + 100); // year since 1900, current year + 100 + 1900 = correct year
set_time(mktime(&t)); // set RTC clock
}
```

The M7 sketch is found below, and uses RPC to print out the incoming data from the M4.

**M7 sketch:**
```arduino
/**
* Initial author: Henatu (https://forum.arduino.cc/u/henatu/summary)
* modified 03 December 2024
* by Hannes Siebeneicher
*/
#include "mbed.h"
#include "RPC.h"
void setup() {
RPC.begin();
Serial.begin(9600);
while (!Serial) {
; // Wait for Serial (USB) connection
}
Serial.println("M7: Serial connection initiated");
}
void loop() {
if (RPC.available()) {
char incomingByte = RPC.read(); // Read byte from RPC
Serial.write(incomingByte); // Forward the byte to Serial (USB)
}
}
```

### MicroPython RPC LED

This example demonstrates how to use MicroPython (running on the M7 core) to remotely control an LED from the M4 core.
Expand Down

0 comments on commit c23e95e

Please sign in to comment.