Need Help with I2C LCD Screen Issue - Displaying Weird Characters

Hello everyone. I am currently facing an issue with the LCD screen. When I upload the code, I notice strange characters appearing on the screen. I am in need of assistance. What steps should I take? All connections have been verified as good, yet the problem persists.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

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

void setup()
{
  // Initialize the LCD
  lcd.begin(16, 2);

  // Turn on the backlight and print a message.
  lcd.backlight();
}

void loop()
{
  lcd.clear();
  lcd.print("Hello World!");
  delay(1000);

  lcd.clear();
  lcd.print("I'm powered by");
  lcd.setCursor(3, 1);
  delay(1000);

  lcd.clear();


  lcd.clear();
}

For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. That may explain the weird characters.

You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.

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

Install the hd44780 library and try this code.

// hd44780 simple "Hello World" by c gounding AKA groundFungus
// hd44780 library see https://github.com/duinoWitchery/hd44780
// thehd44780 library is available through the IDE library manager
// if there are other devices on the I2C bus and one of those devices 
// has a lower I2C address than the LCD, that device could be detected 
// as the LCD. In that case simply put the LCD address in the constructor.

#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip

// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{
   lcd.begin(LCD_COLS, LCD_ROWS);
   lcd.clear();
   lcd.print("Hello World");
   lcd.setCursor(0, 1);
   lcd.print("Millis ");
}

void loop()
{
   updateLCD();
}

void updateLCD()
{
   static unsigned long lcdTimer = 0;
   unsigned long lcdInterval = 500;  // update 2 times per second
   if (millis() - lcdTimer >= lcdInterval)
   {
      lcdTimer = millis();
      lcd.setCursor(8, 1);
      lcd.print("       "); // overwrite old data
      lcd.setCursor(8, 1);  // reset the cursor
      lcd.print(millis());
   }
}

If you still have trouble, please post some clear photos of the LCD and backpack showing the solder joints and wiring.

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

Path to diagnostic sketch and library documentation.

I have already tried this method, but it doesn't work. I don't understand what the main issue is.



What method is that?

That statement conveys no useful information. Can you, please, elaborate?

Did you try the hd44780 library diagnostic sketch?

Run the I2CexpDiag diagnostic sketch that is included in the hd44780 library hd44780_I2Cexp i/o class examples.
It will test things and report any issues it finds.

--- bill

The LCD might have a different controller, the A00 variant... HD44780UA00... based on the katagana characters. I do not know if that mangles to output.

@touseefkhanx
start with an example form the library - not just any code you find in the internet.
For this Library
name=LiquidCrystal I2C
version=1.1.2
author=Frank de Brabander
maintainer=Marco Schwartz

you would need a lcd.init(); and not a lcd.begin(16,2)

Both character sets from the A00 and A02 ROM have the Latin letters at the same ROM position. So this will have no effect. By the way I guess the most common used variant is the A00 anyway.

Ah, ok. Could there be a dropped/added bit (LCD pin stuck high or low) to shift into the katagana range?

could yes.
is no.
see his picture - there is only one half size katagana character.
I assume its due to the wrong initialization (not fitting to his library). the display still could be in 8 bit mode.

The block (255) and the arrow (127) share lower seven bits.

The O (79) and the katakana (207) share lower seven bits.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.