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
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.