In this lesson we will be learning how to write on an LCD module.

Liquid crystal displays

An LCD (liquid crystal display) is a thin and flat screen made up of several coloured or black and white pixels located in front of a light source or reflector. It is often used in battery-powered electronic devices, which use very small quantities of electrical energy. It allows information to be given to the user on what is happening in the program, which is very useful and can make projects even more interactive. In this lesson we will be using an I2C/SPI LCD module. With this module, only 2 signals are required to display information when controlled by I2C, or 3 if controlled by SPI. This LCD in particular has 20 columns x 4 rows, allowing 80 characters to be written on the screen (with the library that we will be using, only ASCII characters can be used).


Preparing the project

To program the LCD module, we will need to use a library. What is a library? Simply a series of functions that someone has written for us to make our work easier. This means that, instead of having the values in the pins, we will have high-level functions such as lcd.print(“hola”) that do the dirty work for us. The library used to control the LCD is called liquidCrystal. However, if the Arduino library is designed for LCDs, they will need 6 signals in order to be controlled. Thanks to the IIC/SPI module, the LCD in this lesson only needs 4, which is why BQ has modified the library so that it functions correctly.

As with previous lessons, we will be using Codebender as a development environment. To be able to use the library, we will need to create a new project and add the included files to the library that we have just downloaded. We show you how it´s done in this video:

Once we have our project ready with those four files, we will connect the LCD and program it.

Connecting the LCD module

The LCD module has 4 pins for connecting (in IIC mode). These pins are:

  1. SCL: Serial clock
  2. SDA: Serial data
  3. VCC, supply voltage
  4. GND or mass

This component must always be connected as shown (so that it´s compatible with the bqLiquidCrystal library – but if you use another library it doesn´t have to be like this).

SCL A5 Blue
SDA A4 Blue
VCC A5 Red
GND A5 Black

Hello LCD

Now we have the necessary library and everything is connected. We will start off with Hello World! (¡Hola Mundo!), displaying the text Arduino Course on the screen. Here you have the code:

We´ll do things bit by bit.

Declaring the LiquidCrystal object

The LiquidCrystal variable type will enable us to control the LCD module. So we will start off with a global variable of this type, which we have called lcd in this case. We will also start off with value 0. From now on, all operations on the LCD will be type.

Starting up the LCD

As we have done before, we will use the global variable as a means to perform an action once, and once that is done, we start writing.

  • lcd.clear(). We clear everything from the screen, but it´s not required as we have already done it with the setup()
  • lcd.setCursor(0,0). We state which column and row we want to write in, in this case row 0 and column 0, which means the top left corner.
  • lcd.print(“Curso de Arduino”). Finally, we will write the text we want to print on the screen.

If we compile and upload this program to the board, this will be the result:


Moving text across the screen

How about if we wanted “BQ” to appear moving across the screen? I will leave you the code here so that you can try it out yourself, analyse it and if you want, you can change it to make it display something else.

2 thoughts

Comments are closed.