Additional Open Source B4R Libraries.
Site Admin
Posts: 224
Joined: 07 Oct 2017, 12:16


Postby rwblinn » 21 Nov 2017, 15:24

rDS1302 - Library for the Real Time Clock.
Developed in C++.

To connect a Real Time Clock (RTC) to an Arduino and set or get the time.
The library is wrapped from a C++ library based upon this open source project (many thanks to the author).
Tested with device "Sunfounder RTC DS1302" connected to an Arduino UNO:

DS1302 = Arduino (Wirecolor) - Other pin decsription
SCL = 7 (yellow) - SCLK
SDA = 6 (brown) - IO
RST = 5 (white) - CE
VCC = 3.3v (red)
GND = GND (black)

Library with B4R source code including examples.

• Library completed (unless bugs are reported)

v1.1.0 (20171122) - Redeveloped as updates in cases not working when a device got disconnected and connected again.
v1.0.0 (20160602) - First version.

B4R Example with set & get time

Code: Select all

Sub Process_Globals
   Public Serial1 As Serial
   ' The first entry is a dummy because the library uses sunday as 1, monday as 2 etc.
   Public DayOfWeekArr() As String = Array As String("", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
   Public ds1302 As DS1302
   Public Timer1 As Timer
End Sub

Private Sub AppStart
   'Init the DS1302
   'Set the RTC time
   'Set the timer reading the RTC time every second. 1sec 0 1000millisec.
   Timer1.Initialize("Timer1_Tick", 1000)
   Timer1.Enabled = True
End Sub

'Set the RTC time by using a DSTime var with values assigned.
'Ensure to update with actual date & time prior uploading.
Sub SetRTCTime
   Dim ds1302time As DSTime
   ds1302time.Years = 2017
   ds1302time.Months = 11
   ds1302time.DayOfMonth = 21
   ds1302time.Hours = 11
   ds1302time.Minutes = 25
   ds1302time.Seconds = 0
   ds1302time.DayOfWeek = 5   'Sunday = 1, Monday = 2 etc.
End Sub

'Get the RTC time
Sub GetRTCTime
   'The current time must be defined in the sub. The global can not be used.
   Dim currenttime As DSTime = ds1302.GetTime
   Log("RTC Time ", _
      NumberFormat(currenttime.years,4,0), " ", NumberFormat(currenttime.months,2,0), "-", NumberFormat(currenttime.dayofmonth,2,0), _
      " ", _
      NumberFormat(currenttime.hours,2,0), ":", NumberFormat(currenttime.minutes,2,0), ":", NumberFormat(currenttime.seconds,2,0), _
      " ", _
End Sub

'Log the time every second as set by the Timer Init
Sub Timer1_Tick
End Sub

Return to “Libraries”

Who is online