Trying to get this rtc to show up on my lcd

#include <LiquidCrystal.h>

Trying to get this rtc to show up on my lcd, can you please help?
Thank you
Guy

LiquidCrystal lcd(2,3,4,5,6,7);
int s,m,h,a,d,state,state1,state2,dg,cnt;

// the 8 arrays that form each segment of the custom numbers
byte bar1[8] =
{
B11100,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11100
};
byte bar2[8] =
{
B00111,
B01111,
B01111,
B01111,
B01111,
B01111,
B01111,
B00111
};
byte bar3[8] =
{
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111
};
byte bar4[8] =
{
B11110,
B11100,
B00000,
B00000,
B00000,
B00000,
B11000,
B11100
};
byte bar5[8] =
{
B01111,
B00111,
B00000,
B00000,
B00000,
B00000,
B00011,
B00111
};
byte bar6[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111
};
byte bar7[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00111,
B01111
};
byte bar8[8] =
{
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};

void setup()

{
Serial.begin(9600);

// assignes each segment a write number
lcd.createChar(1,bar1);
lcd.createChar(2,bar2);
lcd.createChar(3,bar3);
lcd.createChar(4,bar4);
lcd.createChar(5,bar5);
lcd.createChar(6,bar6);
lcd.createChar(7,bar7);
lcd.createChar(8,bar8);
state=1;
state1=1;
state2=1;
// sets the LCD's rows and colums:
lcd.begin(16, 2);
pinMode(8,INPUT_PULLUP);
pinMode(9,INPUT_PULLUP);
pinMode(10,INPUT_PULLUP);
s=0;
m=0;
h=0;
a=0;
}

void custom0(int col)
{ // uses segments to build the number 0
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(8);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(6);
lcd.write(1);
}

void custom1(int col)
{
lcd.setCursor(col,0);
lcd.write(32);
lcd.write(32);
lcd.write(1);
lcd.setCursor(col,1);
lcd.write(32);
lcd.write(32);
lcd.write(1);
}

void custom2(int col)
{
lcd.setCursor(col,0);
lcd.write(5);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(6);
lcd.write(6);
}

void custom3(int col)
{
lcd.setCursor(col,0);
lcd.write(5);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(7);
lcd.write(6);
lcd.write(1);
}

void custom4(int col)
{
lcd.setCursor(col,0);
lcd.write(2);
lcd.write(6);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(32);
lcd.write(32);
lcd.write(1);
}

void custom5(int col)
{
lcd.setCursor(col,0);
lcd.write(2);
lcd.write(3);
lcd.write(4);
lcd.setCursor(col, 1);
lcd.write(7);
lcd.write(6);
lcd.write(1);
}

void custom6(int col)
{
lcd.setCursor(col,0);
lcd.write(2);
lcd.write(3);
lcd.write(4);
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(6);
lcd.write(1);
}

void custom7(int col)
{
lcd.setCursor(col,0);
lcd.write(2);
lcd.write(8);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(32);
lcd.write(32);
lcd.write(1);
}

void custom8(int col)
{
lcd.setCursor(col, 0);
lcd.write(2);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(6);
lcd.write(1);
}

void custom9(int col)
{
lcd.setCursor(col, 0);
lcd.write(2);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(7);
lcd.write(6);
lcd.write(1);
}

void printNumber(int value, int col) {
if (value == 0) {
custom0(col);
} if (value == 1) {
custom1(col);
} if (value == 2) {
custom2(col);
} if (value == 3) {
custom3(col);
} if (value == 4) {
custom4(col);
} if (value == 5) {
custom5(col);
} if (value == 6) {
custom6(col);
} if (value == 7) {
custom7(col);
} if (value == 8) {
custom8(col);
} if (value == 9) {
custom9(col);
}
}

void loop()

{
if(!digitalRead(8)&state==1){
cnt++;
state=0;
if(cnt>3){
cnt=0;
}
}else if(digitalRead(8)&state==0){
state=1;
}

if(!digitalRead(9)&&state1==1){
dg=1;
state1=0;

}else if(digitalRead(9)&state1==0){
state1=1;
}

if(!digitalRead(10)&&state2==1){
dg=-1;
state2=0;
}else if(digitalRead(10)&state2==0){
state2=1;
}
switch(cnt){
case 1:
m=m+dg;
dg=0; if(m>59){
m=59;}
if(m<0){
m=0;}
break;

case 2:
h=h+dg;
dg=0;if(h>11){
h=11;}
if(h<0){
h=0;}
break;
case 3:
if(dg==1){
a=1;
dg=0;}
if(dg==-1){
a=0;
dg=0;}
break;
}
if(s>59){
s=0;
m++;

if(m>59){
m=0;
h++;

if(h>11){
h=0;
a=!a;
}
}
}
d=h%10;
printNumber(d, 3);
d=h/10;
printNumber(d, 0);

d=m%10;
printNumber(d, 10);
d=m/10;
printNumber(d, 7);
lcd.setCursor(14, 0);
if(a){
lcd.print("AM");
}else{
lcd.print("PM");
}
if(cnt==0){
s++;
lcd.setCursor(6, 0);
lcd.print(" ");
lcd.setCursor(6, 1);
lcd.print(" ");
delay(500);
lcd.setCursor(6, 0);
lcd.print(".");
lcd.setCursor(6, 1);
lcd.print(".");
delay(500);
Serial.println("lcd");

}
}

