Another little spurious LCD character problem

I've now got the DS1307 going, showing time on the LCD and the monitor. There is clearly nothing fundamentally wrong, the monitor is fine, but there is a spurious barred character at the end oif the lower line of the LCD. There are two of them if the seconds are 0-9.

Here is the code

#include <LiquidCrystal.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68

LiquidCrystal lcd(8,9,16,5,6,7);

void setup(){
  Wire.begin();
  Serial.begin(9600);
      lcd.begin(16, 2);
      lcd.clear();
  // Print a message to the LCD.
  lcd.print("Today it is");
}

void loop(){
  printDate();
  delay(1000);

}

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

void printDate(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);

  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());


  lcd.setCursor(12, 0);
    switch (weekDay)                      // Friendly printout the weekday
  {
    case 1:
      lcd.print("MON  ");
      Serial.print("MON  ");
      break;
    case 2:
      lcd.print("TUE  ");
      Serial.print("TUE  ");
      break;
    case 3:
      lcd.print("WED  ");
      Serial.print("WED  ");
      break;
    case 4:
      lcd.print("THU  ");
      Serial.print("THU  ");
      break;
    case 5:
      lcd.print("FRI  ");
      Serial.print("FRI  ");
      break;
    case 6:
      lcd.print("SAT  ");
      Serial.print("SAT  ");
      break;
    case 7:
      lcd.print("SUN  ");
       Serial.print("SUN  ");
      break;
  }

  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(month);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
 
   lcd.setCursor(0,1);
  
  lcd.print(monthDay);
  lcd.print("/");
  lcd.print(month);
  lcd.print("/");
  lcd.print(year);
  lcd.print(" ");
  lcd.print(hour);
  lcd.print(":");
  lcd.print(minute);
  lcd.print(":");
  lcd.println(second);
  
}

and here is a pic

I guess it fixes itself when when there are double digits all through, but I would like to know what is going on.....

I guess it fixes itself when when there are double digits all through, but I would like to know what is going on.....

This is what is going on ...

  lcd.println(second);

There's a good reason that you don't find any documentation for lcdprintln() with the LiquidCrystal library.

Don

Thanks for the comment. The lines for the LCD display were simply lifted from those for the screen, the last thus being

lcd.println(second);

I removed the "ln" and it did get rid of the spurious characters, but now the seconds readout is awry. None of the figures have leading zeros and the last digit is no longer cleared after 59 seconds, the "9" remains. Hence 9 seconds now reads 99 and all is OK at 10 seconds. restoring the lcd.println(second); fixes this but I get the spurious character back.

I have visually fixed it by writing the last two lines as

lcd.print(second);
lcd.println(" ");

but I suspect this is an inelegant solution.....

Thanks again

but I suspect this is an inelegant solution.....

  lcd.println("   ");

will display several spaces followed by the two spurious characters produced by the and ASCII codes. How does this help things?

Check this out for two solutions: Arduino Forum

Don

floresta:

but I suspect this is an inelegant solution.....

  lcd.println("   ");

will display several spaces followed by the two spurious characters produced by the and ASCII codes. How does this help things?

[/quote]

The problem is at the end of a two line display. Pic above. I guess the " " just pushes the junk over the edge, possibly to return on January 1st. It helps things inasmuch that the visual result is exactly what is required, while deleting the "ln" simply swaps one problem for another. It only takes one short line but I will follow the link, sure that there a more kosher way of doing this.

in BASIC we use PRINT USING to put all the data where it needs to be. I'm not sure how C does it yet but this will give you a clean line every time.

if (minutes < 10) // Less than 10 mins?, seconds?
tft.print("0"); // Ok print a leading 0
tft.print(minutes);
Works for me... not the most elegant but I have a nice display of time from a GPS receiver. Small change too.

Doc

The problem is at the end of a two line display. Pic above. I guess the " " just pushes the junk over the edge, possibly to return on January 1st.

Not exactly. Yours is not a viable solution if you ever intend to use a different message format or a display with different geometry. The junk did not get pushed over the edge, it just got put in the closet. It is still in the controller memory but it is in a memory location that does not correspond to a visible character on your display. Follow the LCD Addressing link at http://web.alfredstate.edu/weimandn to see all the gory details.

Don

You can always learn the elegant way of formatting your number for output with sprintf. You will be able to address the problem as an alternative to what Doc showed you. A tutorial is here:

BTW, following floresta's logic, if you use a 20X4 display, the character will still show up. You trying to push it more will not work anymore.