I am using nodemcu esp8266 with LCD for the first time and I'm unable to make it work. It lights the background but it does not show any text.
LCD Address: 0x27
sda: d4
sdl: d3
vnn: vin
gnd: gnd
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); //Set LCD Address 0x27 for LCD1602 (16 chars 2 line display)
void setup() { // put your setup code here, to run once:
lcd.begin(0,2); // SDA-0 (GPIO D3 = 0), SCL-2 (GPIO D4 = 2)
lcd.backlight();
lcd.print("Hello world");
}
void loop() {
}
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. 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.
Hi,
run the I2C scanner and see if it is being recognized by ESP.
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup()
{
Wire.begin(0,2); // ESP8266
// Wire.begin(); // Arduino
Serial.begin(115200);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
@ayes
Upload the following tested codes using ESP8266-based NodeMCU and 16x2-LCD with 5V supply at the Vcc-pin of LCD (it will not work with 3.3V supply).
The following sketch uploaded in ESP8266-based NodeMCU does recognize my 5V-LCD at Slave Address 0x27.
#include <Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin(D4, D3);
Serial.println("I2C search");
Serial.println("-------------------------");
Wire.begin();
int i2c = 0b0000000;
for (int i = 0; i < 127; i++)
{
Serial.print("Search at [");
Serial.print(i2c, HEX);
Serial.print("]: ");
Wire.beginTransmission(i2c);
byte busStatus = Wire.endTransmission();
if (busStatus == 0)
{
Serial.println("FOUND!");
while(1);
}
else
{
Serial.println("not found");
}
i2c++;
}
}
void loop() {}
Search at [22]: not found
Search at [23]: not found
Search at [24]: not found
Search at [25]: not found
Search at [26]: not found
Search at [27]: FOUND!