We make a lot of ESP8266 based projects, and although most of them are for IOT and web based projects, it's handy to have a local LCD screen to see what's happening.
I2C is perfect for I/O devices without a lot of available I/O pins, as it only uses two I/O pins. These LCD modules are common, but have a variety of addresses, so let's get you communicating with the ESP8266, connect the screen to the esp8266 module, and run a I2C address scanner to see what address we need to communicate with. The following steps will get you sorted.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Add the ESP8266 to Your Arduino IDE
Before you can use the ESP8266 with the Arduino IDE, you need to add support for the ESP8266 (seen in the "additional board manager url" field above). Adafruit offers a comprehensive tutorial for this step at https://learn.adafruit.com/adafruit-feather-huzzah...
Step 2: I2C LCD Library
You will need to make sure you get the I2C LCD library from https://github.com/marcoschwartz/LiquidCrystal_I2... , otherwise the code won't upload. You may get a warning that the library is only certified for AVR's, but it still works fine on the ESP8266.
Extract the files, and copy them to a "I2C LCD" folder inside the libraries folder inside your sketch folder (specified in the "preferences - sketchbook location" as seen above).
Step 3: Connect the LCD
The ESP8266 and the LCD module have clearly labeled pins, so connect as follow:
SCL - SCL
SDA - SDA
VCC - USB (yes, it's 5v, but the I2C on the 3.3v ESP8266 does not complain)
Gnd - Gnd
Reminder: VCC has to be 5v unless you have a 3.3v compatible display. No level shifting necessary for the I2C pins.
Step 4: Scan the I2C Bus for the Correct Address
I2C is a two wire protocol that allows multiple devices to be used, with only two pins used on the microcontroller. This is accomplished by setting an address on each device on the bus. Not all I2C LCD's use the same address.
There is address scanner code you can run that will report the address any I2C devices connected. You can get the code for the I2C scanner at https://pastebin.com/R3AptATQ
Uploading that sketch showed me in the serial monitor that I was using address 0x27, so I loaded the following sketch and made sure that it was trying to communicate at the correct address, and screen size. Common screen sizes are 20x4, and 16x2.
LiquidCrystal_I2C lcd(0x27, 20, 4);
Step 5: Outputting Text on Your LCD
I have included a sample sketch to show you how to output text on your LCD.
You can get the code for the I2C LCD at https://pastebin.com/LW261xq1
The key to getting output where you want it is that the column is set first, then the line number, both start at 0.
// Move the cursor 5 characters to the right and
// zero characters down (line 1).
// Print HELLO to the screen, starting at 5,0.
Step 6: Additional Information
You can learn more about using the ESP8266 with the Arduino IDE at https://learn.adafruit.com/adafruit-feather-huzza...
And learn how to control your ESP8266 with the Amazon Alexa / Echo platform at http://arduinotronics.blogspot.com/2018/03/control...