Issues with displaying outputs on serial monitor after binary to decimal conversion

I was following a tutorial and I ran the code for displaying the date and time from a DS3231 RTC. However, it seems that the Arduino is not able to properly display these values on the serial monitor. I'm not sure what is causing this issue. I assume maybe the problem is with the decimal to binary conversion functions. How do I go about making the date & time display correctly as intended? For example the original version of the code tried to print a weekday directly from an array based on its index value, which gave a very long line of "???????????????????????????????????????????????" on the serial monitor. In order to fix it, I created a variable to store the value of whatever index was chosen from the array to be the weekday. This got rid of the long string question marks, but still does not output anything legible.

link to the tutorial: Here

#include "Wire.h"
/*
 * DS3231 I2C address is:
 *   1101000 R/W'
 *   = 0x68
 *
 * The Wire.h library will append the R/W' bit.
 * So we only specify the first 7 bits  
 */
#define DS3231_I2C_ID 0x68    //I2C address for the DS3231 RTC chip

void setup() {
  Serial.begin(115200);
  Wire.begin();

  //the parameters are: Second, Minute, Hour, WeekDay, Day, Month, Year
  //the following sets: second=45, minute=59, hour=3, weekday=Wednesday, day=29, month=April, year=2017
  setDate(45, 59, 3, 4, 29, 4, 17);  // 24 hour format; Sun=1 
}

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

void setDate(byte Second, byte Minute, byte Hour, byte WeekDay, byte Day, byte Month, byte Year) {
  Wire.beginTransmission(DS3231_I2C_ID);
  Wire.write(0x0);  // register address for the time and date
  Wire.write(dec2bcd(Second));
  Wire.write(dec2bcd(Minute));
  // Hour must be in 24h format
  bool h12 = 1;  // set 12 hour mode
  if(h12){  // 12 hour mode
    if(Hour >= 12){
      Hour = dec2bcd(Hour-12) | 0b01100000;  // bit5(PM)=1; bit6(12 hour)=1
    }else{
      Hour = dec2bcd(Hour) & 0b11011111 | 0b01000000;  // bit5(PM)=0; bit6(12 hour)=1
    }
  }else{  // 24 hour mode
    Hour = dec2bcd(Hour) & 0b10111111;
  }
  Wire.write(Hour);
  Wire.write(dec2bcd(WeekDay));
  Wire.write(dec2bcd(Day));
  Wire.write(dec2bcd(Month));
  Wire.write(dec2bcd(Year));
  Wire.endTransmission();
}

void readDate() {
  Wire.beginTransmission(DS3231_I2C_ID);
  Wire.write(0x0);  // register address for the time and date
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ID, 7);  // get 7 bytes

  byte Second = bcd2dec(Wire.read() & 0b1111111);
  byte Minute = bcd2dec(Wire.read() & 0b1111111);
  byte Hour = Wire.read();
  bool h12 = Hour & 0b01000000;
  bool PM;
  if (h12) {  // 12 hour clock
    PM = Hour & 0b00100000;
    Hour = bcd2dec(Hour & 0b00011111);
  } else {  // 24 hour clock
    Hour = bcd2dec(Hour & 0b00111111);
  }
  byte WeekDay = bcd2dec(Wire.read());  // 1=Sunday
  byte Day = bcd2dec(Wire.read());
  byte Month = bcd2dec(Wire.read());
  byte Year = bcd2dec(Wire.read());
  
  const char* days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  String wDay = days[WeekDay-1];
  
  Serial.print(wDay);
  Serial.print("  ");
  Serial.print(Month);
  Serial.print("/");
  Serial.print(Day);
  Serial.print("/20");
  Serial.print(Year);
  Serial.print("  ");
  Serial.print(Hour);
  Serial.print(":");
  Serial.print(Minute);
  Serial.print(":");
  if (Second < 10) Serial.print("0");
  Serial.print(Second);
  if (PM) Serial.print("P");
  else Serial.print("A");
  Serial.println();
}

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

// Convert normal decimal number to binary coded decimal
byte dec2bcd(byte val) {
  return ((val/10*16) + (val%10));
}
⸮⸮  165/165/20
  165/165/20165  25:85:85P
  165/165/20165  25:85:85P
  165/165/20165  25:85:85P
  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
