Browse our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteria
How to work with an LCD using I2C in industrial automation
Working with LCD displays using industrial PLC I2C communication
A Liquid-Crystal Display (LCD) is a flat-panel display or other electronically modulating optical device that uses the light-modulating properties of liquid crystals combined with polarizers. It is very common to use them to get and upgrade electronic systems and display the results. In this blog we are going to talk about how to use them using the I2C communications of your PLC controller.
Any of our industrial Programmable Logic Controllers
A liquid crystal LCD (In this example we will be using a 16x2)
I2C interface module and I2C wire
How to connect it?
There are a lot of liquid-crystal displays in the market; in our case we will be using a 16x2 size DEM 16215 an HW-061 I2C interface module. For the industrial Arduino PLC we will use an M-Duino 50RRA+ WiFi/BT.
We will provide a 24V power to the PLC Arduino that will provide 5V to power the LCD. The LCD has 16 pins but we will only use a total of 12 as we will be work with a 4 bit data length interface. The pins that we will use for the characters are the ones 11 to 14.
Look for the I2C communication pins on the side of the controller Arduino since you will connect the SCL and SDA pins of the PLC to those of the I2C module. Then using the I2C wire you will connect the LCD display. Depending on your components, check out the documentation to know the pins to connect between the LCD and the I2C module.
Our industrial controllers are programmed using Arduino Ide, which is a C language based software. They can also be programmed using C directly but it is much easier working with Arduino IDE as it provides lots of libraries that helps in the programming.
Industrial Shields provides boards to program the PLCs for industrial automation. Basically you do not needed to define the pins and whether they are inputs or outputs since everything is automatically configured using the boards.
To install Industrial Shields boards, this link explains everything:
If you do not know the I2C address are you working with, check this post about how an I2C Scanner works. Knowing the address is the first step in order to work properly with this project.
To work properly, the Wire and LiquidCrystal_I2C libraries must be included.
First you have to call the following statement to create the LiquidCrystal class and set up the all the configurations. You will set the address of the I2C device and the number of rows and columns of your LCD. If the I2C address is unknown, you can check our post about how to know it.
LiquidCrystal_I2C lcd(0x3F, 16, 2);
When the display is turned on, it has a default configurations, however, resetting the Arduino does not reset the LCD, so you cannot assume that it is in that state when a sketch is started (and the LiquidCrystal constructor is called). To set all the internal settings, you should call the begin function before doing anything.
The I2C Liquid Crystal library provides a wide range of options to work with it. However, you will only use some of them since they are the most important functions to quickly start working. For more precise use, see all the documentation on the library GitHub.
The ones that you will be using are the following:
lcd.print(“ x ”): This will work as the print function, printing the text on the LCD screen.
lcd.clear(): It will clear the display and set the cursor to position zero.
lcd.setCursor(uint8_t col, uint8_t row): This will set the cursor to the position you have selected.
lcd.backlight(): It will turn on the LCD backlight.
A code will be shown below to see how to display some text on the LCD:
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);
// initialize the LCD
// Turn on the blacklight and print a message.