Wednesday, April 3, 2013

Reading Time & Date from a Chronodot Using Python with a Raspberry Pi

Here is a quick example of how to read the time and date from a Chronodot using the Python SMBus module (for I2C communication).


Chronodot   Raspberry Pi
GND         GND
VCC         3V3
SCL         SCL0
SDA         SDA0

The Raspberry Pi has built-in pull-up resistors on the SCL and SDA lines, so external pull-up resistors are not needed.


import smbus
import time
import time
bus = smbus.SMBus(1)
address = 0x68
data = bus.read_i2c_block_data(address, 0)
ss = (data[0]/16*10) + (data[0]%16)
mm = (data[1]/16*10) + (data[1]%16)
hr = (data[2]/16*10) + (data[2]%16)
day = (data[3]/16*10) + (data[3]%16)
date = (data[4]/16*10) + (data[4]%16)
month = (data[5]/16*10) + (data[5]%16)
year = (data[6]/16*10) + (data[6]%16)
buffer = "%02d:%02d:%02d %02d/%02d/%02d" % (hr, mm, ss, month, day, year)
print buffer

No comments:

Post a Comment