I have just spent nearly a week trying to get a 4 pin LCD to work. In part my lack of experience was part of the problem in that I didn't place any confidence in what I was doing. No matter what I did with libraries, sketches, settings, nothing seemed to work.
I only sorted it this morning and wanted to share with you my experience in case other novices are going through the same frustrating learning experience.
The bottom line first....I bought 4 identical i2c lcd's. The problem lay with the 0x3F or 0x27 code. All 4 LCD's are identical in both layout and writing on them but only 2 work with 0x3F whilst the other identical LCD's used 0x27!!!!! I just happened to pick up one to use. It was only when on a hunch I swapped LCD and it worked. Then I tried all 4 and only 2 worked.
I contacted the supplier and they asked before I returned them if I would check that the small board was not pressed against the main lcd board. On inspection they were very tight so I levered them away but they still didn't work. I then copied the script and inserted both //LiquidCrystal_I2C lcd(0x27,16,2);
LiquidCrystal_I2C lcd(0x3F,16,2);
By uploading this code and isolating one of the settings I found two worked fine. Swapping them over and uploading the second option I found the 'defective' ones now worked and the first two stopped working. So the 4 LCD's identical in everyway operate in different settings!
Ironically if I had only purchased 1 I would have sorted it out within an hour. I must have just picked up the wrong one each time. Very frustrating. So aimed at other novices..the code below should work with the types I bought.....but you may need to disable one, then the other to find which works.
If I have posted this in the wrong area or not followed procedure's I apologise but below is the code that worked for me.
I must express some frustration that the industry produce identical LCD's that work on different code.
=============================================
/* FILE: ARD_LCD_HCARDU0023_I2C_Hello_World_Example.pde
DATE: 11/07/12
VERSION: 0.1
This is a simple example of how to use the Hobby Components I2C LCD module
(HCARDU0023). To use this module you will require the appropriate library
which can be downloaded from the following location:
http://forum.hobbycomponents.com/arduin ... ds_modules
This code also demonstrates the correct pin assignment for the LCD. When you
run this program you should see a greeting message appear on the display.
DEVICE PINOUT (SPI Interface):
PIN 1: GND
PIN 2: +5V
PIN 3: SDA - Connect to Arduino analogue PIN 4
PIN 4: SCL - Connect to Arduino analogue PIN 5
You may copy, alter and reuse this code in any way you like but please leave
reference to hobbycomponents.com in your comments if you redistribute this code. */
/* Include the SPI/IIC Library */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
/* Initialise the LiquidCrystal library. The default address is 0x27 and this is a 16x2 line display */
//LiquidCrystal_I2C lcd(0x27,16,2);
LiquidCrystal_I2C lcd(0x3F,16,2);
void setup()
{
/* Initialise the LCD */
lcd.init();
lcd.init();
}
/* Main program loop */
void loop()
{
/* Make sure the backlight is turned on */
lcd.backlight();
/* Output the test message to the LCD */
lcd.setCursor(0,0);
lcd.print("mikes-models.com");
lcd.setCursor(0,1);
lcd.print("*Hello everyone*");
/* Do nothing */
while(1);
}
I used the latest scripts used in this thread