Weird behaviour with lcd and a function

Are you using a Leonardo? It has I2C on pins 2 and 3 in addition to the dedicated SCA/SCL pins.

If you dont set those SCA SCL pins 2 and 3 will that be a problem? I would assume keypad would not work if they were default SCA SCL.

Sorry, I am new to Arduino programming, just trying to get by.

Another user reported random effects with a keypad library recently. It sounded like a floating pin problem. I send him a test sketch to get it working. Maybe it helps here also: Picking up stray voltage when handling 4+4 matrix keypad. What could be wrong? - #17 by 6v6gt

OK so I tried your code. That works fine by itself with the keypad. As soon as I init the lcd, button 4,5 or 6 it freezes. So I guess it has to be the lcd library I would think. I cant for the life of me figure out how that would cause it to freeze. Maybe an interrupt? Maybe change the address of the LCD?

I traced all the wiring and the buttons all map with continuity rows and cols. So it is not the wiring. I can display anything on the screen if I am not using the keypad.

Any ideas?

That is most odd. With an I2C display, once you've had it working (and therefore demonstrated that the I2C address in the code is OK) there should be nothing to go wrong.

When it all hangs, is the back light of the LCD the same brightness as before ?
Maybe try a separate stripped down "Hello World" type sketch just testing the display and see how far you get. It does look like that, at the moment, the display is the big issue.

OK well, someone mentioned this earlier.

It works on the Arduino uno. So I switched keypad pins on the Leonardo and it started working. It seems leonardo uses pin 2 and 3 for i2C by default?

Once I switched keypad pins off of 2 and 3 it worked.

Thanks for all your help. Sorry for the trouble......