Change SDA and SCL pins in LiquidCrystal_I2C.h using ESP8266

Hello community,
I'm new here, but I have some experince in C and C++. I'm trying to get startet with a 20*4 LCD Display with I2C bus and ESP8266. I've connected SCL to Pin D5(GPIO 14) and SDA to Pin D6(GPIO 12).
My problem is, that if I'm running this code, my LCD Display goes on, but only the first and third row are white and I can't display any characters.

Can someone help me with this issue?

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

LiquidCrystal_I2C lcd(0x27, 20, 4);

int SCL_pin = 14; //Pin D5
int SDA_pin = 12; //Pin D6

void setup() {
  pinMode(SCL_pin, OUTPUT);
  pinMode(SDA_pin, OUTPUT);
  digitalWrite(SDA_pin,LOW);
  digitalWrite(SCL_pin, LOW);
  Serial.begin(115200);
  Serial.println("Beginning");
  Wire.begin(SDA_pin ,SCL_pin);

  lcd.backlight();
  lcd.clear();
  lcd.setCursor (0,0); //
  lcd.print("Robojax LCD2004 Test"); 
  lcd.setCursor (0,1); //       
}

void loop() {
  lcd.print("Please Wait - 3");  
  lcd.setCursor (0,1); //
  Serial.print("Wait"); 
  delay(1000);        
  lcd.print("Please Wait - 2");  
  Serial.print(".");
  delay(1000); 
  lcd.setCursor (0,1); //      
  lcd.print("Please Wait - 1");
  Serial.println("."); 
  delay(1000);   

}// loop end

which LiquidCrystal_I2C library do you use?

where is lcd.begin()?

Or lcd.init(); depending on the library.

The 20x4 I2C LCD displays that I know about are all 5V devices. Are you supplying the LCD with 5V? The ESP8266 is a 3.3V device so will need level shifters on the I2C lines.

I know one libary only. The author ist johnrickman. GitHub - johnrickman/LiquidCrystal_I2C: LiquidCrystal Arduino library for the DFRobot I2C LCD displays

If you use the default I2C pins on the ESP8266 (SDA = pin 4 and SCL = pin 5) you can use the hd44780 library that is superior to any of the LiquidCrystal_I2C libraries. The hd44780 library will auto detect the I2C address and the I2C expander to LCD pin mapping.

You can probably change the I2C pins, but I am not sure how. Perhaps @bperrybap will see this and tell us how.

Here is a simple demo "Hello World" example code. There are many other examples that come with the library.

// hd44780 library see https://github.com/duinoWitchery/hd44780
// thehd44780 library is available through the IDE library manager
#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 = 20;
const int LCD_ROWS = 4;

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());
   }
}

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

I dont know why, but the arduino ide leaving and "Hard resetting via RTS pin..."

This happen with all Libaries and with the diagnostic file of the hd44780_I2Cexp class

After your file the ide give me