⸮⸮  165/165/20165  25:85:85P
  const char* days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  String wDay = days[WeekDay - 1];
  Serial.print(wDay);

Iy might be a good idea to decide whether you are going to use C style strings (the days array) or Strings (wDay for instance)

Why not print days[WeekDay - 1] directly instead of using an intermediate variable ?

Value 165 after bcd2dec conversion means that you only received 0xFF from Wire.

It seems that your RTC doesn't answer.

The original code prints it directly and the output ends up as

⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮``````````````````````````````````````````````````````````⸮'⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮v⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮ 165/165/20165  25:85:85P



The tutorial was specifically for the DS3231. I have the same exact model. Should I change the I2c address? This program utilizes the wire library.

#define DS3231_I2C_ID 0x68

Do you test the connections and the address with I2c scanner?

So it seems it is not connected. The wiring I used to connect is below as well as code I used to check it.

VCC -> Arduino 5V

GND -> Arduino Mega GND

SCL -> A5

SDA -> A4

The code I used below to check connection

#include <Wire.h>

void setup()
{
  Wire.begin();
  Serial.begin(115200);
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;
  Serial.println("Scanning...");
  nDevices = 0;
  for (address = 1; address < 127; address++ )
  {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");
      nDevices++;
    }
    else if (error == 4)
    {
      Serial.print("Unknown error at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
  delay(5000);           // wait 5 seconds for next scan
}

output of code

Scanning...
No I2C devices found

Scanning...
No I2C devices found

Scanning...
No I2C devices found

Scanning...
No I2C devices found

The Mega I2C pins are not connected to A4 and A5. That is only on the Uno. Use the actual SDA and SCL pins.

This is a golden example of why we ask people to name their hardware in the first post.

How would I move the hour or minutes forward or back by one without having all the other values revert back to the original starting time?

Did you fix the original pronlem?

Post the code that works or say the original code does.

TIA

a7

the original code works great. Here is what I have now. I am able to increment the hour by 1, but I don't want to have to use setDate(), because although the hour will be incremented by 1, all the other variables will be reset to their original values. How would I be able to get current values for the variables not being incremented?

#include "Wire.h"
/*
 * DS3231 I2C address is:
 *   1101000 R/W'
 *   = 0x68
 *
 * The Wire.h library will append the R/W' bit.
 * So we only specify the first 7 bits  
 */
#define DS3231_I2C_ID 0x68    //I2C address for the DS3231 RTC chip

#include <Keypad.h>


#define KEYPAD_ROW0 22
#define KEYPAD_ROW1 23
#define KEYPAD_ROW2 24
#define KEYPAD_ROW3 25
#define KEYPAD_COL0 26
#define KEYPAD_COL1 27
#define KEYPAD_COL2 28
#define KEYPAD_COL3 29


const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};


byte rowPins[ROWS] = {22, 23, 24, 25}; 
byte colPins[COLS] = {26, 27, 28, 29};


Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);


/********************
 * LCD Set up 
 *******************/
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);


/*********************************
 * Declared variables 
 *********************************/

char userInput = 'Z';
char userInput2 = 'Q';

int A_count = 0;
int E_count = 2;

byte secs =  45;
byte mins =  49;
byte hrs  =   10;
byte wkdy =   3;
byte dy   =  15;
byte mnth =   11;
byte yr   =  22;


void setup() {
  Serial.begin(115200);
  Wire.begin();

  //the parameters are: Second, Minute, Hour, WeekDay, Day, Month, Year
  //the following sets: second=45, minute=59, hour=3, weekday=Wednesday, day=29, month=April, year=2017
  setDate(secs, mins, hrs, wkdy, dy, mnth, yr);  // 24 hour format; Sun=1 
  lcd.begin(16,2);
}

void loop() {
  lcd.clear();

  //Polling for data from keypad 
  char customKey = customKeypad.getKey();
  
  userInput2 = Serial.read(); 

  if(customKey)
  {
    userInput = customKey;
    Serial.println(userInput);
    if(userInput == '*')
    {
      A_count++; 
    }
    else 
    {
      A_count = 0;
    }
    menu(userInput);
  }
  else 
  {
    readDate();
    delay(1000);
  }

  if(userInput2 == 'E')
  {
    Serial.println(userInput2);
    E_count = E_count + 1;
    Serial.println(E_count);
  }
  else 
  {
    E_count = 0;
  }


  if(A_count == 3 || E_count == 3)
  {
    lcd.clear();
    Serial.println("PROGRAM TERMINATED!!!!");
    delay(200);
    exit(0);
  }
  
}

