DS1307 and LCD

How do I interface an 16x2 LCD and an DS1307 RTC

The 1307 can be done with the Time library http://www.arduino.cc/playground/Code/Time An 16x2 LCD is too vague ? http://arduino.cc/en/Reference/LiquidCrystal?from=Tutorial.LCDLibrary ???

How do I display the current time on an LCD though? I have the LCD currently set up like this: http://www.ladyada.net/learn/lcd/charlcd.html

Assuming you have the "Hello world" example running you must change

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

to include calls to

  lcd.print(hour());
  lcd.print(minute());
   lcd.print(second());

Of course you must read the RTC first to give hour() etc meaningfull values.

Read the examples (esp. TimeRTC) of the time library carefully, It will take some time but it is not that difficult.

Thanks I will see how it goes.

You could also check out my DS1307 library (http://www.henningkarlsen.com/electronics/a_l_ds1307.php).

One of the examples is exactly what you are asking for :)

/Henning

Well things are not going too well. I tried these suggestions with no success. I Really just want to have a DS1307 with a backup battery interfaced with an 16x2 LCD. It should be pretty simple but I cant figure it out. Can someone help?

Well things are not going too well.

Can someone help?

With such vague descriptions of the problems you are having, no. The best we can do is offer condolences and wish you luck.

I Really just want to have a DS1307 with a backup battery interfaced with an 16x2 LCD.

What DS1307 do you have? Are you able to get/set the time on it? What code do you have to get/set the time? What code do you have to display the time on the LCD? Are you able to display ANYTHING on the LCD?

How about you supply some facts this time?

If you want people to concentrate on helping you solve your problem you might want to consider changing/removing your avatar. Just my opinion.

Don

I have a DE-LM003 LCD. I set it up using this tutorial: http://www.ladyada.net/learn/lcd/charlcd.html and I can display things using the LiquidCrystal Library. As for the RTC I have this DS1307 Breakout Board: http://cgi.ebay.com/DS1307-Based-Real-Time-Clock-Arduino-I2C-/230554031842?pt=LH_DefaultDomain_0&hash=item35ae1756e2

That is all the information I know.

I have tried doc_norway's sketch again and all I get displayed for DS1307_LCD is this:

00:00:85 xxx 00.00.2000

I have tried doc_norway's sketch again

http://www.henningkarlsen.com/electronics/a_l_ds1307.php

Four demos are included to demonstrate most of the functions.

I'm really tired of guessing. Show the code YOU are using.

00:00:85 xxx 00.00.2000

Looks like you didn't set the time. This is what you normally would get if this is the case.

/Henning

No, I did set it...

No, I did set it...

Well, that's not at all apparent from looking at your code. If you don't want to post code, please don't post questions, either.

Don't worry about how good or bad your code may look. The important thing is that you post what you are using so that others can see how your program is working and tell you where the problems may be. If you're unwilling to do this, everyone will be guessing as to what you are doing right and what you are doing wrong. There are some very knowledgeable people here who are more than willing to help, but you must be willing to share what you are doing in order to tap into that knowledge. Don't be shy.

;DNevermind, I got everything working last night with using this: http://arduinotronics.blogspot.com/2010/10/ds1307-real-time-clock-working.html ;D

Can you output anything to your LCD?
If you have the Time library, even without setting the CURRENT time you should get something.
This is the sketch I based my code on.

/*
 * RTC Control v.01
 * by <http://www.combustory.com> John Vaughters
 * Credit to:
 * Maurice Ribble - http://www.glacialwanderer.com/hobbyrobotics for RTC DS1307 code
 *
 * With this code you can set the date/time, retreive the date/time and use the extra memory of an RTC DS1307 chip.  
 * The program also sets all the extra memory space to 0xff.
 * Serial Communication method with the Arduino that utilizes a leading CHAR for each command described below. 
 * Commands:
 * T(00-59)(00-59)(00-23)(1-7)(01-31)(01-12)(00-99) - T(sec)(min)(hour)(dayOfWeek)(dayOfMonth)(month)(year) - T Sets the date of the RTC DS1307 Chip. 
 * Example to set the time for 02-Feb-09 @ 19:57:11 for the 3 day of the week, use this command - T1157193020209
 * Q(1-2) - (Q1) Memory initialization  (Q2) RTC - Memory Dump
 */

