香橙派断电后,不带电池,所以时间也没法保持,需要增加模块进行时间处理
支持三种模块
DS1307/DS3231/PCF8563
在某宝上面可以买到

例子
- I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds1307.DefaultI2cAddress);
- I2cDevice device = I2cDevice.Create(settings);
-
- using (Ds1307 rtc = new Ds1307(device))
- {
- // set DS1307 time ,设置时间
- rtc.DateTime = DateTime.Now;
-
- // loop
- while (true)
- {
- // read time 读取时间
- DateTime dt = rtc.DateTime;
-
- Console.WriteLine($"Time: {dt.ToString("yyyy/MM/dd HH:mm:ss")}");
- Console.WriteLine();
-
- // wait for a second
- Thread.Sleep(1000);
- }
- }
官方:https://github.com/dotnet/iot/blob/main/src/devices/Rtc/README.md