forked from switchdoclabs/RTC_SDL_DS3231
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testSDL_DS3231.py
72 lines (52 loc) · 1.52 KB
/
testSDL_DS3231.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
#
# Test SDL_DS3231
# John C. Shovic, SwitchDoc Labs
# 08/03/2014
#
#
# imports
import sys
import time
import datetime
import random
import SDL_DS3231
# Main Program
print ""
print "Test SDL_DS3231 Version 1.0 - SwitchDoc Labs"
print ""
print ""
print "Program Started at:"+ time.strftime("%Y-%m-%d %H:%M:%S")
print ""
filename = time.strftime("%Y-%m-%d%H:%M:%SRTCTest") + ".txt"
starttime = datetime.datetime.utcnow()
ds3231 = SDL_DS3231.SDL_DS3231(1, 0x68)
#comment out the next line after the clock has been initialized
ds3231.write_now()
# Main Loop - sleeps 10 seconds, then reads and prints values of all clocks
# Also reads two bytes of EEPROM and writes the next value to the two bytes
# do the AT24C32 eeprom
print "----------------- "
print "----------------- "
print " Test the AT24C32 EEPROM"
print "----------------- "
print "writing first 10 addresses with random data"
for x in range(0,10):
value = random.randint(0,255)
print "address = %i writing value=%i" % (x, value)
ds3231.write_AT24C32_byte(x, value)
print "----------------- "
print "reading first 10 addresses"
for x in range(0,10):
print "address = %i value = %i" %(x, ds3231.read_AT24C32_byte(x))
print "----------------- "
print "----------------- "
while True:
#
currenttime = datetime.datetime.utcnow()
deltatime = currenttime - starttime
print ""
print "Raspberry Pi=\t" + time.strftime("%Y-%m-%d %H:%M:%S")
print "DS3231=\t\t%s" % ds3231.read_datetime()
print "DS3231 Temp=", ds3231.getTemp()
time.sleep(10.0)