0:09
hello and welcome to controllers Tech
0:12
today I am going to cover a very
0:14
interesting LCD display in the past we
0:17
have covered LCD 1602 displays in
0:20
parallel mode and also via the i2c where
0:24
we connect the pcf8574 module at the
0:27
back of the display in the parallel mode
0:31
we need to connect at least 10 pins from
0:33
the MCU which includes four data pins
0:36
three control pins and rest for the
0:39
power this issue of connecting a lot of
0:42
pins is solved by soldering an i2c
0:44
converter module at the back of the
0:47
display it reduces the pins from 10 to 4
0:50
but the entire setup design becomes
0:53
bulky today I have a very interesting
0:56
display it is LCD 1602 but it comes
1:00
within built i2c mode so we have only
1:03
four pins for the connection and the
1:05
design footprint is that of a normal LCD
1:08
1602 display you can see the display and
1:12
the pins in the picture there are only
1:15
four pins VCC ground clock and
1:21
data this is how the display looks at
1:23
the back we only have four pins
1:26
available to connect to the MCU the pins
1:30
have the pitch of 2 mm therefore I have
1:33
soldered the wires directly to the pins
1:35
instead of connecting a header I am
1:38
connecting the display to the nucleo f44
1:42
6re the clock pin from the nucleo
1:45
connects to pin number three on the
1:47
display the data pin from the nucleo
1:50
connects to pin number four the pin
1:53
number two is the ground pin so connect
1:56
it with the ground of the
1:57
nucleo the display can be powered with 5
2:03
Vols I am using the 3.3 volts here you
2:08
can see the display is powered up here
2:11
you can see the string being displayed
2:13
on it this is from my test
2:17
project this one is black pixel color
2:21
background you can purchase it from ol
2:24
Express and if you are watching from
2:26
India you can purchase it from
2:27
controllers Tech dot store
2:30
the display is available in white
2:32
background and in yellow
2:35
background today in this tutorial we
2:37
will cover how to interface this display
2:41
32 although we can use the same old LCD
2:45
1602 i2c library with it but we still
2:48
need to modify that Library a little so
2:52
let's start the cube ID and create a new
2:56
project I am using F 446 re
3:00
let's give some name to the project and
3:04
finish I will set up the clock
3:07
first here I am bypassing the external
3:10
clock source so that it can use the
3:12
Crystal from the SD link the board has 8
3:16
MHz Crystal on it and we will run the
3:18
system at maximum 180 MHz clock all
3:23
right let's enable the i2c now I am
3:27
going to remap the i2c pins so that it
3:30
can be set as for the connection made
3:32
earlier the i2c is in the standard mode
3:35
with the clock speed at 100
3:38
khz that is all the configuration we
3:41
need to do click save to generate the
3:45
project as I mentioned earlier we can
3:48
use the I2 CCD library that we have used
3:51
in a lot of projects before here I have
3:54
the library files for the i2c
3:57
LCD let's copy the C file in the source
4:00
directory and header file in the include
4:12
directory let me change this inclusion
4:15
to main. so that it remains flexible
4:18
throughout different MCU series we use
4:21
these functions in previous LCD videos
4:24
and we will use them today also before
4:27
we modify the library source file let's
4:30
take a look at the display data sheet
4:33
the lcd1602 module used in this tutorial
4:39
31068 driver this driver uses the i2c
4:43
and SBI interface to connect to the
4:46
display though I have the i2c model with
4:49
me so I will focus on that part let's
4:53
just skip everything and jump to the
4:55
main part here is the i2c interface
4:59
protocol shown in the picture let's
5:02
check the slave address first we know
5:05
that the whole Library uses the 8 bit
5:07
slave address so we need to consider the
5:10
read WR bit also the slave address is
5:16
0111110 this makes up 7 C in
5:19
hexadecimal let's define the slave
5:22
address in the library now to send the
5:25
data or command to the display we need
5:27
to use the 16bit command command word
5:31
this command word consists of a control
5:33
bite and a data bite the most
5:36
significant bit Co is setor one if there
5:39
are more control bytes following the
5:41
current data bite but we will send one
5:44
command bite or one data bite at a time
5:47
so the co bit will be zero so let's
5:51
focus on this part where the co bit is
5:54
zero the control bite is now just used
5:57
to configure the RS bit when we send the
6:00
command the r bit will be kept zero and
6:03
while sending the data this bit will be
6:05
set to one let's modify the i2c LCD
6:09
source file according to this method the
6:12
LCD send command function takes the 8bit
6:15
command as the parameter let me delete
6:18
the previously written code first let's
6:21
define a 16bit command
6:24
word since this is a command the RS bit
6:27
in the control bite will be zero and
6:29
hence we will simply copy the command
6:32
bite now we have our 16bit Command word
6:35
ready to be sent to the display but the
6:38
i2c bus is 8 bit in size and hence we
6:41
need to send the 16bit command word as
6:43
two different bytes first we will send
6:47
the control bite followed by the data
6:49
bite let's define an array to store two
6:53
bytes we will store the control bite
6:56
first so shift the command word to the
6:58
right by 8 bit then store the command
7:01
bite at the next position in the
7:04
array the data has been stored so send
7:08
i2c the slave address is already defined
7:12
above we will send the command array two
7:15
bytes in total that is all we need to
7:18
send the command to the display now
7:21
let's see the LCD send data function the
7:24
function takes the data BTE as the
7:26
parameter Define a 16bit variable data
7:30
word since we are sending the data the
7:33
RS bit needs to be set to one so we will
7:37
set a one to the 14th position and then
7:40
add the data to it we will send the
7:43
16bit data word as two different bytes
7:46
first we will send the control bite
7:49
followed by the data bite let's define
7:52
an array to store two bytes we will
7:55
store the control byte first and then
8:00
the data has been stored so send it via
8:03
i2c that is all we need to do in order
8:06
to send the data bite to the LCD let me
8:10
write a proper method to clear the
8:12
LCD here we will simply send the command
8:15
1 hex to the LCD then wait for a few
8:18
milliseconds for the command to process
8:21
the initialization sequence of this LCD
8:23
is smaller than what we have used in the
8:26
previous one here you can see we just
8:29
need to wait for a few milliseconds and
8:31
then directly send the function set
8:34
display control and other
8:40
commands so we don't need all this part
8:43
actually this was used to initialize the
8:45
LCD in 4-bit mode but this particular
8:48
LCD is by default used in the 8bit mode
8:52
even if we leave this as it is it won't
8:54
have any effect on the
8:56
LCD here the commands are set as as per
8:59
the instruction given in the data sheet
9:02
the comments in front shows what
9:04
configuration is being used for each
9:06
command type you can read more about
9:09
these functions in the instruction table
9:13
for example the N bit in the function
9:15
set controls whether we are using two
9:19
line the fbit controls the font
9:22
type here you can see when the nbit is
9:25
high the display set to use two lines
9:30
also when the fbit low the 5x 8. format
9:34
used this makes the function set common
9:39
hex this is being used here you can
9:43
check the other commands as well and
9:45
modify them as per the need now let's
9:50
file here we will first include the
9:52
library header file now in the main
9:56
function initialize the LCD we will put
10:00
the cursor at the beginning of the first
10:01
row and send a number string to the
10:11
display then put the cursor at the
10:13
beginning of the second row and send an
10:15
alphabetical string let's build the
10:21
project we don't have any errors so
10:24
let's flash it to the
10:28
board here you can see the strings are
10:30
being displayed at their respective
10:33
positions so the display works just fine
10:37
I found this one even better than the
10:39
other lcd1602 with an attached PCF
10:43
module the response of this display is
10:46
way better than the other one now let's
10:49
display some numbers on the
10:51
LCD this could be useful if you want to
10:54
display some sensors value or voltage
10:57
levels let's define a 16bit number that
11:00
we want to display on the
11:02
LCD we need to Define an array to store
11:05
five characters this is because we are
11:07
going to convert the four digits so the
11:09
array should be able to store them in
11:12
format here in th main function after
11:16
displaying the strings let's wait for 2
11:18
seconds and then clear the
11:21
LCD now we will use the S print F
11:23
function to convert the number to the
11:25
character format and store it in the
11:30
now let's put the cursor at the fifth
11:32
column in the top row and send the array
11:40
LCD we need to include the standard IO
11:43
header file for the S print F to
11:48
work there are still some warnings
11:50
because the S print F takes the
11:52
character pointer as the
11:54
parameter so let's typ cast the array to
11:57
the character pointer all right let's
12:00
build and Flash the code to the board
12:03
you can see the number is being
12:05
displayed at the requested
12:07
position so the display works fine by
12:10
modifying the previously written i2c LCD
12:13
Library this is it for the
12:16
video I hope you understood the working
12:23
display the Indian viewers can purchase
12:26
it from controllers tech. store
12:30
today you can download the code from the
12:35
description leave comments in case of
12:37
any doubt keep watching and have a nice