#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address


// Global Variables

int command = 0;       // This is the command char, in ascii form, sent from the serial port     
int i;
long previousMillis = 0;        // will store last time Temp was updated
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
byte test; 
  
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers, Probably need to put in checks for valid numbers.
 
void setDateDs1307()                
{

   second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48)); // Use of (byte) type casting and ascii math to achieve result.  
   minute = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   hour  = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   dayOfWeek = (byte) (Serial.read() - 48);
   dayOfMonth = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   month = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   year= (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.send(0x00);
   Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
   Wire.send(decToBcd(minute));
   Wire.send(decToBcd(hour));      // If you want 12 hour am/pm you need to set
                                   // bit 6 (also need to change readDateDs1307)
   Wire.send(decToBcd(dayOfWeek));
   Wire.send(decToBcd(dayOfMonth));
   Wire.send(decToBcd(month));
   Wire.send(decToBcd(year));
   Wire.endTransmission();
}

// Gets the date and time from the ds1307 and prints result
void getDateDs1307()
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0x00);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  second     = bcdToDec(Wire.receive() & 0x7f);
  minute     = bcdToDec(Wire.receive());
  hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
  dayOfWeek  = bcdToDec(Wire.receive());
  dayOfMonth = bcdToDec(Wire.receive());
  month      = bcdToDec(Wire.receive());
  year       = bcdToDec(Wire.receive());
  
  Serial.print(hour, DEC);
  Serial.print(":");
  Serial.print(minute, DEC);
  Serial.print(":");
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(year, DEC);

}


void setup() {
  Wire.begin();
  Serial.begin(57600);
 
}

void loop() {
     if (Serial.available()) {      // Look for char in serial que and process if found
      command = Serial.read();
      if (command == 84) {      //If command = "T" Set Date
       setDateDs1307();
       getDateDs1307();
       Serial.println(" ");
      }
      else if (command == 81) {      //If command = "Q" RTC1307 Memory Functions
        delay(100);     
        if (Serial.available()) {
         command = Serial.read(); 
         if (command == 49) {      //If command = "1" RTC1307 Initialize Memory - All Data will be set to 255 (0xff).  Therefore 255 or 0 will be an invalid value.  
          Wire.beginTransmission(DS1307_I2C_ADDRESS); // 255 will be the init value and 0 will be considered an error that occurs when the RTC is in Battery mode.
          Wire.send(0x08); // Set the register pointer to be just past the date/time registers.
         for (i = 1; i <= 27; i++) {
             Wire.send(0xff);
            delay(100);
         }   
         Wire.endTransmission();
         getDateDs1307();
         Serial.println(": RTC1307 Initialized Memory");
         }
         else if (command == 50) {      //If command = "2" RTC1307 Memory Dump
          getDateDs1307();
          Serial.println(": RTC 1307 Dump Begin");
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.send(0x00);
          Wire.endTransmission();
          Wire.requestFrom(DS1307_I2C_ADDRESS, 64);
          for (i = 1; i <= 64; i++) {
             test = Wire.receive();
             Serial.print(i);
             Serial.print(":");
             Serial.println(test, DEC);
          }
          Serial.println(" RTC1307 Dump end");
         } 
        }  
       }
      Serial.print("Command: ");
      Serial.println(command);     // Echo command CHAR in ascii that was sent
      }
      
      command = 0;                 // reset command 
      delay(100);
    }
//*****************************************************The End***********************

After I set the current local time I was able to use this bit of code.

/*
 * TimeRTC.pde
 * example code illustrating Time library with Real Time Clock.
 * 
 */

#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

void setup()  {
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet) 
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");      
}

void loop()
{
   digitalClockDisplay();  
   delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Are you sure your Arduino can “see” the RTC?