Has anyone used the new i2c functions in the arduino 006 or 007 to read a dallas DS1307 real time clock? How would I go about implementing something like that in code and spitting out the time over the serial port? What Pins should things be hooked to and how would I use the Wire lib to call the time in from the clock chip?

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.

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...)

I'm working on a 2 digit clock, myself.. Unfortunately I may have just somehow wrecked my ds1307 - also on a carrier board from sparkfun..

lately when I make a request for data from it, it gives me junk data. I'm not sure how I would have wrecked it, but it certainly appears as such.

I also just ordered the atmega168 so I can use i2c and an LCD in a sketch... currently you can just BARELY do it before you're out of space. Making a request and putting it up on the LCD raw leaves me w/ like 4 bytes.

I also think my code for culling the digits is a little fat. I'll try to post it up once I get home...

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 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.

yeah, I thought the same thing - maybe use Processing to send the current time.. but then I wondered how often I would actually be doing that... then hard coded it into the app and tried to time up upload/execution of it..

So yeah.. I wish that the Wire lib didn't take as much space.. What are you using the straight C++ for?

I'm working on a sunrise clock for myself since I have a tendancey to stay up late trying to learn this stuff and have a difficult time getting up in the morning.. It's oddly circular, this project...

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.

I've thought about getting this to drive a Nixie tube clock that I plan on building and using the Arduino to control the tubes.

I liked the idea of the RTC, that way when I power the clock I will automatically have the time. Just wondering if it's worth the $15 or if I should just get some push buttons to increment the hour/minutes and set it every time.

I do think though using the RTC breakout board from Sparkfun would save me a lot of code when I can just pull the values from the RTC, convert to binary and send off to the 74141 IC that is driving the Nixie.

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.

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.

I like the RTC approach as well since it is only $15 and it would then mean I have a very accurate clock that I can move and not worry about resetting the time. Plus it will save me room for other logic (I might interface temperature and any other sensors I can find to generate information to display).

Plus this will most likely sit on my desk at work and I might put it away when I leave the office. So plugging it in each morning and have it automatically set the time will be great.

Thanks for the code as well up top! That will definitely come in handy.

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.