Blue 16x2 LCD showing squares

I know there are a lot of threads on this but I couldn't solve my problem. My 16x2 blue LCD is only showing 16 squares on the first row. This my wiring:

And this is the code:

#include <ThreeWire.h>
#include <RtcDS1302.h>
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

//0x3F or 0x27
LiquidCrystal_I2C lcd(0x3F, 16, 2);   //LCD Object

ThreeWire myWire(11, 10, 12);        // DAT, CLK, RST
RtcDS1302<ThreeWire> Rtc(myWire);    // RTC Object

void setup ()
{
  lcd.init();
  lcd.backlight();
  lcd.clear();

  Rtc.Begin();

  RtcDateTime currentTime = RtcDateTime(__DATE__ , __TIME__);
  Rtc.SetDateTime(currentTime);
}

void loop ()
{
  RtcDateTime now = Rtc.GetDateTime();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Date: ");
  lcd.print(now.Day());
  lcd.print("/");
  lcd.print(now.Month());
  lcd.print("/");
  lcd.print(now.Year());

  lcd.setCursor(0, 1);
  lcd.print("Time: ");
  lcd.print(now.Hour());
  lcd.print(":");
  lcd.print(now.Minute());
  lcd.print(":");
  lcd.print(now.Second());

  //Set the Date and Time Manually when '*' key is pressed
  char c = customKeypad.getKey();
  if (c == '*') {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter Year: ");
    int year = getData();

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter Month: ");
    int month = getData();

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter DayOfWeek: ");
    int day = getData();

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter Hours: ");
    int hour = getData();

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter Minutes: ");
    int minute = getData();

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter Seconds: ");
    int second = getData();

    RtcDateTime newTime = RtcDateTime(year, month, day, hour, minute, second);
    Rtc.SetDateTime(newTime);

  }
  
  delay(500);
}

int getData() {
  String container = "";
  lcd.setCursor(0, 1);
  while (true) {
    char c = customKeypad.getKey();
    if (c == '#') {
      break;
    } else if (isDigit(c)) {
      container += c;
      lcd.print(c);
    } else {
      //Nothing
    }
  }
  return container.toInt();
}

Did you try adjusting the potentiometer on the I2C backpack ?

Are you sure the address is 3F ?

TYSM! Sorry I didn't check the code myself for notes. I'm sorry for wasting your time. The only problem is it says "Date: 165/165/21" "Time 37:65:85"

You will probably need to set the RTC clock time.

I think so because now it says enter year but I don't know how to enter the year.

Edit: I just realized there's a picture in the same .zip that had the code. A picture about a keypad circuit but it didn't say you had to use a keypad in the video. The guy said it would take the time and date ffom your computer

This is what you have in your code:

ThreeWire myWire(11, 10, 12); // DAT, CLK, RST

You have wires on 6, 7, and 8 :open_mouth:

Note

Note that this module does not use I2C communication. Interfacing the DS1302 with a microcontroller is done using a synchronous 3-wire serial communication.

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