WEBVTT

00:00.080 --> 00:06.590
In this new activity, you are going to control your Arduino from Telegram and of course, going through

00:06.590 --> 00:07.670
the Raspberry Pi.

00:07.700 --> 00:13.940
So basically what you have to do is so when you're going to send some comments from the chat, so you're

00:13.940 --> 00:17.420
going to control the RGB led and the LCD screen.

00:17.420 --> 00:24.770
So for example, you type slash LCD, that's going to be the command and then some text, okay, you're

00:24.770 --> 00:25.670
going to type this.

00:25.670 --> 00:27.260
So for now it doesn't do anything.

00:27.260 --> 00:34.640
And this text here should appear on the LCD screen and also a command for the RGB led.

00:35.270 --> 00:35.540
Okay.

00:35.540 --> 00:38.120
So now we arrive at things a little bit more complex.

00:38.120 --> 00:42.530
But again, if you have correctly understood the following, it should not be a problem.

00:42.530 --> 00:44.180
You can manage to do it by yourself.

00:44.180 --> 00:52.610
So on the Arduino side, what you're going to do is just open and handle comments for RGB Led and LCD

00:52.610 --> 00:53.180
screen.

00:53.180 --> 00:56.990
So for the LCD screen, I will let you define a protocol.

00:56.990 --> 01:03.320
So what kind of comment you can send from what we have done before, you should be able to do that.

01:03.320 --> 01:09.140
And for the RGB led, what we have done previously was to set each color independently.

01:09.140 --> 01:12.860
Okay, you would send red, you would send green and you would send blue.

01:12.890 --> 01:19.490
Here we are going to improve a little bit and instead of sending green, blue, red, we are going to

01:19.490 --> 01:22.280
just send one comment for the three colors.

01:22.310 --> 01:22.940
Okay.

01:23.120 --> 01:25.520
And here I have shown you an example.

01:25.520 --> 01:26.060
Okay.

01:26.600 --> 01:28.100
Actually, let's use comma.

01:29.660 --> 01:36.530
So we have the command set led like this and then we have three numbers.

01:36.530 --> 01:39.080
So this is going to be sent as a string, of course.

01:39.290 --> 01:45.080
And so you check that the command starts with set Led, you remove the first one, two, three, four,

01:45.080 --> 01:48.950
five, six, seven, eight characters and then you are left with this.

01:49.280 --> 01:54.920
And then you have the substring function that you can use on the string on the Arduino string.

01:55.130 --> 01:55.310
Okay.

01:55.310 --> 01:58.070
To just get one part of the string.

01:58.070 --> 02:00.600
So that's zero one, two, three.

02:00.630 --> 02:01.140
Okay.

02:01.140 --> 02:08.190
And then four, five, six, seven and then eight to the end and you're going to cast that to an integer.

02:08.190 --> 02:10.020
And so you have red, green and blue.

02:10.140 --> 02:16.470
One very important thing is that when you send the command from the Raspberry Pi and also from Telegram,

02:16.470 --> 02:19.620
you have to respect the number of characters here.

02:19.650 --> 02:21.660
Okay, So I have shown you an example.

02:21.660 --> 02:24.300
So if you send 200 for red, you just put 200.

02:24.330 --> 02:30.510
If you want to put zero for green, you don't just put zero like this, you have to put three zero for

02:30.510 --> 02:31.560
it to work.

02:31.770 --> 02:34.200
And for 80 you just don't send 80.

02:34.230 --> 02:36.480
You send with a zero.

02:36.480 --> 02:39.900
So you make sure you have three characters for each color.

02:39.930 --> 02:40.470
Okay?

02:40.650 --> 02:44.040
And that's the way we are going to be able to read the colors.

02:44.070 --> 02:48.390
You could do something different, of course, to improve it, but we're going to stay with that.

02:48.390 --> 02:52.380
And that's a pretty efficient way actually to set the Led.

02:52.950 --> 02:55.860
Okay, so that's it for the Arduino side on the Raspberry Pi side.

02:55.860 --> 02:59.010
So you're going to connect to Serial, you're going to create some.

02:59.010 --> 03:02.940
So here you don't send notification to Telegram, you receive some comments.

03:02.940 --> 03:07.260
So you're going to create a command handler with an update data, a dispatcher.

03:07.260 --> 03:12.960
And then when you receive a command, you directly pass it to the Arduino, okay, with the correct

03:13.320 --> 03:13.890
command.

03:13.890 --> 03:27.090
So, for example, if I send here, let's say RGB and then so 200 comma, 000 comma zero 80, if I send

03:27.090 --> 03:33.630
this and exactly this, you're going to receive that on the Raspberry Pi and you're not going to send

03:33.660 --> 03:40.500
RGB, you're going to send set Led colon, you're going to add this and you're going to add a new line

03:40.500 --> 03:41.160
character.

03:41.160 --> 03:45.750
So you receive the command from Telegram on the Raspberry Pi and you make sure that you send the correct

03:45.750 --> 03:51.120
command for the Arduino so that the Arduino can understand what you're asking to do.

03:51.660 --> 03:52.080
Okay.

03:52.080 --> 03:55.200
I will see you in the next lesson for the solution.
