I2C 20X4 2004 displays 2 lines with blocks only

I've been trying to display simple text using Arduino UNO/ Mega and 20x4 LCD Display. I've tried bunch of different libraries, but no success. the output is glowing screen filled 2 lines (1st and 3rd) with blocks.
Display Module Version is 2004A - V1.1
Microcontrollers: Arduino UNO and Arduino Mega 2560.

Pins(MEGA):
Ground - Ground
VCC - 5V
SDA - 20
SCL - 21

Code:

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

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

void setup()
{
  lcd.init();                      // initialize the lcd 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Hello, world!");
  lcd.setCursor(2,1);
  lcd.print("Ywrobot Arduino!");
   lcd.setCursor(0,2);
  lcd.print("Arduino LCM IIC 2004");
   lcd.setCursor(2,3);
  lcd.print("Power By Ec-yuan!");
}


void loop()
{
}

The blocks are a sign that the display is powered up. Run the I2C address scanner to check communications and that you have assumed the correct I2C address.

Please use code tags when posting code.

Install the hd44780 library by Bill Perry, available in the IDE's Library Manager.

Run File > Examples > hd44780 > ioClass > hd44780_I2Cexp > I2CexpDiag sketch.

Your display may be using a different I2C address, and/or a different arrangement for the connections between the I2C expander chip and the LCD controller.

1 Like

Have you tried adjusting the contrast pot?

+1 for the hd44780
library. It will make things easy by, automatically, finding the I2C address and LCD to I2C expander pin mapping.

Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Here is your original test code modified to use the hd44780 library. You can see how few changes are necessary. Works fine, tested on my Mega and 20x4 LCD.

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

//LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip

// LCD geometry
const int LCD_COLS = 20;
const int LCD_ROWS = 4;

void setup()
{
//lcd.init(); // initialize the lcd
lcd.begin(LCD_COLS, LCD_ROWS);
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Hello, world!");
lcd.setCursor(2, 1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0, 2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2, 3);
lcd.print("Power By Ec-yuan!");
}

void loop()
{
}

Edit: added loop().

I ran the address scanner and yes, it's the correct address

Check your soldering connections, by the picture seen there could be room for improvement.

1 Like

Thanks for the code. I Installed hd44780 by Bill Perry and ran your code. I'm getting this error while compiling the code. Do you know what the issue is?
ERROR:

Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\smits\AppData\Local\Temp\ccshRdgd.ltrans0.ltrans.o: In function `main':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Mega or Mega 2560.

Compilation Verbose:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\smits\OneDrive\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\smits\OneDrive\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\smits\OneDrive\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -vid-pid=2341_0010 -ide-version=10815 -build-path C:\Users\smits\AppData\Local\Temp\arduino_build_852773 -warnings=none -build-cache C:\Users\smits\AppData\Local\Temp\arduino_cache_880210 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose D:\ArduinoProject\helloWorld\helloWorld.ino
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\arduino-builder -compile -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\smits\OneDrive\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\smits\OneDrive\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\smits\OneDrive\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -vid-pid=2341_0010 -ide-version=10815 -build-path C:\Users\smits\AppData\Local\Temp\arduino_build_852773 -warnings=none -build-cache C:\Users\smits\AppData\Local\Temp\arduino_cache_880210 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose D:\ArduinoProject\helloWorld\helloWorld.ino
Using board 'mega' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr
Detecting libraries used...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\mega" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\sketch\\helloWorld.ino.cpp" -o nul
Alternatives for Wire.h: [Wire@1.0]
ResolveLibrary(Wire.h)
  -> candidates: [Wire@1.0]
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\mega" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\Wire\\src" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\sketch\\helloWorld.ino.cpp" -o nul
Alternatives for hd44780.h: [hd44780@1.3.2]
ResolveLibrary(hd44780.h)
  -> candidates: [hd44780@1.3.2]
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\mega" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-IC:\\Users\\smits\\OneDrive\\Documents\\Arduino\\libraries\\hd44780" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\sketch\\helloWorld.ino.cpp" -o nul
Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire\src\Wire.cpp
Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire\src\utility\twi.c
Using cached library dependencies for file: C:\Users\smits\OneDrive\Documents\Arduino\libraries\hd44780\hd44780.cpp
Generating function prototypes...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\mega" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-IC:\\Users\\smits\\OneDrive\\Documents\\Arduino\\libraries\\hd44780" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\sketch\\helloWorld.ino.cpp" -o "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\mega" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-IC:\\Users\\smits\\OneDrive\\Documents\\Arduino\\libraries\\hd44780" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\sketch\\helloWorld.ino.cpp" -o "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\sketch\\helloWorld.ino.cpp.o"
Compiling libraries...
Compiling library "Wire"
Using previously compiled file: C:\Users\smits\AppData\Local\Temp\arduino_build_852773\libraries\Wire\Wire.cpp.o
Using previously compiled file: C:\Users\smits\AppData\Local\Temp\arduino_build_852773\libraries\Wire\utility\twi.c.o
Compiling library "hd44780"
Using previously compiled file: C:\Users\smits\AppData\Local\Temp\arduino_build_852773\libraries\hd44780\hd44780.cpp.o
Compiling core...
Using precompiled core: C:\Users\smits\AppData\Local\Temp\arduino_cache_880210\core\core_arduino_avr_mega_cpu_atmega2560_94baf922c9d38d8316eaa2affe0e6dcb.a
Linking everything together...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega2560 -o "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773/helloWorld.ino.elf" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\sketch\\helloWorld.ino.cpp.o" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\libraries\\Wire\\Wire.cpp.o" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\libraries\\Wire\\utility\\twi.c.o" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773\\libraries\\hd44780\\hd44780.cpp.o" "C:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773/..\\arduino_cache_880210\\core\\core_arduino_avr_mega_cpu_atmega2560_94baf922c9d38d8316eaa2affe0e6dcb.a" "-LC:\\Users\\smits\\AppData\\Local\\Temp\\arduino_build_852773" -lm
C:\Users\smits\AppData\Local\Temp\ccjRhPli.ltrans0.ltrans.o: In function `main':
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
Using library Wire at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire 
Using library hd44780 at version 1.3.2 in folder: C:\Users\smits\OneDrive\Documents\Arduino\libraries\hd44780 
exit status 1
Error compiling for board Arduino Mega or Mega 2560.

The error is caused by lack of the loop function:

void loop() {}

Totally my bad. I did not copy the loop(). I did fix original posting of the code in reply#5 to include the loop() function. Sorry for the trouble.

No worries, I didn't check that either... the issue was with my poor soldering. and your code works fine now...

Thank you very much... It was soldering issue.. I reapply the soldering and now it's working fine...