[SOLVED] I2C LCD + 1-wire 4×3 Matrix keypad compatibility problem

Hi.

I am trying to get 16×2 I2C LCD to work with the 1-wire keypad code from here.
I got the code uploaded to the UNO and running without any error messages.1

The keypad sometimes works and sometimes doesn't.
I have no idea where the problem is.

I'm fairly new in arduino, but I understand a little bit the coding structures. So be patient if I don't understand all :wink:
The idea at the whole thing is to get the lcd and keypad working with as few pins as possible.

The LCD’s pins are connected to A5, A4, 5V and GND. The Keypad is connected to 5V, GND and A0 as the tutorial shows.

Here’s the code:

#include // OneWireKeypad Library

char KEYS[]= { // Define keys values of Keypad
'1','2','3',
'4','5','6',
'8','8','9',
'*','0','#'
};

/* Define Library :
OnewireKeypad <Print, #of buttons> Keypad(Serial, Char values, #Rows, #Cols, Arduino Pin, Row_resistor, Columns_resistor) */
OnewireKeypad <Print, 12 > Keypad(Serial, KEYS, 4, 3, A0, 4700, 1000 );

#include
#include

#define I2C_ADDR 0x27 // < #define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{
Serial.begin(9600);

lcd.begin(16,2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);

lcd.home();

lcd.print("Hello world...");
}

void loop()
{
Keypad.SetHoldTime(100); // Key held time in ms
Keypad.SetDebounceTime(50); // Key Debounce time in ms

if ((Keypad.Key_State() == 3)) { // not pressed = 0, pressed = 1, released = 2, held = 3

char keypress = Keypad.Getkey(); // put value of key pressed in variable 'keypress'
Serial.println("Keypad Key: ");
Serial.println(keypress); // Display value on Serial Monitor
while ((Keypad.Key_State())){} // Stay here while Key is held down

}
}

Thank you advanced for the replies.

Well thats interesting. I just checked out that link you posted and it goes to a tutorial page that is using my OneWireKeypad library, but yet it doesn't credit my name anywhere. Its almost as if they are passing it off as their own.

I will help you, but I need to take care of something.

Added:
Are you sure you have a solid connection to the analog pin and its not wiggling around?
What exactly is it doing? What does it show on the LCD?

**I got a response back from their support team and they removed the link and video to the tutorial. That was not my intention, a simple line that said "Created By: ..." would have sufficed. Now I feel like an ass :slightly_frowning_face:

Nevermind, I got another reply just moments after, saying they will reactivate the tutorial and any further libraries used (by anyone), will be credited to the original author. :slight_smile:

Andrew,
From what I can see there is no copyright or licensing specified in the actual library source code.
I would highly recommend that you update your source code to include any desired copyright notices and your desired licensing.

Specifying the licensing is very important.
The current code "as is" contains no grant of any license so technically nobody can use the code since under US law it is all copyrighted to the author (you) by default with no copy rights granted to any other party.

There are many licenses to choose from. Pick the one that offers your intended desires and provide the appropriate notices in the source code as well as in a licensing file like COPYING, license, license.txt, etc...

--- bill

Fixed. Went with MIT license.

Hi. Sorry about my few day inactiveness.

I just check the connections and they are fine.
When I wiggle the wires the lcd start to show special characters and
if I leave the wire alone it prints my text just fine.

The keypad itself sometimes works and sometimes doesn't.
It's really weird because when I'm trying to reset the Uno or
loading the code it has small chance to work.

I added picture of the wiring in to the attachments if that helps.

I have not read any docs for your keypad or libraries.

From your photo it looks as if the keypad returns an Analog voltage.
I do not see any wire connecting to 0V.

Your breadboard layout is neat and tidy. Well done.

David.

Oh. Apperently I forgot it when I was tidying up the breadboard.
Now the pull down resistor is set to the A0-pin but still not working.

Without a true photo, we have no idea what you are doing.

There should be a 1k0 to GND.

David.

The wiring is just like your picture shows.
I added the pull down resistor to ground just like you previously noted.

Pic is in attachments.

And is the lower blue negative bus connected to GND?

I am sure that the onewirekeypad library will work fine.
However, I have never used it myself.

Either correct the CODE in the original post or added a compilable sketch in a new message.
Then someone might build it for herself. And verify whether it works or not.

Without a clear understanding of what wiring or code you are using, it is unlikely that anyone would bother.

David.

Yes. The line is connected to GND.

Here's the edited code that I'm trying to get working.
The #-button doesn't change the value that should change the position of the Menu arrow.

Updated: I just found that under 'if(keypress == '#')', the switch statements values didin't match to the menuState -variable .

#include <OnewireKeypad.h> // OneWireKeypad Library

char KEYS[]= {  // Define keys values of Keypad
  '1','2','3',
  '4','5','6',
  '7','8','9',
  '*','0','#'
};

/* Define Library :
      OnewireKeypad <Print, #of buttons>
      Keypad(Serial, Char values, #Rows, #Cols, Arduino Pin, Row_resistor, Columns_resistor) */
OnewireKeypad <Print, 12 > Keypad(Serial, KEYS, 4, 3, A0, 4700, 1000 );

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

uint8_t menuArrow[8] = {  0x00, 0x08, 0x0C, 0x0E, 0x0E, 0x0C, 0x08, 0x00};

//Global variables
int menuState = 0; //Which menu is active
int menuPos = 1; //Position of the menu arrow

void setup()
{
  Serial.begin(9600);
  
  lcd.begin(16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);

  lcd.createChar(1, menuArrow);
  lcd.home();
}

void loop()
{
  Keypad.SetHoldTime(100);  // Key held time in ms
  Keypad.SetDebounceTime(50); // Key Debounce time in ms

  if ((Keypad.Key_State() == 3)) {  // not pressed = 0, pressed = 1, released = 2,  held = 3
  
    char keypress = Keypad.Getkey();  // put value of key pressed in variable 'keypress'

    //Serial.println("Keypad Key: ");
    //Serial.println(keypress);  // Display value on Serial Monitor

    if(keypress == '#') //#-button = Down-button
    {
        switch(menuState)
        {
            case 1:
              if(menuPos > 2)
              {
                  menuPos = 1;
              }
              else
              {
                  menuPos++;
              }
            break;
            case 2:
              if(menuPos > 3)
              {
                  menuPos = 0;
              }
              else
              {
                  menuPos++;
              }
            break;
            case 3:
              if(menuPos > 2)
              {
                  menuPos = 0;
              }
              else
              {
                  menuPos++;
              }
            break;
        }
    }
    else if(keypress == '*')
    {
      //*-button is Select
    }
    while ((Keypad.Key_State())){}  // Stay here while Key is held down
  }

  switch(menuState)
  {
      case 0:
           mainMenu(menuPos); //Main menu
      break;
      case 1:
           modeMenu(menuPos); //Mode menu
      break;
      case 2:
          settingsMenu(menuPos); //Settings menu
      break;
  }
  
}

void mainMenu(int menuPos)
{
    switch(menuPos)
    {
        case 1:
          lcd.setCursor(0,0);
          lcd.write(1);
          //lcd.print(menuPos);
          lcd.print("MODE           ");
          lcd.setCursor(0,1);
          lcd.print(" SETTINGS       ");
        break;
        case 2:
          lcd.setCursor(0,0);
          lcd.write(1);
          //lcd.print(menuPos);
          lcd.print("SETTINGS       ");
          lcd.setCursor(0,1);
          lcd.print(" MODE           ");
        break;
    }
}