0:09
hello and welcome to controllers Tech
0:12
this is the seventh video in the AVR
0:14
series using the explained mini
0:16
development board and today we will
0:18
continue with the i2c Master Series in
0:22
the previous video we saw how to connect
0:24
to the pcf8574 slave device and control
0:28
some LEDs in the output of the device in
0:32
today's video we will see how to use the
0:37
i2c lcd1602 actually requires a minimum
0:42
of eight pins to be connected to the MCU
0:44
but with the help of the pcf8574 module
0:48
the pin requirement goes from 8 to only
0:51
two we will see later in the video how
0:54
the LCD is connected to the module and
0:56
how the module connects to the
0:58
MCU I have already prepared a library
1:01
for the LCD which uses the i2c master
1:05
code that we wrote in the previous
1:07
videos few months ago I released a video
1:10
which shows how I wrote this
1:13
Library the video covers the LCD
1:15
functions although it is made for a
1:17
different MCU but you should watch it if
1:19
you want to understand this
1:22
Library I used the same Library across
1:25
different MCU series and it works
1:27
without any issue for example example
1:30
here is the library for the SDM 32
1:34
controllers you can see that it is
1:36
exactly the same Library the only change
1:39
is the i2c function that is used to send
1:43
data here in the stdm 32 Library I use
1:47
the whole Library function to send the
1:49
i2c data whereas in the AVR Library I am
1:52
using the i2c right function we defined
1:56
videos the function takes the slave
1:59
address data and the size as the
2:02
parameter and that is what we pass in
2:05
library there is one more change in the
2:07
library and that is the delay
2:15
function here is how the module is
2:19
LCD the 16 pins from the module connect
2:23
to the 16 pins of the LCD and the clock
2:25
and data pins connect to the
2:28
MCU the data pin is connected to the pa1
2:32
and the clock pin is connected to the
2:35
pa2 in this video I will only show how
2:37
to use the LCD library and as I
2:40
mentioned if you want to understand how
2:42
the library was written please watch the
2:45
video Linked In the description of this
2:47
one we will continue with the same
2:50
project which we used in the previous
2:53
video Let's copy the LCD Library files
2:58
folder now we need to to include the
3:00
existing items to the project so include
3:03
the header file and source file in the
3:12
folders I have already added the
3:15
necessary inclusions like the Avo header
3:18
file and the i2c master header file now
3:22
let's use the library and send some data
3:25
LCD include the i2c LCD header file in
3:30
file if you check the LCD initialization
3:33
function here you can see the i2c is
3:36
already initialized in it let's add a
3:39
delay of 100 milliseconds so the i2c can
3:43
initialize properly now remove the i2c
3:46
initialization from the main function
3:49
and we will add the LCD initialization
3:51
function here now let's prepare the data
3:54
to be displayed on the
3:56
LCD I will send these two buffers
4:01
the LCD put cursor function is used to
4:03
put the LCD cursor at a specific
4:09
1602 we have the two rows 0 and 1 and 16
4:13
columns 0 to 15 let's put the cursor on
4:17
the zeroth row and zeroth column to send
4:21
the data we can use the LCD send data
4:24
which is used to send a single character
4:26
to the display or LCD send string which
4:29
is used to send an entire string to the
4:32
display we can send the buffer we
4:34
defined above or send the string
4:37
directly now let's put the cursor at the
4:40
beginning of the next row and send the
4:42
buffer to this position all right let's
4:55
now the LCD send string function takes
4:59
the character a pointer as the parameter
5:01
so let's change the buffer type here we
5:04
don't have any errors so let's Flash the
5:08
board here you can see the LCD is
5:11
displaying the data as we programmed it
5:13
to do now let's change the string and
5:21
again you can see the new data on the
5:24
LCD so the strings are working fine we
5:27
can display them to the required
5:29
positions as needed now let's see how to
5:33
display the numbers on the
5:35
LCD let me Define a number and a
5:38
character array where the number will be
5:39
stored in the character
5:41
format we can't send the number directly
5:44
to the display so we will convert each
5:46
digit of the number to character format
5:50
characters the function s printf does
5:53
exactly this let's define this number as
5:57
the 16bit unsigned integer
6:00
the format specifier you converts the
6:02
unsigned integers to the respective
6:05
characters let's include the standard IO
6:08
header file for the S print F to work
6:11
after the number has been converted to
6:13
character form it's stored in the number
6:16
array let's send this array to the
6:24
LCD now build and Flash the code to the
6:31
here you can see the number printed on
6:33
the second row of the display the LCD
6:36
send data can be used to display A
6:39
Single Character to the
6:41
LCD also if we don't set the cursor
6:44
position the new data will display at
6:46
the very next position on the
6:48
LCD here I am sending the character a
6:52
without setting the cursor position you
6:55
can see it got printed on the LCD very
6:57
next to the number the cursor on the LCD
7:01
automatically increments by one and if
7:03
we don't specify the position the data
7:06
will print just next to the previous
7:08
data we have only a few functions in the
7:11
LCD Library there is the initialization
7:14
sending string data and the clear
7:17
function let's use the LCD clear
7:20
function now after writing the data we
7:24
will wait for 2 seconds and then clear
7:27
LCD let's build and Flash it to the
7:34
now so the data is printed on the LCD
7:38
now after 2 seconds the display gets
7:41
cleared so we got the LCD to work with
7:46
MCU if you want to understand the
7:49
library please check this video the link
7:52
to the video is in the description below
7:56
we will continue the i2c master in the
7:58
next video also and finally we will see
8:01
how to read the data from the slave
8:03
device this is it for today you can
8:07
download the code from the link in the
8:09
description leave comments in case of
8:12
any doubt keep watching and have a nice