Not able to print a string on LCD

I have seen in Arduino references and innumerable examples that
lcd.print(“STRING”);
prints the string at the cursor position.But in my case ,it is only printing the first character S on the display.
BTW, I’m using Arduino Uno and 16*2 LCD display.
Thanks for the help in advance !

Sketch.ino (3.33 KB)

I don’t have your LiquidCrystal_I2C library so I modified your code to use the (much better) hd44780 library.

The LCD works fine, displaying all characters using my Uno and 16x2 LCD.

//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> 

#if defined(ARDUINO) && ARDUINO >= 100  //If Arduino IDE version is 1.0 or higher
#define printByte(args)  write(args);   // printByte can be used instead of write 
#else
#define printByte(args)  print(args,BYTE);  //otherwise printByte can be used instead of print(args,BYTE)
#endif                                       // thus same command printByte(args) for all versions of Arduino 
// especially when write(args)has replaced print(args,BYTE) in the
// newer versions of Arduino.In this way same code will work on all versions

uint8_t bell[8]  = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4}; //unsigned integer of size equal to 1 byte i.e 8 bits uint8_t
uint8_t note[8]  = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0}; //array of uint8_t storing 5 pixels in a 5 x 7 dot character
uint8_t clock1[8] = {0x0,
                     0xe,
                     0x15,
                     0x17,
                     0x11,
                     0xe,
                     0x0
                    }; //  A 0 means pixel off and a 1 means pixel on.(after hex->binary conversion)
/* 00100                  |
   01010                 | |
   10001                |   |
   10001                |   |         represents an O
   10001                |   |
   01010                 | |
   00100                  |
*/
uint8_t heart[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
uint8_t duck[8]  = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
uint8_t check[8] = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
uint8_t cross[8] = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
uint8_t retarrow[8] = {   0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};


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

const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{
   //lcd.init();                      // initialize the lcd
   lcd.begin(LCD_COLS, LCD_ROWS);
   lcd.backlight();                 // backlight on

   lcd.createChar(0, bell);         //create custom characters using predefined arrays
   lcd.createChar(1, note);
   lcd.createChar(2, clock1);
   lcd.createChar(3, heart);
   lcd.createChar(4, duck);
   lcd.createChar(5, check);
   lcd.createChar(6, cross);
   lcd.createChar(7, retarrow);
   lcd.home();                     //Positions the cursor in the upper-left of the LCD

   lcd.print("Hello world...");
   lcd.setCursor(0, 1);
   lcd.print(" i ");
   lcd.printByte(3);
   lcd.print(" arduinos!");
   delay(5000);
   displayKeyCodes();

}

//display all keycodes
void displayKeyCodes(void)
{
   uint8_t i = 0;
   while (1)
   {
      lcd.clear();
      //    lcd.print("Codes 0x"); lcd.print(i, HEX);
      //    lcd.print("-0x"); lcd.print(i+15, HEX);
      lcd.print("C"); lcd.print("o"); lcd.print("d"); lcd.print("e"); lcd.print("s"); lcd.print(" "); lcd.print("0"); lcd.print("x"); lcd.print(i, HEX);
      lcd.print("-"); lcd.print("0"); lcd.print("x"); lcd.print(i + 15, HEX);
      lcd.setCursor(0, 1);  //placing cursor in second row
      for (int j = 0; j < 16; j++)
      {
         lcd.printByte(i + j); //printing 0-15,1-16,2-17.... when i=0 in hex characters,equivalent to lcd.print(i+j, HEX);
      }
      i += 16;

      delay(4000);
   }
}

void loop()
{

}

Install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.

The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results.

Since the code is not posted according to the forum guidelines and I do not intend to load it in my IDE, I cannot spot the problem, but this is a question that comes up on a regular basis - I just forget the actual reason! :astonished:


OK, so you just search for the answer and here it is! :grinning:

Also here.

And here.

And many others ...

normsbreaker:
I have seen in Arduino references and innumerable examples that
lcd.print("STRING");
prints the string at the cursor position.But in my case ,it is only printing the first character S on the display.
BTW, I'm using Arduino Uno and 16*2 LCD display.
Thanks for the help in advance !

Yep. It is a well known issue in an old version of that library. (like prior to Nov 13, 2015)
There are many versions of that library floating around out there.

The official version is available from the Arduino IDE library manager.
However, that library has not been very well maintained over the years and the maintainers have not had the technical kills to maintain it.
Recently, the github repository was handed off to a new person (johnrickman) who immediately copied it from github over to gitlab, changed its name a few times, illegally changed the license on it, then removed it from gitlab.
So basically, that library is not in a good state since it is no longer being maintained at all.

I reported the specific issue you are seeing years ago and the fix which is quite simple.
The code was fixed (back in 2015), but the maintainer originally didn't set the github tags correctly for a new release which confused the Arduino IDE library manager which broke the library.
The git tags and the library.properties files are still all screwed up so you can't use the library manager to get the updated code.

I would recommend that you switch to the hd44780 library.
It is easier to use, has additional features and is faster than LiquidCrystal_I2C

and... I'm actively maintaining it.

--- bill

Paul__B:
Since the code is not posted according to the forum guidelines and I do not intend to load it in my IDE,

Why not fix your browser so you can bring up the attached sketch in a code editor when you click on it?

I actually prefer attached code as it is much easier and quicker to get into a code editor than having to deal with inlined code.

--- bill

bperrybap:
Why not fix your browser so you can bring up the attached sketch in a code editor when you click on it?

Perchance because I do not want to? :astonished:

I wish to look at the code, determine the problem and correct it whilst using my browser, it is more direct and faster for me that way. While the formatting may frequently be terrible, I generally do not need the facilities of the IDE (or code editor which other than the IDE, I do not use) to do this. :grinning:

bperrybap:
I actually prefer attached code as it is much easier and quicker to get into a code editor than having to deal with inlined code.

I also speak on behalf of those who choose - for their own reasons - to deal with it on an iPad or similar tablet device where it is very difficult to manage "helper" applications for attachments. OK, I myself find tablets ridiculously clumsy for serious work without a real keyboard and even a laptop keyboard is a pain with its non-standard layout (and dimensions) but each to his own.

If it is in the post proper, then pretty much all browsers can handle it directly and adequately.

groundFungus:
I don’t have your LiquidCrystal_I2C library so I modified your code to use the (much better) hd44780 library.

The LCD works fine, displaying all characters using my Uno and 16x2 LCD.

//Compatible with the Arduino IDE 1.0

//Library version:1.1
#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h>

#if defined(ARDUINO) && ARDUINO >= 100  //If Arduino IDE version is 1.0 or higher
#define printByte(args)  write(args);   // printByte can be used instead of write
#else
#define printByte(args)  print(args,BYTE);  //otherwise printByte can be used instead of print(args,BYTE)
#endif                                       // thus same command printByte(args) for all versions of Arduino
// especially when write(args)has replaced print(args,BYTE) in the
// newer versions of Arduino.In this way same code will work on all versions

uint8_t bell[8]  = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4}; //unsigned integer of size equal to 1 byte i.e 8 bits uint8_t
uint8_t note[8]  = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0}; //array of uint8_t storing 5 pixels in a 5 x 7 dot character
uint8_t clock1[8] = {0x0,
                    0xe,
                    0x15,
                    0x17,
                    0x11,
                    0xe,
                    0x0
                   }; //  A 0 means pixel off and a 1 means pixel on.(after hex->binary conversion)
