WEBVTT

00:00.110 --> 00:05.720
This is the first step of the final project where we build a complete intercom system.

00:05.720 --> 00:09.950
And for this step, well, we are not going to write any code.

00:09.950 --> 00:16.220
We are going to define the protocol we will use to communicate between the Arduino and the Raspberry

00:16.220 --> 00:20.030
Pi and also between the Raspberry Pi and the Telegram application.

00:20.030 --> 00:20.420
Okay?

00:20.420 --> 00:27.020
Because when you communicate between both sides, you need to agree on what you send and what you receive

00:27.020 --> 00:30.770
so you can correctly process the comments and the messages.

00:30.770 --> 00:38.210
So I'm just going to open well, just I'm going to open Genie here just to write some text.

00:39.710 --> 00:45.080
So what you can do, what I would recommend is just write the protocol on paper first.

00:45.110 --> 00:45.290
Okay?

00:45.290 --> 00:46.610
Just a pen and paper.

00:46.610 --> 00:47.480
That's it.

00:47.810 --> 00:54.320
Or just open any text editor you want on the Raspberry Pi or on your phone, on Windows or.

00:54.320 --> 00:56.060
Well, basically any way you want.

00:56.090 --> 00:56.270
Okay.

00:56.270 --> 00:57.320
It doesn't really matter.

00:57.320 --> 01:03.510
It's just to write the protocol that then you keep on the side for the duration of the project.

01:03.510 --> 01:08.580
So first of all, we're going to focus on serial communication.

01:10.700 --> 01:12.070
We're not putting full size.

01:12.080 --> 01:12.740
Okay.

01:13.250 --> 01:18.560
And then on telegram communication.

01:21.620 --> 01:23.140
So what do we need for soil?

01:23.150 --> 01:28.790
So basically between the Arduino and the Raspberry Pi, first let's do the commands that are going to

01:28.790 --> 01:31.430
go from Arduino to Raspberry Pi.

01:31.460 --> 01:34.120
I'm going to write a Pi like this.

01:34.130 --> 01:35.210
What do we have?

01:35.210 --> 01:40.490
Well, we have just one output we want to send is when we press on the push button.

01:40.490 --> 01:48.350
And when we press on the push button, we can send the command, for example, button pressed with backslash

01:48.350 --> 01:53.030
n Okay, I'm going to add backslash n here so that the command is complete.

01:53.540 --> 01:55.100
So we send this.

01:55.100 --> 01:58.790
So we've already done that actually in some of the previous activities.

01:58.790 --> 02:03.320
We send this from the Arduino, we receive that on the Raspberry Pi, then that's it for this side of

02:03.320 --> 02:04.430
the communication we have.

02:04.430 --> 02:09.860
Then the API to the Arduino here we have a few more comments.

02:09.860 --> 02:17.270
So we are going to control the RGB led the buzzer, the servo motor and the LCD screen from the Raspberry

02:17.270 --> 02:17.690
Pi.

02:17.690 --> 02:21.060
And so what commands exactly are we going to send?

02:21.060 --> 02:23.850
Let's first think about the servo motor.

02:23.880 --> 02:29.460
So basically the command we want to do is not to move the servo motor in a at a high level.

02:29.460 --> 02:35.010
It's more to open the door or to close the door because this is an intercom project where the servo

02:35.010 --> 02:36.600
motor is linked to the door.

02:36.900 --> 02:46.140
So what I'm going to do is I'm going to send a command open door backslash n and close the backslash.

02:46.140 --> 02:53.350
N And the Arduino will be responsible for moving the servo to the correct position when it receives

02:53.400 --> 03:00.570
open door and moving the servo to the closed position when it receives the closed door command.

03:00.600 --> 03:00.900
Okay.

03:00.900 --> 03:03.810
I could send directly the angle of the servo to the Arduino, but.

03:03.810 --> 03:06.300
Well, actually this way may be better.

03:06.300 --> 03:06.540
Okay.

03:06.540 --> 03:11.820
We send open door closed door and the Arduino knows because the Arduino is closer to hardware, the

03:11.820 --> 03:18.120
Arduino knows what is the angle to send the servo to, what is the speed to move the servo, etcetera.

03:18.150 --> 03:23.490
Okay, so we are done with the servo and with the open and close door functionality is then when we

03:23.490 --> 03:28.740
open and we close the door, we also want to set the Led the buzzer and the LCD.

03:28.890 --> 03:30.300
So let's start with LCD.

03:30.330 --> 03:41.670
We are going to send print, text, colon and then let's say this is some text backslash N So we have

03:41.670 --> 03:42.900
already done that before.