void setDate(byte Second, byte Minute, byte Hour, byte WeekDay, byte Day, byte Month, byte Year) {
  Wire.beginTransmission(DS3231_I2C_ID);
  Wire.write(0x0);  // register address for the time and date
  Wire.write(dec2bcd(Second));
  Wire.write(dec2bcd(Minute));
  // Hour must be in 24h format
  bool h12 = 1;  // set 12 hour mode
  if(h12){  // 12 hour mode
    if(Hour >= 12){
      Hour = dec2bcd(Hour-12) | 0b01100000;  // bit5(PM)=1; bit6(12 hour)=1
    }else{
      Hour = dec2bcd(Hour) & 0b11011111 | 0b01000000;  // bit5(PM)=0; bit6(12 hour)=1
    }
  }else{  // 24 hour mode
    Hour = dec2bcd(Hour) & 0b10111111;
  }
  Wire.write(Hour);
  Wire.write(dec2bcd(WeekDay));
  Wire.write(dec2bcd(Day));
  Wire.write(dec2bcd(Month));
  Wire.write(dec2bcd(Year));
  Wire.endTransmission();
}

void readDate() {
  Wire.beginTransmission(DS3231_I2C_ID);
  Wire.write(0x0);  // register address for the time and date
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ID, 7);  // get 7 bytes

  byte Second = bcd2dec(Wire.read() & 0b1111111);
  byte Minute = bcd2dec(Wire.read() & 0b1111111);
  byte Hour = Wire.read();
  bool h12 = Hour & 0b01000000;
  bool PM;
  if (h12) {  // 12 hour clock
    PM = Hour & 0b00100000;
    Hour = bcd2dec(Hour & 0b00011111);
  } else {  // 24 hour clock
    Hour = bcd2dec(Hour & 0b00111111);
  }
  byte WeekDay = bcd2dec(Wire.read());  // 1=Sunday
  byte Day = bcd2dec(Wire.read());
  byte Month = bcd2dec(Wire.read());
  byte Year = bcd2dec(Wire.read());
  
  const char* days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  lcd.setCursor(0,0);
  Serial.print(days[WeekDay-1]);
  lcd.print(days[WeekDay-1]);
  Serial.print("  ");
  lcd.print(" ");
  Serial.print(Month);
  lcd.print(Month);
  Serial.print("/");
  lcd.print("/");
  Serial.print(Day);
  lcd.print(Day);
  Serial.print("/20");
  lcd.print("/20");
  Serial.print(Year);
  lcd.print(Year);
  Serial.print("  ");
  lcd.setCursor(3,1);
  lcd.print(" ");
  Serial.print(Hour);
  lcd.print(Hour);
  Serial.print(":");
  lcd.print(":");
  Serial.print(Minute);
  lcd.print(Minute);
  Serial.print(":");
  lcd.print(":");
  if (Second < 10){ 
  Serial.print("0");
  }
  Serial.print(Second);
  lcd.print(Second);
  if (PM){
  Serial.print("P");
  }
  else {
    Serial.print("A");
  }
  Serial.println();
}

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

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


/****************************************************
 * Evaluate the user data 
 ***************************************************/

void menu(char userInput)
{
  switch(userInput)
  {
    case '1':
      Serial.println("Set time to DTC");
      Serial.println("Enter sec:"); 
      secs = Serial.read();
      delay(5000);
      Serial.println("Enter mins: ");
      mins = Serial.read();
      delay(5000);
      Serial.println("Enter hours: ");
      hrs = Serial.read();
      delay(5000);
      setDate(secs, mins, hrs, wkdy, dy, mnth, yr);
      break; 
    case '2':
      hrs +=1;
      setDate(secs, mins, hrs, wkdy, dy, mnth, yr);
      break;
    case '3':
      break;
    case '4':
      break;
    case '5':
      break;
    case '0':
      break;      
    case 'A':
      break;
    case 'B':
      break;           
  }
}

Read all data. Change some of it. Write it back.

You don't have a readDateSomehow() function (yet), but I bet you could use readDate() as a model and write one that just got the RTC data into some variables so you could change one of the numbers and write it back.

