x[0] = val & 0xFF return x def array_to_int(x): # convert a four byte array into an integer val = (x[0]<<24) + (x[1]<<16) + (x[2]<<8) + x[3] return val # 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) # integer to be written to the RTC memory writeval = 176247 # convert the integer into an array of bytes writearray = int_to_array(writeval) # write the array to the RTC memory rtc.write_memory(0x08, writearray) # read four bytes from the RTC memory into an array read_array = rtc.read_memory(0x08, 4) # print the individual array values print (read_array[0], read_array[1], read_array[2], read_array[3])
#!/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
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))
#!/usr/bin/python3 from ABE_RTCPi import RTC from ABE_helpers import ABEHelpers import time """ ================================================ ABElectronics RTC Pi real-time clock | Set Time Demo Version 1.0 Created 29/02/2015 Requires python 3 smbus to be installed run with: python3 demo-rtcsettime.py ================================================ This demo shows how to set the time on the RTC Pi and then read the current time at 1 second intervals """ i2c_helper = ABEHelpers() bus = i2c_helper.get_smbus() rtc = RTC(bus) # create a new instance of the RTC class # set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS rtc.set_date("2013-04-23T12:32:11") while True: # read the date from the RTC in ISO 8601 format and print it to the screen print(rtc.read_date()) time.sleep(1) # wait 1 second
from ABE_RTCPi import RTC from ABE_helpers import ABEHelpers import time """ ================================================ ABElectronics RTC Pi real-time clock | Set Time 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-rtcsettime.py ================================================ This demo shows how to set the time on the RTC Pi and then read the current time at 1 second intervals """ i2c_helper = ABEHelpers() bus = i2c_helper.get_smbus() rtc = RTC(bus) # create a new instance of the RTC class # set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS rtc.set_date("2013-04-23T12:32:11") while True: # read the date from the RTC in ISO 8601 format and print it to the screen print rtc.read_date() time.sleep(1) # wait 1 second
#!/usr/bin/python3 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 29/02/2015 Requires python 3 smbus to be installed run with: python3 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