### Install PCF85063A Library using pip Source: https://github.com/bablokb/circuitpython-pcf85063a/blob/main/README.rst Commands to install the PCF85063A library using pip. This includes installation for the current user, system-wide, and within a virtual environment. Ensure pip3 is used for Python 3 installations. ```shell pip3 install circuitpython-pcf85063a ``` ```shell sudo pip3 install circuitpython-pcf85063a ``` ```shell mkdir project-name && cd project-name python3 -m venv .venv source .venv/bin/activate pip3 install circuitpython-pcf85063a ``` -------------------------------- ### Complete PCF85063A Datalogging Example Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt A comprehensive CircuitPython example demonstrating multiple PCF85063A features for a datalogging application. It includes initializing the RTC, setting the initial time, using the RAM byte as a boot counter, configuring a 5-minute wakeup timer, logging simulated temperature data, and handling the timer interrupt to enter a low-power sleep state. ```python import time import board import pcf85063a i2c = board.I2C() rtc = pcf85063a.PCF85063A(i2c) # Initialize RTC on first boot if rtc.lost_power: print("Setting initial time...") rtc.datetime = time.struct_time((2025, 10, 18, 0, 0, 0, 4, -1, -1)) rtc.ram_byte = 0 # Initialize boot counter # Increment boot counter boot_count = rtc.ram_byte + 1 rtc.ram_byte = boot_count print(f"Boot #{boot_count}") # Configure 5-minute wakeup timer rtc.timerA_frequency = pcf85063a.PCF85063A.TIMER_FREQ_1HZ rtc.timerA_value = 300 # 300 seconds = 5 minutes rtc.timerA_interrupt = True rtc.timerA_pulsed = False rtc.timerA_enabled = True # Log current time and simulated temperature current = rtc.datetime print(f"{current.tm_year}-{current.tm_mon:02}-{current.tm_mday:02} " f"{current.tm_hour:02}:{current.tm_min:02}:{current.tm_sec:02}") print(f"Temperature: 23.5°C") # Replace with actual sensor reading # Wait for timer interrupt (board would enter deep sleep here) print("Entering sleep mode...") while not rtc.timerA_status: time.sleep(0.1) rtc.timerA_status = False # Reset for next cycle print("Timer elapsed, waking up...") ``` -------------------------------- ### Initialize PCF85063A RTC in CircuitPython Source: https://github.com/bablokb/circuitpython-pcf85063a/blob/main/README.rst Demonstrates how to import the library, initialize the I2C bus using the board library, and instantiate the PCF85063A RTC object. This is the fundamental setup for interacting with the RTC module. ```python3 import time import board import pcf85063a i2c = board.I2C() rrtc = pcf85063a.PCF85063A(i2c) ``` -------------------------------- ### Set and Get Time using PCF85063A Source: https://github.com/bablokb/circuitpython-pcf85063a/blob/main/README.rst Shows how to set the RTC's time using a `time.struct_time` object and how to retrieve the current time. The retrieved time can be accessed using standard `struct_time` attributes like `tm_hour` and `tm_min`. ```python3 rtc.datetime = time.struct_time((2017,1,9,15,6,0,0,9,-1)) t = rtc.datetime print(t) print(t.tm_hour, t.tm_min) ``` -------------------------------- ### Initialize PCF85063A RTC Device Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Initializes the PCF85063A RTC device connected via I2C. Requires the `board` and `pcf85063a` modules. Returns a PCF85063A instance. ```python import board import pcf85063a i2c = board.I2C() rtc = pcf85063a.PCF85063A(i2c) ``` -------------------------------- ### Set and Check Alarm using PCF85063A Source: https://github.com/bablokb/circuitpython-pcf85063a/blob/main/README.rst Illustrates how to configure an alarm on the PCF85063A RTC, specifying a time and frequency (e.g., 'daily'). It also shows how to check the `alarm_status` and reset it after an alarm event. ```python3 rtc.alarm = (time.struct_time((2017,1,9,15,6,0,0,9,-1)), "daily") if rtc.alarm_status: print("wake up!") rtc.alarm_status = False ``` -------------------------------- ### Configure RTC Countdown Timer Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Sets up a countdown timer (timerA) on the RTC with a specified value and frequency. Optionally enables interrupts on the INT pin. Requires `time`, `board`, and `pcf85063a` modules. The timer status can be polled and reset. ```python import time import board import pcf85063a i2c = board.I2C() rpc = pcf85063a.PCF85063A(i2c) # Configure 60-second timer with 1Hz frequency rpc.timerA_frequency = pcf85063a.PCF85063A.TIMER_FREQ_1HZ rpc.timerA_value = 60 # 60 ticks at 1Hz = 60 seconds # Enable timer interrupt on INT pin rpc.timerA_interrupt = True rpc.timerA_pulsed = False # Permanent assertion (not pulsed) # Start the timer rpc.timerA_enabled = True # Wait for timer to elapse while True: if rpc.timerA_status: print("Timer elapsed!") rpc.timerA_status = False # Reset timer flag break time.sleep(0.5) ``` -------------------------------- ### Configure PCF85063A Timer Frequencies Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Demonstrates setting the timer frequency and value for the PCF85063A RTC. Different frequencies allow for timers with varying precision, suitable for tasks ranging from precise 1-minute intervals to longer, less precise durations. The timer can be enabled after configuration. ```python import pcf85063a # Assuming 'rtc' is an initialized PCF85063A object # For 1-minute timer with high precision, use 1Hz rtc.timerA_frequency = pcf85063a.PCF85063A.TIMER_FREQ_1HZ rtc.timerA_value = 60 # 60 seconds # For 1-minute timer with low precision, use 1/60Hz rtc.timerA_frequency = pcf85063a.PCF85063A.TIMER_FREQ_1_60HZ rtc.timerA_value = 1 # 1/60Hz * 1 = 60 seconds # Available frequencies: # TIMER_FREQ_4KHZ = 4.096kHz # TIMER_FREQ_64HZ = 64Hz # TIMER_FREQ_1HZ = 1Hz # TIMER_FREQ_1_60HZ = 1/60Hz (default) rtc.timerA_enabled = True ``` -------------------------------- ### Set Date and Time on RTC Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Sets the date and time on the RTC using a `time.struct_time` object. Automatically clears the power loss flag. Requires `time`, `board`, and `pcf85063a` modules. The input `time.struct_time` should contain year, month, day, hour, minute, second, and weekday. ```python import time import board import pcf85063a i2c = board.I2C() rpc = pcf85063a.PCF85063A(i2c) # Set time: (year, month, day, hour, minute, second, weekday, yearday, isdst) t = time.struct_time((2025, 10, 18, 14, 30, 0, 4, -1, -1)) rpc.datetime = t # Verify time was set print(f"Time set to: {rtc.datetime}") ``` -------------------------------- ### Use PCF85063A RAM Byte for Storage Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Illustrates how to use the PCF85063A's single user RAM byte for storing small amounts of data that persist across power cycles. The RAM byte can be written with values from 0 to 255 and read back. This feature is useful for implementing boot counters or storing simple flags. ```python import board import pcf85063a i2c = board.I2C() rtc = pcf85063a.PCF85063A(i2c) # Write a value to RAM byte (0-255) rtc.ram_byte = 42 # Read RAM byte stored_value = rtc.ram_byte print(f"Stored value: {stored_value}") # Output: 42 # Common use: boot counter or flags boot_count = rtc.ram_byte boot_count += 1 rtc.ram_byte = boot_count print(f"Boot count: {boot_count}") ``` -------------------------------- ### Adjust Oscillator Capacitance with PCF85063A Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Explains how to configure the oscillator load capacitance for the PCF85063A RTC. This setting is crucial for external crystal stability and depends on the PCB layout and load characteristics. Options include high capacitance (12.5pF) for longer traces or higher loads, and low capacitance (7pF) for standard operation. ```python import board import pcf85063a i2c = board.I2C() rtc = pcf85063a.PCF85063A(i2c) # Set high capacitance (12.5pF) for longer traces or higher capacitance loads rtc.high_capacitance = True # Set low capacitance (7pF) for standard operation (default) rtc.high_capacitance = False ``` -------------------------------- ### Configure RTC Clock Output Frequency Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Configures the frequency of the CLKOUT pin on the RTC. Available frequencies range from 32.768kHz down to 1Hz, or can be disabled. Requires `board` and `pcf85063a` modules. Use constants like `PCF85063A.CLOCKOUT_FREQ_1HZ`. ```python import board import pcf85063a i2c = board.I2C() rpc = pcf85063a.PCF85063A(i2c) # Set clock output to 1Hz for LED blinking rpc.clockout_frequency = pcf85063a.PCF85063A.CLOCKOUT_FREQ_1HZ # Available frequencies: # CLOCKOUT_FREQ_32KHZ = 32.768kHz (default) # CLOCKOUT_FREQ_16KHZ = 16.384kHz # CLOCKOUT_FREQ_8KHZ = 8.192kHz # CLOCKOUT_FREQ_4KHZ = 4.096kHz # CLOCKOUT_FREQ_2KHZ = 2.048kHz # CLOCKOUT_FREQ_1KHZ = 1.024kHz # CLOCKOUT_FREQ_1HZ = 1Hz # CLOCKOUT_FREQ_DISABLED = disabled # Disable clock output to save power rpc.clockout_frequency = pcf85063a.PCF85063A.CLOCKOUT_FREQ_DISABLED ``` -------------------------------- ### Configure RTC Alarm Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Configures an alarm on the RTC, optionally triggering an interrupt on the INT pin. The alarm is set using a `time.struct_time` object and a frequency string (e.g., 'daily', 'hourly'). Requires `time`, `board`, and `pcf85063a` modules. The alarm status can be polled and reset. ```python import time import board import pcf85063a i2c = board.I2C() rpc = pcf85063a.PCF85063A(i2c) # Enable alarm interrupt on the INT pin rtc.alarm_interrupt = True # Set alarm for specific time with "daily" frequency alarm_time = time.struct_time((2025, 10, 18, 7, 30, 0, 0, -1, -1)) rpc.alarm = (alarm_time, "daily") # Poll alarm status in main loop while True: if rtc.alarm_status: print("Alarm triggered!") rtc.alarm_status = False # Reset alarm flag break time.sleep(0.1) ``` -------------------------------- ### Check RTC Power Loss Status Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Checks if the RTC has lost power since the last time setting. Returns a boolean value. If power was lost, the time may be invalid and should be reset. Requires `board` and `pcf85063a` modules. ```python import board import pcf85063a i2c = board.I2C() rpc = pcf85063a.PCF85063A(i2c) if rtc.lost_power: print("Warning: RTC lost power, time may be invalid") # Set time to known value import time rtc.datetime = time.struct_time((2025, 1, 1, 0, 0, 0, 0, -1, -1)) else: print(f"RTC time is valid: {rtc.datetime}") ``` -------------------------------- ### Apply Clock Calibration to PCF85063A Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Details how to fine-tune the accuracy of the PCF85063A RTC using offset calibration. The calibration value ranges from -64 to +63 ppm, allowing for speeding up or slowing down the clock. It also covers the calibration schedule, which determines how often the offset is applied, impacting power consumption and precision. ```python import board import pcf85063a i2c = board.I2C() rtc = pcf85063a.PCF85063A(i2c) # Apply calibration offset (range: -64 to +63) # Positive values speed up the clock, negative values slow it down rtc.calibration = -5 # Slow down by 5 LSB # Set calibration schedule # False = every 2 hours (1 LSB = 4.340ppm, lower power, default) # True = every 4 minutes (1 LSB = 4.069ppm, higher precision) rtc.calibration_schedule_per_minute = False # Example: If RTC gains 20 seconds per day, calculate offset: # 20 seconds/day ≈ 231 ppm # Using 2-hour schedule: 231 / 4.340 ≈ -53 LSB rtc.calibration = -53 ``` -------------------------------- ### Read Current Date and Time from RTC Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Reads the current date and time from the RTC. Returns a `time.struct_time` object. Requires `time`, `board`, and `pcf85063a` modules. Individual time components can be accessed as attributes. ```python import time import board import pcf85063a i2c = board.I2C() rpc = pcf85063a.PCF85063A(i2c) # Read current time current = rtc.datetime print(f"Date: {current.tm_year}/{current.tm_mon}/{current.tm_mday}") print(f"Time: {current.tm_hour}:{current.tm_min:02}:{current.tm_sec:02}") print(f"Day of week: {current.tm_wday}") # 0=Monday, 6=Sunday # Access individual fields year = current.tm_year hour = current.tm_hour minute = current.tm_min ``` -------------------------------- ### Adjust RTC Timer Frequency Source: https://context7.com/bablokb/circuitpython-pcf85063a/llms.txt Adjusts the frequency for the RTC's countdown timer. Frequencies range from 4.096kHz down to 1/60Hz, allowing for different countdown precision levels. Requires `board` and `pcf85063a` modules. Use constants like `pcf85063a.PCF85063A.TIMER_FREQ_4096HZ`. ```python import board import pcf85063a i2c = board.I2C() rpc = pcf85063a.PCF85063A(i2c) # Example: Set timer frequency to 4.096kHz rpc.timerA_frequency = pcf85063a.PCF85063A.TIMER_FREQ_4096HZ # Example: Set timer frequency to 1/60Hz rpc.timerA_frequency = pcf85063a.PCF85063A.TIMER_FREQ_1_60HZ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.