This is the solution of the previous activity where you have to start from the previous activity.
So activity number three again.
But this time we are going to put some logs from the Arduino to the LCD screen.
And so first of all, we are going to initialize the LCD screen.
So I'm going to include the liquid crystal library.
So liquid crystal dot H with angle bracket.
And then add some define for the pin.
So LCD is PIN, which is eight four, and then LCD pin which is a five.
And let's actually copy this.
Four more times with d4 d5 d6 D7, which are pins number two, three, four and five.
And so we can now create the LCD object.
So let's create it here.
Liquid crystal, let's name it LCD again with all the pins, so S and then E So make sure you respect
the order here.
Okay?
That's very important.
And then.
Let's go.
Here.
The five.
And D6 and D7.
Okay.
Now in the setup, so we have begin we can also do LCD dot begin with 16.
And to.
So here again, the order doesn't really matter because as soon as the LCD is started, well, you can
start to print something.
And now, well, we're going to use the LCD here.
So let's say that when we send the counter at the same time we do serial.println.
So just after that, maybe we do LCD dot clear.
Okay.
So we clear the screen from anything that was on the screen before we do the LCD.
Set cursor zero zero to go back to the beginning of the screen and we say, let's say LCD dot print
with.
Since counter.
Okay.
And let's do LCD dot print with the counter.
So here, as you can see, if we do a print and then another print where the cursor it starts from zero
zero and then it's going to go to one, two, three, four, five, six, seven, eight, nine, ten,
11, 12, 13, 14.
So we just have two more characters that are possible here.
So basically, as long as the counter doesn't reach 100, we're going to get all the characters.
If you want, you can also do LCD dot set cursor with zero and one.
So basically you're going to print that on the first line and that on the second line, okay, let's
keep it like this.
And now when we receive something here, well, for example, what we could do is directly when we receive
a comment, just print that comment.
Or we could do a different LCD print for each comment.
Okay.
With a custom text that we want.
But here I'm just going to do this LCD dot clear.
Okay.
If I don't do LCD dot clear, everything is going to be written on top of what's what has been written
before, but it's not going to remove the other characters.
So you may have something that is quite weird on the screen.
So that's why when I write something here with the logs, I'm going to do LCD clear and LCD dot set
clear.
So zero zero LCD dot print cmd.
Okay.
So whenever we send something or we receive a command, the screen is going to be cleared and we're
going to get the new log that is printed.
So let's try that.
Okay, I'm gonna upload the code first.
Let's name it activity for.
I'm going to also save this file.
This python file as.
Activity as well.
He even if that's the same code.
And then let's start the Python program.
Okay, so sale Okay.
And you can see here send counter.
Okay.
You can see and we have reset counter and then send counter because well, it goes very fast and we
just received it.
We just receive the command before we send another counter.
You can see up to 20 and then reset, counter send counter.
Okay.
So you can see basically what's happening from the Arduino.
I'm going to kill this.
And so, as you can see, this system is not the best ideal system because, for example, here on the
Raspberry Pi, the logs that we see here are kind of better, but that's always something you can do
to debug a little bit.
And you can see also that it's not just about debugging.
Now you can see that you can control the LCD screen directly from your Raspberry Pi, okay?
Because here you just send some text and you can print that text on the LCD.
So you can already control some Arduino components from the Raspberry Pi going through the serial communication.
And that's the end of this activity.
Number four.