Meadow.Foundation.RTCs.Ab0805
| Ab0805 | |
|---|---|
| Status | |
| Source code | GitHub |
| Datasheet(s) | GitHub |
| NuGet package |
Code Example
private Ab0805 rtc;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
rtc = new Ab0805(Device.CreateI2cBus());
return base.Initialize();
}
public override async Task Run()
{
// Test basic RTC functionality
await TestBasicRTC();
// Test countdown timers
await TestCountdownTimers();
}
private async Task TestBasicRTC()
{
Resolver.Log.Info("=== Testing Basic RTC Functionality ===");
var running = rtc.IsRunning;
Resolver.Log.Info($"RTC {(running ? "is running" : "is not running")}");
if (!running)
{
Resolver.Log.Info("Starting RTC...");
rtc.IsRunning = true;
}
var currentTime = rtc.GetTime();
Resolver.Log.Info($"RTC current time: {currentTime:MM/dd/yy HH:mm:ss}");
// Set RTC to a known time for testing
var testTime = new DateTime(2025, 6, 15, 14, 30, 0);
Resolver.Log.Info($"Setting RTC to: {testTime:MM/dd/yy HH:mm:ss}");
rtc.SetTime(testTime);
currentTime = rtc.GetTime();
Resolver.Log.Info($"RTC time after setting: {currentTime:MM/dd/yy HH:mm:ss}");
await Task.Delay(2000);
currentTime = rtc.GetTime();
Resolver.Log.Info($"RTC time after 2 second delay: {currentTime:MM/dd/yy HH:mm:ss}");
}
private async Task TestCountdownTimers()
{
Resolver.Log.Info("\n=== Testing Countdown Timer Functionality ===");
await TestAlarm();
await Task.Delay(1000);
await TestBasicTimer();
}
private async Task TestBasicTimer()
{
Resolver.Log.Info("\n--- Test 1: Basic 2-second countdown timer ---");
rtc.ResetTimer();
Resolver.Log.Info("Starting 2-second countdown timer...");
rtc.StartTimer(5, Ab0805.DelayTimeUnit.Seconds);
var startTime = DateTime.Now;
TimeSpan elapsed;
while (rtc.HasTimerEnded == false)
{
elapsed = DateTime.Now - startTime;
Resolver.Log.Info($"Elapsed: {elapsed.TotalSeconds:F1}s");
await Task.Delay(1000);
}
elapsed = DateTime.Now - startTime;
Resolver.Log.Info($"✓ Timer completed! Interrupt fired after {elapsed.TotalSeconds:F1}s");
rtc.ResetTimer();
}
private async Task TestAlarm()
{
Resolver.Log.Info("\n--- Test 2: Alarm 5 seconds in the future ---");
DateTimeOffset alarmTime = rtc.GetTime().AddSeconds(5);
Resolver.Log.Info("Monitoring alarm...");
rtc.SetAlarm(alarmTime);
var startTime = DateTime.Now;
TimeSpan elapsed;
while (rtc.HasAlarmTriggered == false)
{
elapsed = DateTime.Now - startTime;
Resolver.Log.Info($"Elapsed: {elapsed.TotalSeconds:F1}s");
await Task.Delay(1000);
}
elapsed = DateTime.Now - startTime;
Resolver.Log.Info($"✓ Alarm triggered! Interrupt fired after {elapsed.TotalSeconds:F1}s");
await Task.Delay(5000);
rtc.ResetAlarm();
}
Sample project(s) available on GitHub
API Reference
Class Ab0805
Represents a Ab0805 real-time clock
Assembly: Ab0805.dll
View Source
Declaration
public class Ab0805 : II2cPeripheral, IRealTimeClock
Implements:
Meadow.Hardware.II2cPeripheral, Meadow.Hardware.IRealTimeClock
Properties
DefaultI2cAddress
The default I2C address for the peripheral
View Source
Declaration
public byte DefaultI2cAddress { get; }
IsRunning
Gets or sets whether the RTC is running
View Source
Declaration
public bool IsRunning { get; set; }
HasTimerEnded
Has the timer ended
View Source
Declaration
public bool HasTimerEnded { get; }
HasAlarmTriggered
Has the alarm triggered
View Source
Declaration
public bool HasAlarmTriggered { get; }
Methods
GetTime()
Gets the current time from the RTC.
View Source
Declaration
public DateTimeOffset GetTime()
Returns
System.DateTimeOffset: A System.DateTimeOffset object representing the current time.
SetTime(DateTimeOffset)
Sets the time on the RTC.
View Source
Declaration
public void SetTime(DateTimeOffset time)
Parameters
| Type | Name | Description |
|---|---|---|
System.DateTimeOffset | time | The System.DateTimeOffset to set. |
SetAlarm(DateTimeOffset)
Sets the alarm time
View Source
Declaration
public void SetAlarm(DateTimeOffset alarmTime)
Parameters
| Type | Name | Description |
|---|---|---|
System.DateTimeOffset | alarmTime | The DateTimeOffset to trigger the alarm |
StartTimer(byte, DelayTimeUnit)
Start the timer on the RTC
View Source
Declaration
public void StartTimer(byte timerValue, Ab0805.DelayTimeUnit unit = DelayTimeUnit.Seconds)
Parameters
| Type | Name | Description |
|---|---|---|
System.Byte | timerValue | Count down timer value as an integer |
| Meadow.Foundation.RTCs.Ab0805.DelayTimeUnit | unit | Count down seconds or minutes |
ResetTimer()
Reset the timer on the RTC.
View Source
Declaration
public void ResetTimer()
ResetAlarm()
Reset the alarm on the RTC.
View Source
Declaration
public void ResetAlarm()
Implements
Meadow.Hardware.II2cPeripheralMeadow.Hardware.IRealTimeClock