a7

Working solution
The keypad I have prints the output of the number pressed, so I adjusted the time to also add a second to make up for the time it takes to print the keypad's value on the screen. Here I made all the variables that readData() intializes as global variables, so set data can take the current values after they have been manipulated.

    case '2':
      Hour+=1;
      Second+=1;
      setDate(Second, Minute, Hour, WeekDay, Day, Month, Year);
      break;
Tue  11/22/2021  11:49:46A
Tue  11/22/2021  11:49:47A
2
Tue  11/22/2021  12:49:48A
Tue  11/22/2021  12:49:49A
Tue  11/22/2021  12:49:50A
Tue  11/22/2021  12:49:51A

What this "solution" has to do with problem of reading values from RTC?
Do you fix I2c connection? What is the address of your RTC module?

This is what I have so far. I am able to read values from the RTC and manipulate the time to move the clock and hour ahead or a minute ahead and vice versa. Now, I am having problems with my case 'B': portion of the code that is in the menu function. The keypad seems to show that 'B' is indeed being pressed, but none of the code in the case seems to run. I know that the data in the c byte array is there because I was able to print out all the values stored in it by placing it in the for loop of case 'A'. Any ideas why the code doesn't seem to execute for case 'B'?

#include "Wire.h"
/*
 * DS3231 I2C address is:
 *   1101000 R/W'
 *   = 0x68
 *
 * The Wire.h library will append the R/W' bit.
 * So we only specify the first 7 bits  
 */
#define DS3231_I2C_ID 0x68    //I2C address for the DS3231 RTC chip
#define AT24C32_I2C_ID 0x57   //I2C address for the AT24C32 EEPROM chip on the DS3231 RTC board

#include <Keypad.h>

#define KEYPAD_ROW0 22
#define KEYPAD_ROW1 23
#define KEYPAD_ROW2 24
#define KEYPAD_ROW3 25
#define KEYPAD_COL0 26
#define KEYPAD_COL1 27
#define KEYPAD_COL2 28
#define KEYPAD_COL3 29


const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};


byte rowPins[ROWS] = {22, 23, 24, 25}; 
byte colPins[COLS] = {26, 27, 28, 29};


Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);


/********************
 * LCD Set up 
 *******************/
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);


/*********************
 * Keep track of time 
 ********************/
 #include <Time.h>


/*********************************
 * Declared variables 
 *********************************/

char userInput = 'Z';
char userInput2 = 'Q';

int A_count = 0;
int E_count = 2;

/*********************************
 * SET DATE 
 ********************************/

byte secs =  45;
byte mins =  49;
byte hrs  =   10;
byte wkdy =   3;
byte dy   =  15;
byte mnth =   11;
byte yr   =  22;



/*********************************
 * READ DATE
 ********************************/

  byte Second;
  byte Minute;
  byte Hour;
  byte WeekDay;  
  byte Day;
  byte Month;
  byte Year;
  //byte c;
  byte c[12];
  byte sInfo[12];
 


void setup() {
  Serial.begin(115200);
  Wire.begin();

  //the parameters are: Second, Minute, Hour, WeekDay, Day, Month, Year
  //the following sets: second=45, minute=59, hour=3, weekday=Wednesday, day=29, month=April, year=2017
  setDate(secs, mins, hrs, wkdy, dy, mnth, yr);  // 24 hour format; Sun=1 
  //setTime(secs, mins, hrs, wkdy, dy, mnth, yr);
  lcd.begin(16,2);
}

void loop() {
  lcd.clear();

  //Polling for data from keypad 
  char customKey = customKeypad.getKey();
  
  userInput2 = Serial.read(); 

  if(customKey)
  {
    userInput = customKey;
    Serial.println(userInput);
    if(userInput == '*')
    {
      A_count++; 
    }
    else 
    {
      A_count = 0;
    }
    menu(userInput);
  }
  else 
  {
    readDate();
    delay(1000);
  }

  if(userInput2 == 'E')
  {
    Serial.println(userInput2);
    E_count = E_count + 1;
    Serial.println(E_count);
  }
  else 
  {
    E_count = 0;
  }


  if(A_count == 3 || E_count == 3)
  {
    lcd.clear();
    Serial.println("PROGRAM TERMINATED!!!!");
    delay(200);
    exit(0);
  }
  
}

