#!/usr/bin/python # DS3231 import smbus import time address = 0x68 register = 0x00 # sec min hour week day month year NowTime = [0x00,0x53,0x19,0x03,0x19,0x12,0x17] w = ["Nedelja","Ponedeljak","Utorak","Sreda","Cetvrtak","Petak","Subota"]; # Get I2C bus bus = smbus.SMBus(1) def ds3231SetTime(): bus.write_i2c_block_data(address,register,NowTime) def ds3231ReadTime(): return bus.read_i2c_block_data(address,register,19); ds3231SetTime() t = ds3231ReadTime() t[0] = t[0]&0x7F #sec t[1] = t[1]&0x7F #min t[2] = t[2]&0x3F #hour t[3] = t[3]&0x07 #week t[4] = t[4]&0x3F #day t[5] = t[5]&0x1F #month print("20%x/%x/%x %x:%x:%x %s" %(t[6],t[5],t[4],t[2],t[1],t[0],w[t[3]-1])) print("DS3231 Temp= %d.%dC" %(t[17],t[18]))