Connecting the LCD through I2C board

Similar tutorials are all over the internet, this one is here so that I can have a compatible setup between all the devices in the IoT project, the way those 2 boards (The LCD and I2C board) are very popular, and are connected in more or less the same way in all tutorials, but since you are here, might as well make it as simple and complete as possible.

LCD displays require a lot of connected digital pins to work, but this is easily solved with a very cheap LCD-I2C board that connects to my 1602 (16×2) LCD display (Or 2004 20 x 4 LCD modules) with its 16 pins on one end, and connects to your microcontroller (ESP8266, ESP32, Or Arduino, etc…) via 2 I2C pins (SDA/SCL)

The LCD I2C Interface Adapter board is based of a popular 8-bit, remote I/O expander for the I2C bus namely the pcf8574T / ABX919… A remote expander can function as an LCD driver, but it also works for many other purposes, but that is beyond the scope of the simple instructions presented here, here we are interested in driving an LCD screen

The I2C address of can be set by setting the available solder points for addresses in the range of 0x20 – 0x27.

One thing you may want to know is that the jumper at one side of the nameless I2C board is for the LED backlight ! it can be fed through a separate power supply (Remember to combine the ground pins).

In this example, I am using an ESP8266 on a NodeMCU board.

Power

The ESP8266 and the ESP32 are 5V tolerant on the data pins (Proof here), So, because the linear voltage regulator on the ESP8266 NodeMCU board does not have a heatsink, we will be connecting the screen directly to the 5V power source, why burdain the small regulator with the screen !

So, on my I2C board, I connect the GND and VCC to the external power supply (Don’t power the board via USB and connect to the VIN, this is not how it works, VIN is for voltage input, not for output)

So, on my board, the geekcreit doit esp12f devkit v3 (In arduino studio, it is compatible with NodeMCU 1.0 – ESP-12E Module)

The data pins are connected as follows
SDA – D2 – GPIO-04
SCL – D1 – SPIO-05

You are done with this, now, how to print to the screen !

the first step is to find the I2C address, my board provides addresses in the range of 0x20 – 0x27. without soldering anything, the address is probably 0x20, but if not, we can figure it out.

To figure out the address of your LCD display, use the following code

#include <Wire.h>
void setup() {
Wire.begin(4, 5); // SDA, SCL
Serial.begin(115200);
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices = 0;
Serial.println("Scanning...");
for(address = 1; address < 127; 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++;
}
}
if (nDevices == 0) Serial.println("No I2C devices found\n");
else Serial.println("done\n");
delay(5000);
}

Leave a Reply

Your email address will not be published. Required fields are marked *