Skip to main content

Meadow.Foundation.Grove.RTCs.RTC

RTC
StatusStatus badge: working
Source codeGitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Grove.RTCs.RTC

Code Example

RTC rtc;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

rtc = new RTC(Device.CreateI2cBus());

return Task.CompletedTask;
}

public override Task Run()
{
var running = rtc.IsRunning;

Resolver.Log.Info($"{(running ? "is running" : "is not running")}");

if (!running)
{
Resolver.Log.Info(" Starting RTC...");
rtc.IsRunning = true;
}

var dateTime = rtc.GetTime();
Resolver.Log.Info($" RTC current time is: {dateTime:MM/dd/yy HH:mm:ss}");

Resolver.Log.Info($" Setting RTC to : {dateTime:MM/dd/yy HH:mm:ss}");
dateTime = new DateTime(2030, 2, 15);
rtc.SetTime(dateTime);

dateTime = rtc.GetTime();
Resolver.Log.Info($" RTC current time is: {dateTime:MM/dd/yy HH:mm:ss}");

var rand = new Random();

var data = new byte[56];

for (int i = 0; i < 56; i++)
{
data[i] = (byte)rand.Next(256);
}

Resolver.Log.Info($" Writing to RTC RAM : {BitConverter.ToString(data)}");
rtc.WriteRAM(0, data);
Resolver.Log.Info($" Reading from RTC RAM : ");
data = rtc.ReadRAM(0, 56);
Resolver.Log.Info(BitConverter.ToString(data));

return Task.CompletedTask;
}

Sample project(s) available on GitHub

Wiring Example

RTCMeadow Pin
GNDGND
VCC3.3V
RXD01
TXD00

Class RTC

Represents a Real Time Clock (RTC)

Assembly: RTC.dll
View Source
Declaration
public class RTC : Ds1307, II2cPeripheral, IRealTimeClock

Inheritance: System.Object -> Meadow.Foundation.RTCs.Ds1307

Implements:
Meadow.Hardware.II2cPeripheral, Meadow.Hardware.IRealTimeClock

Implements

  • Meadow.Hardware.II2cPeripheral
  • Meadow.Hardware.IRealTimeClock