|
| 1 | +# RV3028 Breakout (MicroPython) |
| 2 | + |
| 3 | +An ultra-low-power ( ~100 nA), highly accurate real-time clock breakout. The RV3028 RTC breakout is perfect for adding timekeeping to your project and, thanks to the tiny on-board battery, it'll keep time when your device is powered off. Like all the best timepieces, it's Swiss-made! |
| 4 | + |
| 5 | +Available here: https://shop.pimoroni.com/products/rv3028-real-time-clock-rtc-breakout |
| 6 | + |
| 7 | +# **Example Program** |
| 8 | + |
| 9 | +Example program shows how to setup the RV3028, set the date and time and output it once a second. |
| 10 | + |
| 11 | +``` |
| 12 | +from pimoroni_i2c import PimoroniI2C |
| 13 | +from breakout_rtc import BreakoutRTC |
| 14 | +
|
| 15 | +PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} # i2c pins 4, 5 for Breakout Garden |
| 16 | +
|
| 17 | +i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) |
| 18 | +rtc = BreakoutRTC(i2c) |
| 19 | +
|
| 20 | +rtc.setup() |
| 21 | +rtc.enable_periodic_update_interrupt(True) |
| 22 | +
|
| 23 | +rtc.set_time(10, 10, 10, 5, 1, 1, 2001) |
| 24 | +
|
| 25 | +while True: |
| 26 | + |
| 27 | + if (rtc.read_periodic_update_interrupt_flag()): |
| 28 | + rtc.clear_periodic_update_interrupt_flag() |
| 29 | + |
| 30 | + rtc.update_time() |
| 31 | + rtc_time = rtc.string_time() |
| 32 | + print(rtc_time) |
| 33 | +
|
| 34 | +``` |
| 35 | + |
| 36 | +# **Functions** |
| 37 | + |
| 38 | +## `.setup()` |
| 39 | + |
| 40 | +Sets the RTC to 24 Hour Mode, disables the Trickle Charge and sets Level Switching Mode to 3. |
| 41 | + |
| 42 | +## `.set_time(second, minute, hour, weekday, day, month, year)` |
| 43 | + |
| 44 | +Set the time and date on the RTC. Returns **True** if successful and **False** if something went wrong. |
| 45 | + |
| 46 | +**Example:** |
| 47 | + |
| 48 | +``` |
| 49 | +>>> rtc.set_time(0, 52, 8, 4, 5, 6, 2024) |
| 50 | +True |
| 51 | +>>> rtc.update_time() |
| 52 | +True |
| 53 | +>>> print(rtc.string_time(), rtc.string_date()) |
| 54 | +08:52:13 05/06/2024 |
| 55 | +``` |
| 56 | + |
| 57 | +You can also set a time or date element individually with: |
| 58 | + |
| 59 | +`.set_seconds()`, `.set_minutes()`, `.set_hours()`, `.set_weekday()`, `.set_date()`, `.set_month()` and `.set_year()` |
| 60 | + |
| 61 | + |
| 62 | +## `.set_24_hour()` |
| 63 | + |
| 64 | +Set the RTC to output 0-23 Hours. This function will convert any current hour to 2 Hour Mode. |
| 65 | + |
| 66 | +## `.set_12_hour()` |
| 67 | + |
| 68 | +Set the RTC to output 1-12 Hours. This function will convert any current hour to 12 Hour Mode. |
| 69 | + |
| 70 | +## `.is_12_hour()` |
| 71 | + |
| 72 | +Returns **True** if the RV3028 has been configured for 12 Hour mode. |
| 73 | + |
| 74 | +``` |
| 75 | +>>> rtc.is_12_hour() |
| 76 | +False |
| 77 | +>>> rtc.set_12_hour() |
| 78 | +>>> rtc.is_12_hour() |
| 79 | +True |
| 80 | +>>> |
| 81 | +``` |
| 82 | + |
| 83 | +### `.is_pm()` |
| 84 | + |
| 85 | +Returns **True** if the RTC has the PM bit set and the 12 Hour bit set |
| 86 | + |
| 87 | +**Example:** |
| 88 | +``` |
| 89 | +>>> rtc.is_pm() |
| 90 | +False |
| 91 | +``` |
| 92 | + |
| 93 | +## `.update_time()` |
| 94 | + |
| 95 | +This function moves the data from the RV3028 registers to an array. You need to call this function before printing the time and date. The function returns **True** if successful and **False** if something went wrong. |
| 96 | + |
| 97 | +**Example**: |
| 98 | + |
| 99 | +``` |
| 100 | +while True: |
| 101 | + |
| 102 | + rtc.update_time() |
| 103 | + rtc_time = rtc.string_time() |
| 104 | + print(rtc_time) |
| 105 | +
|
| 106 | + time.sleep(1) |
| 107 | +``` |
| 108 | +**Output**: |
| 109 | + |
| 110 | +``` |
| 111 | +10:10:25 |
| 112 | +10:10:26 |
| 113 | +10:10:27 |
| 114 | +``` |
| 115 | + |
| 116 | +## `.string_time()` |
| 117 | + |
| 118 | +Returns the time as a formatted String. You will need to call `.update_time()` to get the current time from the RTC before using this function. |
| 119 | + |
| 120 | +**Example:** |
| 121 | +``` |
| 122 | +>>> rtc.string_time() |
| 123 | +'05:05:05' |
| 124 | +``` |
| 125 | + |
| 126 | +## `.string_date()` |
| 127 | + |
| 128 | +Returns the date as a formatted String. You will need to call `.update_time()` to get the current date from the RTC before using this function. |
| 129 | + |
| 130 | +**Example:** |
| 131 | +``` |
| 132 | +>>> rtc.string_date() |
| 133 | +'05/05/2005' |
| 134 | +``` |
| 135 | + |
| 136 | +## `.enable_periodic_update_interrupt(True)` |
| 137 | + |
| 138 | +Enables the periodic update interrupt. Triggers onces every second. |
| 139 | + |
| 140 | +## `.disable_periodic_update_interrupt()` |
| 141 | + |
| 142 | +Disables the periodic update interrupt. |
| 143 | + |
| 144 | +## `.read_periodic_update_interrupt_flag()` |
| 145 | + |
| 146 | +Read the periodic update interrupt flag. Returns a boolean value. |
| 147 | + |
| 148 | +**Example:** |
| 149 | + |
| 150 | +``` |
| 151 | +>>> rtc.read_periodic_update_interrupt_flag() |
| 152 | +True |
| 153 | +``` |
| 154 | + |
| 155 | +## `.clear_periodic_update_interrupt_flag()` |
| 156 | + |
| 157 | +Clear the periodic update interrupt flag. |
| 158 | + |
| 159 | +**Example:** |
| 160 | +``` |
| 161 | +>>> rtc.clear_periodic_update_interrupt_flag() |
| 162 | +>>> rtc.read_periodic_update_interrupt_flag() |
| 163 | +False |
| 164 | +``` |
| 165 | + |
| 166 | +## `.get_unix()` |
| 167 | + |
| 168 | +Get the UNIX Time from the RTC |
| 169 | + |
| 170 | +**IMPORTANT:** The Real Time and the UNIX time are independent of each other. Retrieving the UNIX Time will not give you the Real Time stored by the RTC. |
| 171 | + |
| 172 | +**Example:** |
| 173 | +``` |
| 174 | +>>> rtc.get_unix() |
| 175 | +3084 |
| 176 | +``` |
| 177 | + |
| 178 | +## `.set_unix()` |
| 179 | + |
| 180 | +Set the UNIX Time on the RTC. Returns **True** if successful and **False** if something went wrong. |
| 181 | + |
| 182 | +**IMPORTANT:** The Real Time and the UNIX time are independent of each other. Setting the UNIX time will not update the Real Time (Hours, minutes, seconds etc) |
| 183 | + |
| 184 | +**Example:** |
| 185 | +``` |
| 186 | +>>> rtc.set_unix(1717508760) |
| 187 | +True |
| 188 | +>>> rtc.get_unix() |
| 189 | +1717508765 |
| 190 | +``` |
| 191 | + |
| 192 | +## `.set_backup_switchover_mode(int value)` |
| 193 | + |
| 194 | +Set the backup switchover mode of the RTC. Accepts values 0-3. |
| 195 | + |
| 196 | +0 = Switchover disabled |
| 197 | +1 = Direct Switching Mode |
| 198 | +2 = Standby Mode |
| 199 | +3 = Level Switching Mode |
| 200 | + |
| 201 | +Function returns **True** if successful and **False** if something went wrong. |
| 202 | + |
| 203 | + |
| 204 | + |
0 commit comments