Introduction: I2C LCD on NodeMCU V2 With Arduino IDE
In this quick instructable I'll show you how to lunch LCD with I2C Serial Adapter on NodeMCU v2 using ArduinoIDE and available libraries.
Step 1: Required Parts and Software
Hardware:
1. NodeMCU v2
2. 16x2 LCD Display with i2c Serial Interface Adapter Module
3. Some wires, USB for power supply and sketch uploading
Software:
1. ArduinoIDE - https://www.arduino.cc/en/main/software
2. LiquidCrystal_I2C library - https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
Step 2: Hardware Setup
Preparations:
When you order LCD from Ali/ebay you can solder 16 pin headers to LCD display in order to avoid 'wiring mess' when connecting to serial adapter
Setup:
- Place LCD display and Serial Adapter on bread board next to each other
- Connect adapter's SCL pin with NodeMCU D1 pin
- Connect adapter's SDA pin with NodeMCU D2 pin
- Connect adapter's GND, VCC pins with NodeMCU GND, Vin accordingly - here I need to explain one thing. Basically you should connect LCD display to 5v source but NodeMCU only has 3.3v outputs so the LCD is pretty dark. If you provide LCD with external 5v source you'll need to use logic level converter because it will not work. Here I used some hack using USB provided power that is bypassed to Vin. It's 5V but it works :)
Step 3: The Sketch
Preparations:
- Install ArduinoIDE
- Add NodeMCU support - nicely described here.
- Add LiquidCrystal_I2C library - please use instructions provided by author. Installation from AdruinoIDE will add outdated version
The Sketch:
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
//Use predefined PINS consts
Wire.begin(D2, D1);
lcd.begin();
lcd.home();
lcd.print("Hello, NodeMCU");
}
void loop() { // do nothing here }
---------------------
Upload the sketch and you're done!
13 Comments
Question 4 months ago on Step 1
5 months ago
Please, I am using a 3v NodeMCU. My LCD lights come on but I tried uploading the code but it doesn't display. I adjusted the potentiometer/contrast but still no text displayed. I need your help please
Question 2 years ago on Step 3
Hey!
I tried this code, connections ,I also included the LCD library mentioned but then I am getting this error. Kindly get back ASAP!
Thanks:)
Answer 2 years ago
Try
lcd.init();
2 years ago
What library should I include?
2 years ago
1.//**************Ejemplo para Placa NodeMcu V3 Lolin Version 0.1*****************
// By Godbad , Colombia
#include <Wire.h> // Libreria para configurar los puertos Base
#include <LiquidCrystal_I2C.h> //Libreria para manejar LCD
LiquidCrystal_I2C lcd(0x27, 16, 2); // Protocolo 0x27 para este tipo de LCD, 16 para la cantidada de caracteres por linea , cantidad de Lineas en el LCD que son 2
/*
Ejemplo de nuestro LCD
X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X
X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X
*/
void setup()
{
pinMode(2, OUTPUT);
Wire.begin(D2, D1); // D1 = SCL | D2 = SDA
lcd.init(); // Iniciamos el LCD
lcd.backlight(); // Prendemos la Iluminacion del LCD
lcd.clear();
}
void loop()
{
lcd.clear();
digitalWrite(2, LOW);
delay(1000);
digitalWrite(2, HIGH);
delay(1000);
lcd.setCursor(0, 0); // Cursor0 , Linea0
lcd.print("Linea1");
lcd.setCursor(0, 1); // Cursor0 , Linea1
lcd.print("Linea2");
delay(1000);
}
2 years ago
work find, ,but for the 5V power , I use the VU pin ( 5V ) and not Vin ( 0.3v for me plugged on usb )
Question 2 years ago
What if I'm using PCF8574 at pin D1 and D2 with address 0x20? Can I use pin D3 and D4 for LCD? If so, what address should I use?
2 years ago
How can I go for the buttom line to write another thing? Thanks ;)
3 years ago
If I didn't do a hack, the usual wiring schematic would be like:
SDA (LCD) →TTL converter from 5V to 3.3V → D2.
SCL (LCD) → TTL converter from 5V to 3.3V → D1.
Vcc (LCD) → 5V (of another source).
Gnd (LCD) → Gnd (of the same other source).
Do you agree?
3 years ago
What if I wanted to power the NodeMCU (I have ver 3 by the way) from 3.3V and Gnd, will NodeMCU Vin still work if connected to LCD Vcc pin?
Thanks anyway.
Reply 3 years ago
Would it be possible to use VU pin instead of Vin?
4 years ago
Thanks for sharing :)