Instructables

Step 7: Hook up a Chronodot.

Picture of Hook up a Chronodot.
DSC_6831.JPG
DSC_6837.JPG
Macetech has a really cool real time clock module for ~$15 that can keep perfect time!  It is called a Chronodot.  Check it out and order it here: http://macetech.com/store/index.php?main_page=product_info&cPath=5&products_id=8&zenid=3395f33814bb6d6d78fe449837b4305b

I found it really easy to program.  I just used the test program at the bottom of the documentation page as a basis. 

To hook up the chronodot, I made a couple of wires to connect to the 5v, gnd, scl and sda pins on the chronodot.  I hooked the power and gnd connectors on the chronodot to the 5V and gnd connectors on the Arduino.  The SDA pin connects to Analog pin 4 and the SCL pin goes to Analog pin 5.  Here is a resource for hooking up the Chronodot: http://www.codingcolor.com/microcontrollers/an-arduino-lcd-clock-using-a-chronodot-rtc/

Then I hacked the chronodot test code into my program and away it went!

Here is the code, or you can download below.

/*
* gearclock_Chronodot.pde
*
* Brian Wagner
* LVL1 - Louisville's Hackerspace
* www.lvl1.org
* 9/10/11
* 9/18/11 reworked to use time_t
* 9/19/11 Added Chronodot
*/

#include <Stepper.h>
#include <Wire.h>

#define STEPS 20 // The stepper has 20 steps per revolution
int ledPin = 13; // LED connected to digital pin 13
int LastMinute;
int ThisMinute;

int LastSecond;
int ThisSecond;

//for the 21-02485-03 stepper, the colors in order are yellow, red, black/white, blue

Stepper Hours(STEPS, 4, 5, 6, 7);
Stepper Minutes(STEPS, 8, 9, 10, 11);
int MinuteCount;

void setup()
{
pinMode(ledPin, OUTPUT);
//Serial.begin(9600);
Wire.begin();
// clear /EOSC bit
// Sometimes necessary to ensure that the clock
// keeps running on just battery power. Once set,
// it shouldn't need to be reset but it's a good
// idea to make sure.
Wire.beginTransmission(0x68); // address DS3231
Wire.send(0x0E); // select register
Wire.send(0b00011100); // write register bitmap, bit 7 is /EOSC
Wire.endTransmission();

LastMinute = 0;
LastSecond = 0;

//how fast is it gonna step
Minutes.setSpeed(5);
Hours.setSpeed(5);

//test the minutes and hours to make sur it is going in the correct direction
//Minutes.step(100);
//Hours.step(100);
Minutes.step(4);
Hours.step(4);

MinuteCount = 1;
}

void loop()
{
int seconds ;
int minutes ;
int hours ;

// send request to receive data starting at register 0
Wire.beginTransmission(0x68); // 0x68 is DS3231 device address
Wire.send(0); // start at register 0
Wire.endTransmission();
Wire.requestFrom(0x68, 3); // request three bytes (seconds, minutes, hours)

while(Wire.available())
{
seconds = Wire.receive(); // get seconds
minutes = Wire.receive(); // get minutes
hours = Wire.receive(); // get hours

seconds = (((seconds & 0b11110000)>>4)*10 + (seconds & 0b00001111)); // convert BCD to decimal
minutes = (((minutes & 0b11110000)>>4)*10 + (minutes & 0b00001111)); // convert BCD to decimal
hours = (((hours & 0b00110000)>>4)*10 + (hours & 0b00001111)); // convert BCD to decimal (assume 24 hour mode)

//Serial.print(hours); Serial.print(":"); Serial.print(minutes); Serial.print(":"); Serial.println(seconds);
}

ThisMinute = minutes;
ThisSecond = seconds;

if ( ThisSecond != LastSecond ) {
digitalWrite(ledPin, HIGH); // set the LED on
delay(200); // wait for 500ms
digitalWrite(ledPin, LOW); // set the LED off
LastSecond = ThisSecond;
}


if ( ThisMinute != LastMinute ) {
Minutes.step(2);
MinuteCount++;
LastMinute = ThisMinute;
}

//tick the hour ring every 5 minutes
if (MinuteCount > 5) {
Hours.step(2);
MinuteCount = 1;
}

delay(200);
}




 
Remove these adsRemove these ads by Signing Up