/* 00100                  |
  01010                 | |
  10001                |   |
  10001                |   |         represents an O
  10001                |   |
  01010                 | |
  00100                  |
*/
uint8_t heart[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
uint8_t duck[8]  = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
uint8_t check[8] = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
uint8_t cross[8] = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
uint8_t retarrow[8] = {   0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};

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

const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{
  //lcd.init();                      // initialize the lcd
  lcd.begin(LCD_COLS, LCD_ROWS);
  lcd.backlight();                 // backlight on

lcd.createChar(0, bell);         //create custom characters using predefined arrays
  lcd.createChar(1, note);
  lcd.createChar(2, clock1);
  lcd.createChar(3, heart);
  lcd.createChar(4, duck);
  lcd.createChar(5, check);
  lcd.createChar(6, cross);
  lcd.createChar(7, retarrow);
  lcd.home();                     //Positions the cursor in the upper-left of the LCD

lcd.print(“Hello world…”);
  lcd.setCursor(0, 1);
  lcd.print(" i “);
  lcd.printByte(3);
  lcd.print(” arduinos!");
  delay(5000);
  displayKeyCodes();

}

//display all keycodes
void displayKeyCodes(void)
{
  uint8_t i = 0;
  while (1)
  {
     lcd.clear();
     //    lcd.print(“Codes 0x”); lcd.print(i, HEX);
     //    lcd.print("-0x"); lcd.print(i+15, HEX);
     lcd.print(“C”); lcd.print(“o”); lcd.print(“d”); lcd.print(“e”); lcd.print(“s”); lcd.print(" “); lcd.print(“0”); lcd.print(“x”); lcd.print(i, HEX);
     lcd.print(”-"); lcd.print(“0”); lcd.print(“x”); lcd.print(i + 15, HEX);
     lcd.setCursor(0, 1);  //placing cursor in second row
     for (int j = 0; j < 16; j++)
     {
        lcd.printByte(i + j); //printing 0-15,1-16,2-17… when i=0 in hex characters,equivalent to lcd.print(i+j, HEX);
     }
     i += 16;

delay(4000);
  }
}

void loop()
{

}




Install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.

The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping. 

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results.

Thank You @groundFungus, @Paul__B and @bperrybap for the help provided. The issue has been resolved.
I will try to abide by the forum guidelines the next time.