void setDate(byte Second, byte Minute, byte Hour, byte WeekDay, byte Day, byte Month, byte Year) {
  Wire.beginTransmission(DS3231_I2C_ID);
  Wire.write(0x0);  // register address for the time and date
  Wire.write(dec2bcd(Second));
  Wire.write(dec2bcd(Minute));
  // Hour must be in 24h format
  bool h12 = 1;  // set 12 hour mode
  if(h12){  // 12 hour mode
    if(Hour >= 12){
      Hour = dec2bcd(Hour-12) | 0b01100000;  // bit5(PM)=1; bit6(12 hour)=1
    }else{
      Hour = dec2bcd(Hour) & 0b11011111 | 0b01000000;  // bit5(PM)=0; bit6(12 hour)=1
    }
  }else{  // 24 hour mode
    Hour = dec2bcd(Hour) & 0b10111111;
  }
  Wire.write(Hour);
  Wire.write(dec2bcd(WeekDay));
  Wire.write(dec2bcd(Day));
  Wire.write(dec2bcd(Month));
  Wire.write(dec2bcd(Year));
  Wire.endTransmission();
}

void readDate() {
  Wire.beginTransmission(DS3231_I2C_ID);
  Wire.write(0x0);  // register address for the time and date
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ID, 7);  // get 7 bytes

  /*byte Second = bcd2dec(Wire.read() & 0b1111111);
  byte Minute = bcd2dec(Wire.read() & 0b1111111);
  byte Hour = Wire.read();
  bool h12 = Hour & 0b01000000;
  bool PM;
  if (h12) {  // 12 hour clock
    PM = Hour & 0b00100000;
    Hour = bcd2dec(Hour & 0b00011111);
  } else {  // 24 hour clock
    Hour = bcd2dec(Hour & 0b00111111);
  }
  byte WeekDay = bcd2dec(Wire.read());  // 1=Sunday
  byte Day = bcd2dec(Wire.read());
  byte Month = bcd2dec(Wire.read());
  byte Year = bcd2dec(Wire.read());*/

  Second = bcd2dec(Wire.read() & 0b1111111);
  Minute = bcd2dec(Wire.read() & 0b1111111);
  Hour = Wire.read();
  bool h12 = Hour & 0b01000000;
  bool PM;
  if (h12) {  // 12 hour clock
    PM = Hour & 0b00100000;
    Hour = bcd2dec(Hour & 0b00011111);
  } else {  // 24 hour clock
    Hour = bcd2dec(Hour & 0b00111111);
  }
  WeekDay = bcd2dec(Wire.read());  // 1=Sunday
  Day = bcd2dec(Wire.read());
  Month = bcd2dec(Wire.read());
  Year = bcd2dec(Wire.read());

  
  
  const char* days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  lcd.setCursor(0,0);
  Serial.print(days[WeekDay-1]);
  lcd.print(days[WeekDay-1]);
  Serial.print("  ");
  lcd.print(" ");
  Serial.print(Month);
  lcd.print(Month);
  Serial.print("/");
  lcd.print("/");
  Serial.print(Day);
  lcd.print(Day);
  Serial.print("/20");
  lcd.print("/20");
  Serial.print(Year);
  lcd.print(Year);
  Serial.print("  ");
  lcd.setCursor(3,1);
  lcd.print(" ");
  Serial.print(Hour);
  lcd.print(Hour);
  Serial.print(":");
  lcd.print(":");
  Serial.print(Minute);
  lcd.print(Minute);
  Serial.print(":");
  lcd.print(":");
  if (Second < 10){ 
  Serial.print("0");
  }
  Serial.print(Second);
  lcd.print(Second);
  if (PM){
  Serial.print("P");
  }
  else {
    Serial.print("A");
  }
  Serial.println();
}

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

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


/****************************************************
 * Evaluate the user data 
 ***************************************************/