Trying to set time and date and year

@raiders9691 you did not provide the information I requested in my previous reply.

Are you still experiencing the problem you reported previously?:

No, I am not.

i hope this time I am sending this out correctly.
I cannot seem to set time and date.

here is my code

/*
DS3231_test.pde
Eric Ayars
4/11

Test/demo of read routines for a DS3231 RTC.

Turn on the serial monitor after loading this to check if things are
working as they should.

*/

#include <DS3231.h>
#include <Wire.h>

DS3231 myRTC;
bool century = false;
bool h12Flag;
bool pmFlag;
byte alarmDay, alarmHour, alarmMinute, alarmSecond, alarmBits;
bool alarmDy, alarmH12Flag, alarmPmFlag;

void setup() {
// Start the I2C interface
Wire.begin();

// Start the serial interface
Serial.begin(57600);
}

void loop() {
// send what's going on to the serial monitor.

// Start with the year
Serial.print("2");
if (century) { // Won't need this for 89 years.
Serial.print("1");
} else {
Serial.print("0");
}
Serial.print(myRTC.getYear(), DEC);
Serial.print(' ');

// then the month
Serial.print(myRTC.getMonth(century), DEC);
Serial.print(" ");

// then the date
Serial.print(myRTC.getDate(), DEC);
Serial.print(" ");

// and the day of the week
Serial.print(myRTC.getDoW(), DEC);
Serial.print(" ");

// Finally the hour, minute, and second
Serial.print(myRTC.getHour(h12Flag, pmFlag), DEC);
Serial.print(" ");
Serial.print(myRTC.getMinute(), DEC);
Serial.print(" ");
Serial.print(myRTC.getSecond(), DEC);

// Add AM/PM indicator
if (h12Flag) {
if (pmFlag) {
Serial.print(" PM ");
} else {
Serial.print(" AM ");
}
} else {
Serial.print(" 24h ");
}

// Display the temperature
Serial.print("T=");
Serial.print(myRTC.getTemperature(), 2);

// Tell whether the time is (likely to be) valid
if (myRTC.oscillatorCheck()) {
Serial.print(" O+");
} else {
Serial.print(" O-");
}

// Indicate whether an alarm went off
if (myRTC.checkIfAlarm(1)) {
Serial.print(" A1!");
}

if (myRTC.checkIfAlarm(2)) {
Serial.print(" A2!");
}

// New line on display
Serial.println();

// Display Alarm 1 information
Serial.print("Alarm 1: ");
myRTC.getA1Time(alarmDay, alarmHour, alarmMinute, alarmSecond, alarmBits, alarmDy, alarmH12Flag, alarmPmFlag);
Serial.print(alarmDay, DEC);
if (alarmDy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(' ');
Serial.print(alarmHour, DEC);
Serial.print(' ');
Serial.print(alarmMinute, DEC);
Serial.print(' ');
Serial.print(alarmSecond, DEC);
Serial.print(' ');
if (alarmH12Flag) {
if (alarmPmFlag) {
Serial.print("pm ");
} else {
Serial.print("am ");
}
}
if (myRTC.checkAlarmEnabled(1)) {
Serial.print("enabled");
}
Serial.println();

// Display Alarm 2 information
Serial.print("Alarm 2: ");
myRTC.getA2Time(alarmDay, alarmHour, alarmMinute, alarmBits, alarmDy, alarmH12Flag, alarmPmFlag);
Serial.print(alarmDay, DEC);
if (alarmDy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(" ");
Serial.print(alarmHour, DEC);
Serial.print(" ");
Serial.print(alarmMinute, DEC);
Serial.print(" ");
if (alarmH12Flag) {
if (alarmPmFlag) {
Serial.print("pm");
} else {
Serial.print("am");
}
}
if (myRTC.checkAlarmEnabled(2)) {
Serial.print("enabled");
}

// display alarm bits
Serial.println();
Serial.print("Alarm bits: ");
Serial.println(alarmBits, BIN);

Serial.println();
delay(1000);
}

Thank you in advance for your help.

Since the latest posts are unrelated to the subject of the original post, I split them out to a dedicated topic so that the helpers knowledgeable in the new subject matter will be more likely to see your request for assistance.

1 Like

Please read the advice in the topic "How to get the best from this forum". Post the code using code tags. While you are at it also post an annotated schematic showing exactly how you have wired it showing all connections, power, ground and power sources.

1 Like

How do you expect the special characters to be set before you start the lcd? Why not just use the existing characters?

so you mean start the lcd then put in time and date?/

@raiders9691

Instead of Bxxxxx, use 0bxxxxx here. Also, when using

lcd.write();

values must be cast as byte. So, this

lcd.write(2);

would look like this

lcd.write((byte)2);

after correction.
Also, I don't know about

lcd.write(32);

I have never seen it used like that. There might be more errors that I didn't catch.
All best, V

1 Like

Apart from lack of portability, there is no problem at all using Bxxxx in Arduino-land.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.