Wrote 272144 bytes (199622 compressed) at 0x00000000 in 18.3 seconds (effective 119.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

And with the diagnostic file

Wrote 283296 bytes (206474 compressed) at 0x00000000 in 19.0 seconds (effective 119.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

I saw the same thing when my ESP8266-7 finished uploading. Since I do not have rts connected to reset I just manually reset the ESP with the reset button when I see that when the upload is finished. Then the LCD displays "Hello World" on the top line and Millis and the count on the second line.

Is the LCD powered by 5V?

Yes the LCD is powered by 5V. How I disconnect Reset from rts?

sorry, i missunderstand,

How I connect rts to Reset?

What variant of the ESP8266 are you using? How is it connected to the computer (PC)?

I program my ESP8266 with a USB to serial adapter (FTDI) that connects, only, to 3.3V, ground, RX and TX. So there is no connection to the ESP8266 reset. So when programming is done I must press the ESP8266 reset to exit from programming mode and enter run mode.

I'm using the Nodemcu ESP8266 V1

It's connected via micro USB to the computer

I have never used the NodeMCU. My best guess is to just manually reset it when programming is done. What does that do?

nothing. after upload is finished, it's starting to blink continuously

What is blinking?

Sorry, the I2C pins are different on the NodeMCU. SCL is D1 and SDA is D2.

Post photos of the project showing the wiring, please, if it still does not work.
And the output from the serial monitor of the diagnostic program.

Just a clarification, John Rickman is not the author.
This library has a long and somewhat twisted past.

IMO, Rickman has made a wreck of the library by basically attempting to steal it and re-license it with a more liberal license (which is not allowed) after being given control of the github repository you referenced.
He first attempted to re-license it on github, then moved a copy over to gitlab.
Then renamed it on gitlab and now removed it from gitlab.
He has now abandoned the repo on github.
It has issues like some of the tags and version numbers in the library.properties are incorrect which confuses the IDE library manager.
Rickman no longer responds to any of my emails.
You can read a bit more about the history and the Rickman stuff in these issues:

--- bill

Not exactly sure what code you are running.
If you are using the hd44780 library, the first thing to run is the included diagnostic sketch I2CexpDiag.
It will print out diagnostic information to the serial console.
It will tell which pins to use for the i2c signals.

If you are using the hd44780 library hd44780_I2Cexp i/o class and run something like HelloWorld and the led on the NodeMCU blinks, it is blinking an error code.
If you get an error code, then you should run the diagnostic sketch, I2CexpDiag to have it try to figure out what the issue is.

As far as the "RTS" message goes, you shouldn't have to worry about it as autoreset should work to reset the board for downloading and to restart the board after downloading.

That said, there are some poor quality esp8266 boards, that do need some modifications to get autoreset to work. Without the modifications, you will have to press the button(s) to start a download of code and restart the board.

Also, some esp8266 boards can have issues if using a poor quality USB power supply. Some of the inexpensive 5v USB wall adapters have noisy power and it screws up the esp8266. Usually this can be see by the device having issues like reseting itself randomly or not even booting up.

--- bill

Bill thank you a lot for the explanation and the short history.
I run the diagnostic file, and it returned

⸮⸮⸮⸮⸮3⸮
********************************************************************
Serial Initialized
--------------------------------------------------------------------
I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
--------------------------------------------------------------------
hd44780 lib version: 1.3.2
--------------------------------------------------------------------
Reported Arduino Revision: 1.8.17
Arduino Board: ESP8266_NODEMCU_ESP12E
CPU ARCH: ESP8266 - F_CPU: 80000000
--------------------------------------------------------------------
SDA digital pin: 4 (GPIO4)
SCL digital pin: 5 (GPIO5)
--------------------------------------------------------------------
Checking for required external I2C pull-up on SDA - NO
Checking for required external I2C pull-up on SCL - NO
Checking for I2C pins shorted together - Not Shorted
********************************************************************
WARNING: I2C requires external pullups for proper operation
It may appear to work without them, but may be unreliable and slower
Do not be surprised if it fails to work correctly
Install external pullup resistors to ensure proper I2C operation
********************************************************************
--------------------------------------------------------------------
Scanning i2c bus for devices..
Total I2C devices found: 0
No I2C devices found

It says, that Pin 4 and 5 are default, but I want to use Pin 14 and 12. In some comments in the forum they say, that I can setup my I2C Pins with

Wire.begin(SDA, SCL); //SDA = 14; SCL = 12

Does this work with the hd44780.h library?

Hi
You cant change these pins they are not software driven but part of the fabric of the chip itself. Whats wrong with pins 4 and 5?

Ta

There is a special version of the Wire library that comes with the ESP8266 plug in (core) that allows one to specify the pins used for I2C.

I found, through experimentation, that preceding the lcd.begin() with Wire.begin(12,14) works (for me, anyway). My setup is an ESP8266-7 on a homemade breakout with a 2004 (20x4) LCD. Power and communication with the PC is provided by a USB to serial converter. The converter supplies 3.3V to the ESP and 5V to the LCD.

// hd44780 library see https://github.com/duinoWitchery/hd44780
// thehd44780 library is available through the IDE library manager
#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 = 20;
const int LCD_ROWS = 4;

void setup()
{
  Wire.begin(12,14);
  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 = 250;  // 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());
  }
}

The above code does work on my setup even though the diagnostic says that no LCD was found.  So YMMV. 

The diagnostic output for any interested party.

Serial Initialized
--------------------------------------------------------------------
I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
--------------------------------------------------------------------
hd44780 lib version: 1.3.2
--------------------------------------------------------------------
Reported Arduino Revision: 1.8.12
Arduino Board: ESP8266_GENERIC
CPU ARCH: ESP8266 - F_CPU: 80000000
--------------------------------------------------------------------
SDA digital pin: 4 (GPIO4)
SCL digital pin: 5 (GPIO5)
--------------------------------------------------------------------
Checking for required external I2C pull-up on SDA - NO
Checking for required external I2C pull-up on SCL - NO
Checking for I2C pins shorted together - Not Shorted
********************************************************************
WARNING: I2C requires external pullups for proper operation
It may appear to work without them, but may be unreliable and slower
Do not be surprised if it fails to work correctly
Install external pullup resistors to ensure proper I2C operation
********************************************************************
--------------------------------------------------------------------
Scanning i2c bus for devices..
Total I2C devices found: 0
No I2C devices found