void menu(char userInput)
{
  switch(userInput)
  {
    case '1':
      Serial.println("Set time to DTC");
      Serial.println("Enter sec:"); 
      secs = Serial.read();
      delay(5000);
      Serial.println("Enter mins: ");
      mins = Serial.read();
      delay(5000);
      Serial.println("Enter hours: ");
      hrs = Serial.read();
      delay(5000);
      setDate(secs, mins, hrs, wkdy, dy, mnth, yr);
      break; 
    case '2':
      Hour+=1;
      Second+=1;
      setDate(Second, Minute, Hour, WeekDay, Day, Month, Year);
      break;
    case '3':
      Hour-=1;
      Second+=1;
      setDate(Second, Minute, Hour, WeekDay, Day, Month, Year);
      break;
    case '4':
      Minute+=1;
      Second+=1;
      setDate(Second, Minute, Hour, WeekDay, Day, Month, Year);
      break;
    case '5':
      Minute-=1;
      Second+=1;
      setDate(Second, Minute, Hour, WeekDay, Day, Month, Year);
      break;
    case '6':
      Minute=0;
      Second+=1;
      setDate(Second, Minute, Hour, WeekDay, Day, Month, Year);
      break;      
    case 'A':
      byte sInfo[] = {WeekDay, Month, Day, Year, Hour, Minute, Second};
      for(int i = 0; i < 7; i++)
      { 
        writeEEPROM(i,sInfo[i]);
        c[i] = readEEPROM(i);
        Serial.print(sInfo[i]);
        Serial.print(" Byte stored in EEPROM location: ");
        Serial.println(i);    
      }
      //writeEEPROM(0,98); 
      //c = readEEPROM(0);
      break;
    case 'B':
      delay(1000);
      Serial.print("Bytes read from EEPROM are: ");
      delay(1000);
      for(int i = 0; i < 7; i++)
      {
        Serial.print(c[i]);
      }
      delay(5000);
      //Serial.println(c);  
      break;           
  }
}


/*****************************************************
 * Write data to EEPROM
 *****************************************************/
void writeEEPROM(int address, byte data) {
  Wire.beginTransmission(AT24C32_I2C_ID);
  // send memory address to write
  // the memory address consists of 12 bits (2^12 = 4096 = 32K bytes)
  Wire.write(address >> 8);    // Address MSB = upper 4 bits
  Wire.write(address & 0xff);  // Address LSB = last 8 bits
  // write data
  Wire.write(data);
    
  Wire.endTransmission();
  delay(5);  // need this delay after a write before a read
}

/*****************************************************
 * Read data from EEprom
 ****************************************************/

byte readEEPROM(int address) {
  // send address to read
  Wire.beginTransmission(AT24C32_I2C_ID);
  Wire.write(address >> 8);    // Address MSB = upper 4 bits
  Wire.write(address & 0xff);  // Address LSB = last 8 bits
  Wire.endTransmission();
  // request 1 byte to read
  Wire.requestFrom(AT24C32_I2C_ID, 1);
  return Wire.read();
}

This will never work. read() blindly reads only one character, whether there is any there or not at the time it's invoked. Try this (I consulted the docs, you should also):
https://www.arduino.cc/reference/en/language/functions/communication/serial/parseint/

Please post the serial output so we can interpret it ourselves.

Output as requested
The keypad value is printed on the screen to confirm the input was received
The values in front of the word "Byte" are is the weekday (it's location in the array), the month, the day, the day and the time in hours, minutes and seconds.

Tue  11/15/2022  11:30:34A
Tue  11/15/2022  11:30:35A
A
3 Byte stored in EEPROM location: 0
11 Byte stored in EEPROM location: 1
15 Byte stored in EEPROM location: 2
22 Byte stored in EEPROM location: 3
11 Byte stored in EEPROM location: 4
30 Byte stored in EEPROM location: 5
35 Byte stored in EEPROM location: 6
Tue  11/15/2022  11:30:36A
Tue  11/15/2022  11:30:37A
Tue  11/15/2022  11:30:38A
Tue  11/15/2022  11:30:39A
Tue  11/15/2022  11:30:40A
Tue  11/15/2022  11:30:41A
Tue  11/15/2022  11:30:42A
B
Tue  11/15/2022  11:30:43A
Tue  11/15/2022  11:30:44A
Tue  11/15/2022  11:30:45A
Tue  11/15/2022  11:30:46A
Tue  11/15/2022  11:30:47A

Well, you seem to have pressed "A" on the keypad. What output when you press "B"?

'B' is towards the bottom under "Tue 11/15/2022 11:30:42A". No code seems to execute. it is just supposed to print out everything stored in byte array c.