For this Arduino tutorial we have two real-time clock modules to use, one based on the Maxim DS1307. We keep getting requests on how to use DS1307 and DS3231 real-time clock modules with Arduino from various sources – so this is the first of a two part tutorial on how to use them. Because this is not an especially unlikely occurrence - particularly if you're querying the time pretty often - we take a 'snapshot' of the time from the RTC all at once and then we can pull it apart into day() or second()as seen above. If you did it the other way around you could get 3:15:59 - so one minute off in the other direction. However, there's one problem where if you happen to ask for the minute right at 3:14:59 just before the next minute rolls over, and then the second right after the minute rolls over (so at 3:15:00) you'll see the time as 3:14:00 which is a minute off. There are some RTC libraries that instead have you call something like RTC.year() and RTC.hour() to get the current year and hour. There's pretty much only one way to get the time using the RTClib, which is to call now(), a function that returns a DateTime object that describes the year, month, day, hour, minute and second when you called now(). Now load up the following sketch (which is also found in Examples→RTClib→ds1307) and upload it to your Arduino with the datalogger shield on! Wait 3 seconds and then replace the battery. So to start, remove the battery from the holder while the Arduino is not powered or plugged into USB. We'll also show what happens if you remove the battery and replace it since that causes the RTC to halt. If is first Run ds1307 then call Ds1307_play() 4.Enjoy!įirst RTC TestThe first thing we'll demonstrate is a test sketch that will read the time from the RTC once a second. '- 1.Edit “Sub Ds1307_config()”:For ex) ' Soft_I2C config pins- Sub Ds1307_config() 'Config ds1307 Waitms 50 Dim A As Byte Dim B As Byte Config Scl = Portc.5 'set scl_i2c pin Config Sda = Portc.4 'set sda_i2c pin 'set i2c speed 100khz Config I2cdelay = 10 End Sub ' - 2.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |