Keypad, RTC, and LCD display connection

Hi everyone,

I needed a bit information regarding connecting some components to the Arduino pro mini. I have already connected the keypad and RTC but now I want to connect the I2C display to it. I have seen the connection of RTC and the display on the same I2C bus, where time from the RTC can be display on the LCD. But I just wanted to know that would it work without any problem for the RTC or the display that when I press a key on the keypad and I can see it on the display? The response and guidance would be highly appreciated. Thank you!

It us doable.

Railroader:
It us doable.

Thank you. Will do it then. Just one question, in the sketch do I just need to specify the address for the LCD, for instance, lcd.begin(0x27, 16, 2) and the rest would be managed by the program?

Include an LCD library file in the beginning of the code.
Yes, lcd.begin...... looks good. Then use lcd.print for printing and lcd..... to position the cursor etc.

Thank you. Will do it then. Just one question, in the sketch do I just need to specify the address for the LCD, for instance, lcd.begin(0x27, 16, 2) and the rest would be managed by the program?

For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.

To install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.

The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results.

I fully agree with @groundFungus. Have a few snippets of used parts:

//I2C for LCD
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>

hd44780_I2Cexp mylcd; // declare lcd object: auto locate & config exapander chip

// LCD geometry
#define LCD_COLS 16
#define LCD_ROWS 2

.
.
.
.

void setup()
{
  Serial.begin(115200);
  bool  status = mylcd.begin(LCD_COLS, LCD_ROWS);
  if (status) // non zero status means it was unsuccesful
  {
    status = -status; // convert negative status value to positive number

    // begin() failed so blink error code using the onboard LED if possible
    hd44780::fatalError(status); // does not return
  }
  mylcd.clear();

Forum, maybe groundFungus, tipped me and I never experienced any trouble with my LCDs.

Railroader,
The begin() function in the hd44780 library will clear the display and turn on the backlight (if possible) .

Also, it is no longer necessary to invert the sign of the status value returned from begin() if you want pass it to fatalError()

--- bill

bperrybap:
Railroader,
The begin() function in the hd44780 library will clear the display and turn on the backlight (if possible) .

Really? I used one of the examples and never bothered about those things.

Also, it is no longer necessary to invert the sign of the status value returned from begin() if you want pass it to fatalError()

Eehh? Your suggestion looks like the logic reply is inverted? A misunderstanding?
— bill

Railroader,
I'm going by the code you posted in post #5
My comments are not merely suggestions. They are how the code currently works. (I am the author)
I just want to be clear for others who may be reading the thread since the code you posted in post #5 contains some things that users don't have to do and should not be doing.

You had this:

 mylcd.clear();

after you called begin() and the return status check.
This is not necessary as begin() clears the display before returning.

And then in the return status check, in the code you posted, you had this:

    status = -status; // convert negative status value to positive number

This line is from early versions of the library examples.
This is no longer necessary as fatalError() now accounts for negative status codes.
Users can, and should, pass the return value from begin() directly to fatalError()

--- bill

Okey, thanks. Nothing really wrong, only overdone.

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