Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: July 06, 2007, 02:42:20 pm
Quote
I also thought about getting this to drive a clock and be very hands off, and for me that means adjusting for DST so once set I shouldn't have to touch it.

Nice!
2  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: July 06, 2007, 02:41:01 pm
Quote
So use (0x40 | your_time) for 24-hour, or ( ((is_am) ? 0 : 0x02) | your_time) for am/pm mode.

This is some really bad advice btw.  I need to go back to bit shifting school.

24 hour mode: just use your_hour with no ORs (bit 6 - 0=24 hr, 1=12 hr)
12 hour mode: use -
    0x40 | ((is_am) ?  0 : 0x20) | your_hour

your_hour should be binary-coded decimal (so 0x13 == 1pm in 24 hour mode).
3  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: July 02, 2007, 01:16:31 pm
Quote
yep, that's done the trick. One final thing if I'm setting the hour to be 6, how do I know if its am or pm? or how can I set it to be 18:00 instead of 6?

That's what the high bits of the hour are for.  From the datasheet, you have in the top nibble: bit 2 selects 12 or 24 hour time, bit 1 is either the am/pm indicator or the high bit of the 24 hour time.

So use (0x40 | your_time) for 24-hour, or ( ((is_am) ? 0 : 0x02) | your_time) for am/pm mode.
4  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: July 02, 2007, 11:56:46 am
Quote
Wire.beginTransmission(104); // transmit to device #104, the ds1307
  Wire.send(0);
  Wire.send(0x00);

You have an extra 0 in there I think.  You just need to send one to set the register pointer.
5  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: July 02, 2007, 10:56:42 am
Quote
Hi there, I have modified slightly the code to give me the full set of data the module outputs, and removed the code specific to the display.

the problem I'm getting is that the data returned doesn't seem to make much sense...  smiley

time is: 34:49:66 day, 2 date, 5 month, 5 year, 0
time is: 34:49:67 day, 2 date, 5 month, 5 year, 0
time is: 34:49:68 day, 2 date, 5 month, 5 year, 0
time is: 34:49:69 day, 2 date, 5 month, 5 year, 0
time is: 34:49:70 day, 2 date, 5 month, 5 year, 0

Thanks.

Well first things first, you need to mask off a few bits on the second and the hrs.  Note in the original code there was "hrs & 0x3f" when it was writing it, and "secs & 0x7f".. yes that should've been up there on the same line with Wire.receive() but oh well.  This is because the 'clock halt' sits in the top bit of secs and there are all kinds of state variables in the top 3 bits of hrs.

Looking at the diagram, note that date is split into two nibbles - the most significant holds '10 date'.  The date is stored in BCD so for the 31st day of the month you'd see 0x31 instead of e.g. 0x1f if it were straight binary.

To program the clock (which you may not need to do after fixing the above) just uncomment the code at the top, and pick reasonable values for the time/date.  It was originally set for 9:52pm.  Make sure the CH bit is zero or the clock won't run.  I also think there's a bug up there, 0x80 should've been 0x40 when setting the hours to 24 hour time.

HTH,
Bob
6  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: January 30, 2007, 09:57:04 am
I like the RTC approach simply because it's less hassle.  If you don't want to drop $15, you can get the DS1307 in a DIP package for $4 from Digikey (of course, then you still need the battery, the crystal, etc).  You don't even have to convert the values from the RTC -- they are BCD just like the 74141 expects, but you do have to mask off the AM/PM bits, clock enable, etc.

My project is going to use four large LED-based 7 segment displays, but the clock functionality is kind of a side thing.
7  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: January 26, 2007, 06:01:29 pm
Quote
So yeah.. I wish that the Wire lib didn't take as much space.. What are you using the straight C++ for?

No particular reason, just as a C hacker used to the command line, I like to get the GUI out of the way.  I haven't really had a reason to optimize for space yet but may look into it if I get close to the limit.
8  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: January 25, 2007, 12:11:34 pm
Yeah one definite improvement would be to read the current time from the host computer then program the chip when first setting up the sketch.  I'm too lazy to do that though, since this is only a test for a larger thing I'm doing smiley  So I had just hardcoded it to program 9:48 pm or whatever time it was when I first loaded it up, then relied on the battery backup from then on.
9  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: January 23, 2007, 12:08:44 pm
BTW I finally got around to taking a picture of the device using the above sketch.  It's a one-digit clock using the DS1307.  Most of the arduino's outputs are dedicated to the inputs a-g on the 7 segment display.  I built the thing on Sparkfun's spiffy little ProtoShield.  (Yeah, the picture is too dark...)

10  Forum 2005-2010 (read only) / Interfacing / Re: i2c and a Dallas RTC Anyone?? on: January 12, 2007, 09:33:03 am
Hi there,

I've done this using the breakout module from Spark Fun.  Basically, assuming the atmega8, you connect analog 4 to SDA and A5 to SCL, and attach a pull-up resistor (I think I used 2.2k) from both of these to the 5V line.  I used the data sheet for the chip to figure out how to program it and read it over I2C.  Here's my code for a circuit that reads the time and displays the hours/minutes/seconds on a single 7 segment display.  I use straight C++ outside the IDE, so you can probably kill the #includes.
Code:
/*
 * A single-digit clock
 * (c) 2007 Bob Copeland <me at bobcopeland.com>
 */
#include <WProgram.h>
#include <Wire.h>
#include <HardwareSerial.h>

char bcd_to_7seg[] = {
    0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x00
};

// pins a-g on 7 seg display
int pins[] = { 11, 10, 7, 3, 4, 8, 12 };

void setup()
{
    int i;

    Wire.begin();
    Serial.begin(9600);

    for (i=0; i<7; i++)
        pinMode(pins[i], OUTPUT);

/*
    // program the time & enable clock
    Wire.beginTransmission(0x68);
    Wire.send(0);
    Wire.send(0x00);
    Wire.send(0x52);
    Wire.send(0x80 | 0x21);
    Wire.endTransmission();
*/
}

void write_digit(char digit)
{
    int i;
    char byte = bcd_to_7seg[digit];
    for (i=0; i<7; i++)
    {
        digitalWrite(pins[i], byte & 1);
        byte >>= 1;
    }
}

void write_number(char num)
{
    write_digit(10);
    delay(50);
    write_digit((num >> 4) & 0x0f);
    delay(200);

    write_digit(10);
    delay(50);
    write_digit(num & 0x0f);
    delay(200);
}

void loop()
{
    // reset register pointer
    Wire.beginTransmission(0x68);
    Wire.send(0);
    Wire.endTransmission();
    delay(100);

    Wire.requestFrom(0x68, 3);
    char secs = Wire.receive();
    char mins = Wire.receive();
    char hrs = Wire.receive();

    write_number(hrs & 0x3f);
    delay(100);
    write_number(mins);
    delay(100);
    write_number(secs & 0x7f);
    delay(1000);
}
11  Forum 2005-2010 (read only) / Interfacing / Re: Creating an analog second hand on: February 06, 2007, 03:05:43 pm
Since you are going for an analog look and feel, what about finding and putting an analog vu-meter in there.  Set it up so that at 59 seconds it hits the max level, then whenever the seconds roll over you can just dump the analog out back to zero.  This way you don't have to worry about drift at all - just put the seconds on analog out scaled to whatever voltage level matches the meter's range.

... err nevermind.  I just asked digikey how much those cost.  Yikes!
Pages: [1]