I have combined several example sketches for a real time clock and the result is that the LCD displays two wierd characters at the end of the lines.
I used the example sketches from several libraries, DS1302, LiquidCrystal_I2C.
What am I doing wrong here?
Here is the code:
// include the library code:
#include <stdio.h>
#include <string.h>
#include <DS1302.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
/* Set the appropriate digital I/O pin connections */
uint8_t CE_PIN = 2;
uint8_t IO_PIN = 3;
uint8_t SCLK_PIN = 11;
/* Create buffers */
char buf1[20];
char buf2[20];
char buf3[20];
//char buf4[25];
char day[10];
/* Create a DS1302 object */
DS1302 rtc(CE_PIN, IO_PIN, SCLK_PIN);
// initialize the LCD library
LiquidCrystal_I2C lcd2(0x20,20,4); // set the LCD address of the first lcd to 0x20 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd1(0x21,16,2); // set the LCD address of the second lcd to 0x21 for a 16 chars and 2 line display
void print_time()
{
/* Get the current time and date from the chip */
Time t = rtc.time();
/* Name the day of the week */
memset(day, 0, sizeof(day)); /* clear day buffer */
switch (t.day) {
case 1:
strcpy(day, "Zo");
break;
case 2:
strcpy(day, "Ma");
break;
case 3:
strcpy(day, "Di");
break;
case 4:
strcpy(day, "Wo");
break;
case 5:
strcpy(day, "Do");
break;
case 6:
strcpy(day, "Vr");
break;
case 7:
strcpy(day, "Za");
break;
}
/* Format the time and date and insert into the temporary buffer */
snprintf(buf1, sizeof(buf1), "%s %02d-%02d-%04d ",
day,
t.date, t.mon, t.yr);
snprintf(buf2, sizeof(buf2), "%02d:%02d:%02d ",
t.hr, t.min, t.sec);
/* Print the formatted string to LCD so we can see the time */
lcd1.clear();
// lcd1.setCursor(5, 0);
lcd1.println(buf1);
lcd1.setCursor(0, 1);
lcd1.println(buf2);
// lcd1.setCursor(4, 2);
// lcd1.println(buf3);
}
void setup() {
lcd1.init(); // initialize the first lcd
lcd2.init(); // initialize the second lcd
// Print a message on the first LCD.
lcd1.backlight();
lcd1.print("Hello, #1 world!");
// Print a message on the second LCD.
lcd2.backlight();
lcd2.setCursor(0, 0);
lcd2.print("Hello, #2 world!");
delay(1000);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd1.setCursor(0, 0);
// // print the number of seconds since reset:
// lcd.print(millis()/1000);
print_time();
delay(1000);
}