Problem with RTC and LCD Display

I received my Arduino w/ATmega328 couple weeks ago and worked through some of the examples on the web site with good results.

I recently tried my luck of hooking up a RTC DS1307 to my Arduino and would like to display the time on the 20x4 display. Though the learning curve I learned how to add the time library and was able to upload the program to the board. However all that displays to the board is solid boxes in rows one and three?

Does anybody have the code that will allow this to work? Im just looking to print the time and date. Thanks in advance...Jeff

Can you show us the code you're using? The hash button above the text box lets you put code in here easily.

I'd also recommend working through the ladyada tutorial:
http://www.ladyada.net/learn/lcd/charlcd.html
It helped me get my first LCD working.

Once you can something displayed on the LCD it's fairly straight forward to change it so it shows the time.

Thanks for the quick response. I actually started off using that website when I first purchased everything and had a lot of fun doing the projects. The only difference in that site is how he addresses the pins for the LCD compared to how all the other examples in the arduino library are. Still a great and very informative site though. I did verify that I can display custom messages, make them blink, scroll, etc...

The code that I am using is basically copied from a forum member on reef central. I tried to comment out stuff and worked until I got cross eyed. One of the forum members suggested I post in this forum and ask for help. I really am clueless with this and have a lot to learn. Not sure if I need this difficult of a program. I would just like to display the time and date for now. Thanks...Jeff

#include <LiquidCrystal.h>
#include <DS1307RTC.h>
#include <Wire.h>
#include <Time.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte res;
byte msb;
byte lsb;
int val;
int switchPin = 2;// switch is connected to pin 2
int ledPin = 13;
int val1;
int val2;      // variable for reading the pin status
int lightMode;
int buttonState;

void setup()  {
  
  pinMode(switchPin, INPUT);
  buttonState = digitalRead(switchPin);
  lcd.begin(20, 4);
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  Wire.begin();
 
}

void loop()
{
   displayTime();
   getTemp();
   //watchButton();
   //delay(1000);
    val = digitalRead(switchPin);      // read input value and store it in val
  lcd.setCursor(0,3);
  if (val != buttonState) {          // the button state has changed!
    if (val == LOW) {                // check if the button is pressed
      if (lightMode == 0){
        lightMode = 1;
         digitalWrite(ledPin, HIGH);
         lcd.print(".");
      }
      else {
        lightMode = 0;
        digitalWrite(ledPin, LOW);
        lcd.print(" ");
      }
      
    } else {                         // the button is -not- pressed...
      //Serial.println("Button just released");
    }
  }
  buttonState = val;      // save the new state in our variable
  }



void displayTime(){
  lcd.setCursor(15, 0);
  lcd.print(hour());
  printDigits(minute());
  //printDigits(second());
  lcd.print(" ");  
}

void displayDate(){
  //lcd.print(month());
  //lcd.print("/");
  //lcd.print(day());
  //lcd.print("/");
  //lcd.print(year());
}

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

void getTemp(){
  res = Wire.requestFrom(72,2); 
  if (res == 2) {
    msb = Wire.receive(); /* Whole degrees */ 
    lsb = Wire.receive(); /* Fractional degrees */ 
    val = ((msb) << 4);   /* MSB */
    val |= (lsb >> 4);    /* LSB */
    //Serial.println(val*0.0625);
    lcd.setCursor(0, 0);
    lcd.print((((val*0.0625)*9)/5)+32);
    //delay(500);
  }
}

However all that displays to the board is solid boxes in rows one and three?

This indicates that your LCD is not being initialized properly. Since you had it working earlier you know that the hardware is (or was) good. Are you sure that your actual connections match your lcd.begin() statement? Is R/W still connected to GND?

You have got your Serial.println() statements commented out but the Serial.begin() statement is still active. Try commenting that one out as well.

As a final approach you will probably have to comment out all of the non LCD statements from your RTC program and get just the LCD part working again. Then start putting the other stuff back, a few steps at a time, until it stops working again.

Don

I scrapped that example totally. I stumbled across a new DS1307 library matt created and tried that. I have a parallel lcd so that was changed from serial. The issue I have is the date is not displaying properly. It seems that its displaying day/month/year?

Here is the code..

#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> // written by  mattt on the Arduino forum and modified by D. Sjunnesson
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  lcd.begin(20, 4);
  
  Serial.begin(9600);

  RTC.stop();
  RTC.set(DS1307_SEC,1);        //set the seconds
  RTC.set(DS1307_MIN,35);     //set the minutes
  RTC.set(DS1307_HR,10);       //set the hours
  RTC.set(DS1307_DOW,4);       //set the day of the week
  RTC.set(DS1307_DATE,13);       //set the date
  RTC.set(DS1307_MTH,6);        //set the month
  RTC.set(DS1307_YR,10);         //set the year
  RTC.start();

}

void loop()
{

  lcd.setCursor(0, 1);
  lcd.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  lcd.print(":");
  lcd.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  lcd.print(":");
  lcd.print(RTC.get(DS1307_SEC,false));//read seconds
  lcd.print(" ");                 // some space for a more happy life
  lcd.print(RTC.get(DS1307_DATE,false));//read date
  lcd.print("/");
  lcd.print(RTC.get(DS1307_MTH,false));//read month
  lcd.print("/");
  lcd.print(RTC.get(DS1307_YR,false)); //read year 
  lcd.println();

  delay(1000);

}

Sometimes I make things more difficult then what they really are ;D. I played around with some of the programming and came up with the results below.

#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> // written by  mattt on the Arduino forum and modified by D. Sjunnesson
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  lcd.begin(20, 4); //20x4 LCD Display
  lcd.setCursor(3, 0); //Starts on column 3 row 0 
  lcd.print("LED Controller"); //Line above centers statement
  Serial.begin(9600);

  RTC.stop();
  RTC.set(DS1307_SEC,1);        //set the seconds
  RTC.set(DS1307_MIN,22);     //set the minutes
  RTC.set(DS1307_HR,11);       //set the hours
  RTC.set(DS1307_DOW,1);       //set the day of the week
  RTC.set(DS1307_DATE,13);       //set the date
  RTC.set(DS1307_MTH,6);        //set the month
  RTC.set(DS1307_YR,10);         //set the year
  RTC.start();

}

void loop()
{

  lcd.setCursor(0, 2); //Starts on column 0 row 2 
  lcd.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  lcd.print(":");
  lcd.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  lcd.print(":");
  lcd.print(RTC.get(DS1307_SEC,false));//read seconds
  //lcd.print(" ");                 // some space for a more happy life
  lcd.setCursor(10, 2);
  lcd.print(RTC.get(DS1307_MTH,false));//read month
  lcd.print("/");
  lcd.print(RTC.get(DS1307_DATE,false));//read date
  lcd.print("/");
  lcd.print(RTC.get(DS1307_YR,false)); //read year 
  //lcd.println();

  delay(1000);

}

It was being display day, month, year in the code so that why it was like that. I changed that around and displayed what this will actually be used for… Jeff

The issue I have is the date is not displaying properly. It seems that its displaying day/month/year?

You do realize of course that this is the 'proper' order for most places except the US. Take a look at the date at the top of this page.

Don