03:42.900 --> 03:49.890
We send the print text command with Colon, and then we're going to extract this from the command.

03:50.220 --> 03:52.290
So this is an exact command.

03:52.290 --> 03:55.200
We are going to check if it's equal to open door here.

03:55.200 --> 04:01.110
We are going to check if the command starts with print text and then extract this and print this on

04:01.110 --> 04:02.250
the LCD screen.

04:02.250 --> 04:03.660
Now for the buzzer.

04:03.660 --> 04:09.510
Well, we haven't used the buzzer in any activity before, so that's something new.

04:09.540 --> 04:12.450
What can we do to send comment to the buzzer?

04:12.450 --> 04:19.500
So we want to play a sound on the buzzer And to play a sound, we need to give two things the frequency

04:19.500 --> 04:21.240
and the duration.

04:21.240 --> 04:23.730
And so I'm going to put a comment.

04:23.730 --> 04:24.840
Let's say play.

04:26.130 --> 04:29.910
Buzzer column and then frequency.

04:32.000 --> 04:35.120
Comma, duration backslash n.

04:35.270 --> 04:41.120
So on the Arduino, we're going to first check that we have a command that starts with play Buzzer Colon

04:41.120 --> 04:43.020
and then we're going to extract.

04:43.040 --> 04:49.880
So this and we're going to find the index of the comma and then everything before the index is the frequency.

04:49.880 --> 04:52.330
Everything after the index is the duration.

04:52.340 --> 04:52.570
Okay?

04:52.580 --> 04:57.170
So the frequency can be anything from, let's say, 20Hz to 20,000Hz.

04:57.170 --> 05:02.840
And the duration also can be anything from one millisecond to whatever milliseconds you want.

05:02.840 --> 05:16.370
And then we have set led because we want to set the RGB led with red, green and blue backslash n And

05:16.370 --> 05:21.980
so here we're going to follow the protocol we have used previously in one of the other activity, which

05:21.980 --> 05:25.820
is to say that each color will be exactly three characters.

05:25.850 --> 05:26.050
Okay.

05:26.060 --> 05:38.310
So as an example, we have set led, let's say you want to give three for the red and then 255 for the

05:38.310 --> 05:43.080
green and then zero 50 for the blue.

05:43.320 --> 05:48.810
Okay, You're going to make sure that each color gets three characters.

05:49.290 --> 05:49.770
Okay.

05:49.770 --> 05:53.160
And let's just actually do an example for the play buzzer.

05:53.730 --> 06:04.590
The buzzer, let's say, for example, 201,000, so 200 frequency, 1000 milliseconds.

06:04.590 --> 06:09.870
And so we're going to handle actually those two commands a bit differently in the code, in the Arduino

06:09.870 --> 06:10.430
code.

06:10.440 --> 06:18.270
So we have covered all the functionalities here and all the components between the Arduino and the Raspberry

06:18.270 --> 06:18.540
Pi.

06:18.660 --> 06:20.820
So we're going to keep this on the side.

06:21.150 --> 06:26.370
And so when we work on the Arduino, we know what to send and what to receive.

06:26.370 --> 06:31.050
And when we work on the Raspberry Pi, we know what to receive and what to send.

06:31.350 --> 06:31.530
Okay?

06:31.530 --> 06:34.260
We don't need to always compare the two codes.

06:34.260 --> 06:36.330
We can just refer to this document.

06:36.330 --> 06:42.930
And then we also need to define what command we are going to send and receive from Telegram.

06:42.930 --> 06:50.670
So well, when we actually send the notification with a message and a photo, there is no specific comment

06:50.670 --> 06:58.080
to agree on because we're just going to send a message on the chat using the chat ID, But when we receive

06:58.080 --> 07:03.480
command, we need to check what command we receive so we can process them with a handler in the Python

07:03.480 --> 07:03.930
code.

07:03.930 --> 07:07.080
And so we're going to have the start command as always.

07:07.080 --> 07:13.020
And then to open the door, we are going to use open like you could see in the demo and to close the

07:13.020 --> 07:18.360
door actually to deny access, not to close the door, but to deny access, just deny.

07:18.870 --> 07:22.320
So we start we can get a welcome message.

07:22.320 --> 07:29.370
When we receive a notification we can send open to open the door or we can send deny to deny the access.

07:29.370 --> 07:32.880
And well, that's pretty much it.

07:33.460 --> 07:35.410
So I'm going to save control.

07:35.410 --> 07:40.060
S this as protocol dot txt.

07:42.040 --> 07:42.520
Okay.

07:42.520 --> 07:45.550
And keep it on the side for the duration of the project.

07:45.550 --> 07:52.120
And now that we have this we are ready to start writing some code with the next step.
