Beispiel #1
0
#!/usr/bin/python

from ABE_RTCPi import RTC
from ABE_helpers import ABEHelpers
import time

"""
================================================
ABElectronics RTC Pi real-time clock | RTC clock output demo
Version 1.0 Created 19/05/2014
Version 1.1 16/11/2014 updated code and functions to PEP8 format

run with: python demo-rtcout.py
================================================

This demo shows how to enable the clock square wave output on the RTC Pi
and set the frequency
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
rtc = RTC(bus)  # create a new instance of the RTC class


# set the frequency of the output square-wave, options are: 1 = 1Hz, 2 =
# 4.096KHz, 3 = 8.192KHz, 4 = 32.768KHz
rtc.set_frequency(3)
rtc.enable_output()  # enable the square-wave
Beispiel #2
0
        x[i] = buf[i]
    return x


def array_to_double(val):
    # convert an eight byte array into a double
    dval, = struct.unpack('d', bytearray(val))
    return (dval)


# create an instance of the helper class and create an i2c bus object
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

# create a new instance of the RTC class
rtc = RTC(bus)

# number to be written to the RTC memory
value = 0.0005

# convert the number into an array of bytes
writearray = double_to_array(value)

# write the array to the RTC memory
rtc.write_memory(0x08, writearray)

# read eight bytes from the RTC memory into an array
read_array = rtc.read_memory(0x08, 8)

# combine the array values into an number and print it
print(array_to_double(read_array))