What is an LCD screen?
They are everywhere! Lathes on trains, your alarm clock, intercoms. They are small screens that show simple information, such as letters or numbers. And they are really useful! Want to learn how to use one for your projects? Let´s do it! The LCD is a liquid crystal display screen that allows us to display information, such as messages or variables.
Something very important to remember when using the LCD screen, which is different to the rest of the components we have seen, is that it must always be connected to the same pins. It also has 4 cables to connect instead of 3… Keep calm! Don´t panic! Once explained, you will see how easy it is:
How to connect the LCD screen
Unlike the rest of the Mi Primer Kit de Robótica (My First Robotics Kit), the LCD has 4 pins to connect, instead of 3. These pins are:
- SCL: Serial clock
- SDA: Serial data
- VCC, supply voltage
- GND or mass
As a result, connecting up this component is more complex and must always be done the same way. Turn the LCD over to make it easier for you to read which pin is which. The GND, VCC and SCL must be connected to the corresponding A5 pins. We will also connect the SDA to the A4 signal pin, as shown in this diagram:
You can use this table to makes things clearer for you:
|NAME||PIN NUMBER||PIN COLOUR|
Be sure to pay close attention to the names of the pins, independently of the colour of the cables. The good thing is that the connection is always the same so once you have connected the LCD a couple of times, you will already be an expert.
|We will now give a couple of examples so that you learn how to use the LCD. You will need:
Got everything? Let´s get started:
How to display a message on the screen.
During this course, we´ve made lights shine in hundreds of ways, we´ve moved motors from one side to another, made beeps and even melodies… Now it´s time to say something! To do this, we will use the bitbloq blocks located in the LCD blocks tag.
The program displays this phrase on the LCD screen: “Dave, I´m afraid I can´t do this) …gulp! You will also have noticed that the LCD screen lights up. We will explain how it functions and how it can be used block by block. The first block tells bitbloq that we are going to use the LCD screen. Make sure you don´t forget this! Unlike the others blocks in bitbloq, this one has no other options and there is no need to tell it where we have connected the LCD, as it is connected at the same point. The second block: LCD: Set backlight enables us to switch the LCD screen light on and off. If you are in a well-lit area you won´t need it, but if you do need light or you want to make your projects even more impressive, then light it up! There´s only one thing to remember: the screen backlight uses more battery. The LCD: Print block enables us to print the message or variable that we want on the screen. If you select the Set text position? option, you can determine where your message starts to appear, i.e. which position, line and column of the LCD the first character will appear. Important! The first line and column of the LCD is NOT line 1 but rather line 0. This is because in programming, we usually index a vector or matrix starting with the number 0 rather than number 1. Some special characters cannot be used on the LCD.
How to display the number of times that we press the button on the LCD.
In this exercise, we will use the push-button and the LCD screen. We will display the number of times that we press the button.
To do this you will need to connect the components of the following form: The LCD to its fixed pins and the push-button to digital pin 11. The program in bitbloq would be:The program always creates a phrase with the number of times that we have pressed the button. As you can see, the LCD doesn´t only display messages, it´s also very useful for displaying variable values. In this exercise, we have used a new block: LCD clear. This block is very useful and it enables us to erase any previous messages from the screen. So now you know how to use the LCD screen. Although it might seem a bit complicated at first, you will soon see that it´s very simple to use, and most of all, it´s great fun! Soon you´ll be making any excuse to include it in all your projects, even though they don´t need it. Or at least that´s what we do…