Dear friends welcome to another Arduino Tutorial!
Today we are going to learn how to use this 20x4 character LCD display with Arduino.
There is a lot to cover so let's get started!
Hello guys, I am Nick and welcome to educ8s.tv a channel that is all about DIY electronics
projects with Arduino, Raspberry Pi, ESP8266 and other popular boards.
Subscribe to the channel now if you don't want to miss any future videos.
In this video we are going learn how to use this inexpensive character LCD display with
Arduino.
After we learn how to use the display we are going to build something useful.
A simple real time clock.
Let's start.
I discovered this display some time ago on Banggood.com.
You can find a link for it in the description of the video.
It drew my attention because it is inexpensive, it costs around 7$, it is big, and it uses
the I2C interface.
Since it uses the I2C interface it is extremely easy to use with Arduino.
We only need to connect two wires.
I needed a big, easy to connect display for prototyping some projects and the only display
that was using the I2C interface was this tiny OLED display.
Now we have a big I2C display to use in our projects!
Great!
As you can see, the display is really big compared to the displays we were using so
far.
It can display 20 characters per line, and it has 4 lines.
It cannot draw graphics, just characters.
At the back we can find a small black board soldered on the display.
On the black board there is a trimpot which controls the contrast of the LCD.
Let's now see how to connect the LCD to an Arduino Uno.
As we said before we only need to connect 4 wires.
I connect GND to Arduino GND, Vcc to Arduino 5V, SDA pin to Analog Pin 4 on the Arduino
Uno and lastly SCL pin to Analog Pin 5 of the Arduino Uno.
That's it!
Our display is ready to use.
We now need to download the library for the display.
I am using the NewLiquidCrystal library.
You can find a link for the library in the description below.
After installing the library we are ready to write our first sketch.
We are going to develop a simple sketch that is going to display some text on the display.
Let's see how to achieve that.
As you can see the code of this first project is very simple.
All we need to do is to include 2 libraries, and set the I2C address of the display here.
Now we can initialize the display, we set the cursor to the desired position and print
some text.
The setCursor command works like this.
The first argument is the column and the second one is the row.
So, in this line of code we tell the cursor to move to column 3 and row 0 and with the
following command we print the text "Hello YouTube".
We do the same for all the other lines of text.
As you can see using the display is very easy, so this display is great for quick prototyping
and ideal for beginners to Arduino.
Let's now build a more useful project with this display.
Let's connect a DS3231 RTC real time clock.
The DS3231 real time clock module also uses the I2C interface so we need to use a small
breadboard in order to connect both the display and the real time clock to the I2C pins of
the Arduino.
We are going to use the top power rails of the breadboard as the I2C bus.
In an I2C bus we can connect up to 128 devices.
We connect the blue rail to analog pin 4 on the Arduino Uno which is SDA, and the red
rail to analog pin 5 which is SCL.
Now we connect SDA, and SCL pins of both the display and the Real Time Clock module to
the I2C bus.
We also connect power and we are ready to write the code.
You can find the schematic diagram of the project in the description below.
If we now load the code, we can see the real time clock in action.
It displays the date and the time and a frame around them.
Let's take a quick look at the code now.
In this example we are using one more library for the Real time clock module.
We are using the excellent DS1307RTC library which works with DS3231 real time clock as
well.
The code is simple.
In the setup function we initialize the display and then we create some characters.
We can create our own characters if we wish using the createChar function.
It works like this.
Each character can be 5pixels long in width and 8 pixels in height.
In order to create a custom character we need to create a new byte array like this one.
This character is a vertical line.
This custom character was needed in order to draw the frame on the display.
Watch this.
Do you see the pattern?
These are the pixels of the character, and the ones are the lit pixels!
So, if you need to design a custom character we just have to turn the zeros to ones.
I have created 5 custom characters.
All these characters are needed for the frame.
Now that we have created the byte arrays for each character we need to call the command
createChar.
Up to 8 custom characters are supported and each one is numbered from 0 to 7.
So, when we call the createChar command, we create a new custom character, we give it
a number from 0 to 7 and then we define the byte array with the character data.
Now we can display this character on the display using the command write.
So if we use the command lcd.write(0) we display the first custom character.
Back to the code now.
After creating the custom characters we print the frame using the lcd.print command and
the command write to print the custom characters.
In the loop function, once a second, we get the date and time from the Real Time Clock
and we print it on the display using the lcd.print command.
If the time on the display is not the correct one, you have to set the time to the Real
Time Clock.
It is very easy, go to File -> Examples -> DS1307RTC and load the SetTime example.
Upload this program to your Arduino while the Real Time clock is connected to it.
The program will get the time from your computer and it will set the time to the DS3231 module.
Now, load our program once more and the correct time and date will appear.
As always you can find the code of the project in the description of the video below.
As a final thought, I really like this display.
Even though it can only display characters, it is extremely useful because it big and
very easy to use.
If you need a big, low cost display or a display for quick prototyping look no further.
I would to hear your opinion about this display.
Do you find it useful and if so, what kind of projects are you going to build with one
of these?
Please post your comments in the comments section below and don't forget to like the
video and share it with your friends if you find it interesting!
Also consider subscribing to the channel and do click that bell or YouTube might not show
you updates as new videos come out.
If you are going to be shopping for parts check out the affiliate links from the video
description.
That's it for today guys, thank you very much watching, I will see you in the next one!
[ Translating these subtitles? Add your name here! ]
Không có nhận xét nào:
Đăng nhận xét