Go Down

Topic: Problems with 16X4 LCD, I2C interface (Read 171 times) previous topic - next topic

markos00

I am helping my neighbor's son learn about programming and I thought an Arduino would be an easy and inexpensive way for him to learn. We have an interesting problem. Using a 16X4 LCD (I2C connected) we can't write to the first 4 characters of lines 3 and 4. Any help would be greatly appreciated.

Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,4);  // set the LCD address to 0x27 for a 16 chars and 4 line display

void setup()
{
  lcd.init();   // initialize the lcd
  lcd.blink_off();
 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("11111111");
  lcd.setCursor(0,1);
  lcd.print("22222222");
  lcd.setCursor(0,2);
  lcd.print("33333333");
  lcd.setCursor(0,3);
  lcd.print("44444444");
}

void loop()
{
}



floresta

#1
Sep 13, 2017, 02:34 pm Last Edit: Sep 13, 2017, 02:36 pm by floresta
There was a problem with the cursor positioning for 16x4 displays in earlier versions of the regular (parallel interface) LiquidCrystal library for years but I believe this has been corrected in later versions. 

If your particular LiquidCrystal_I2C library (there are many of them) was derived from one of those earlier libraries then it will have the same problem.

I suggest that you look into using the HD44780 library instead of the one you are using now.

Don

bperrybap

I suggest that you look into using the HD44780 library instead of the one you are using now.
I would also recommend using the hd44780 library ( but then I'm the author  :) ).

The hd44780 library package is available in the library manager.
You can read more about it here: https://github.com/duinoWitchery/hd44780

The hd44780 github page contains information about the library including installation instructions.
Use the IDE library manager to install it as it is easier and faster than trying to do it manually or using the zip install.
Also, by using the IDE library manager it ensures that the library is installed properly not to mention that you will also get the latest tested version of the library.

The library package includes support for several different h/w i/o interfaces used to communicate with the LCD module.

Each i/o interface has its own i/o class and its own set of examples.
The examples for each i/o class are grouped together in a directory by the name of the i/o class.
While all the examples are always available regardless of which h/w you actually have, using an example for an i/o class that is for different h/w will not work.
It will compile but obviously will not work.
The i/o class you will want to use for that backpack which contains an i2c i/o expander chip is hd44780_I2Cexp
That i/o class includes a diagnostic sketch (I2CexpDiag) which will test the i2c signals and internal RAM of the LCD module to verify that the the library is properly communicating with the LCD module.
It is useful to first run this sketch to verify that the library is properly talking to your backpack and LCD module.
Read the instructions in the sketch for how to run it and what to expect on the serial monitor.

After running the diagnostic sketch, you can run and look at other sketches for the hd44780_I2Cexp i/o class like the HelloWorld sketch to see what header files need to be included and how to declare the lcd object.


The hd44780 library contains additional capabilities not available in other libraries like
- return status to tell if API functions are not working correctly (usually do to i2c communication issues)
- ability to enable automatic line wrapping
- ability to read the display RAM or LCD status
- faster than other libraries as Arduino can run in parallel with LCD commands/instructions

I would highly recommend first running the diagnostic skech I2CexpDiag to verify that everything is working, then you can run and look at the other examples included in the hd44780_I2Cexp i/o class (like HelloWorld) to see what header files need to be included and how to declare the lcd object.


--- bill

markos00

Thanks to both of you. I was able to use those unusable positions. It's going to be a bit more complicated now, but at least it works.

bperrybap

Thanks to both of you. I was able to use those unusable positions. It's going to be a bit more complicated now, but at least it works.
It isn't complicated if you have library that properly supports that LCD geometry.
It will "just work".

Go Up