This is the first step of the final project where we build a complete intercom system.
And for this step, well, we are not going to write any code.
We are going to define the protocol we will use to communicate between the Arduino and the Raspberry
Pi and also between the Raspberry Pi and the Telegram application.
Okay?
Because when you communicate between both sides, you need to agree on what you send and what you receive
so you can correctly process the comments and the messages.
So I'm just going to open well, just I'm going to open Genie here just to write some text.
So what you can do, what I would recommend is just write the protocol on paper first.
Okay?
Just a pen and paper.
That's it.
Or just open any text editor you want on the Raspberry Pi or on your phone, on Windows or.
Well, basically any way you want.
Okay.
It doesn't really matter.
It's just to write the protocol that then you keep on the side for the duration of the project.
So first of all, we're going to focus on serial communication.
We're not putting full size.
Okay.
And then on telegram communication.
So what do we need for soil?
So basically between the Arduino and the Raspberry Pi, first let's do the commands that are going to
go from Arduino to Raspberry Pi.
I'm going to write a Pi like this.
What do we have?
Well, we have just one output we want to send is when we press on the push button.
And when we press on the push button, we can send the command, for example, button pressed with backslash
n Okay, I'm going to add backslash n here so that the command is complete.
So we send this.
So we've already done that actually in some of the previous activities.
We send this from the Arduino, we receive that on the Raspberry Pi, then that's it for this side of
the communication we have.
Then the API to the Arduino here we have a few more comments.
So we are going to control the RGB led the buzzer, the servo motor and the LCD screen from the Raspberry
Pi.
And so what commands exactly are we going to send?
Let's first think about the servo motor.
So basically the command we want to do is not to move the servo motor in a at a high level.
It's more to open the door or to close the door because this is an intercom project where the servo
motor is linked to the door.
So what I'm going to do is I'm going to send a command open door backslash n and close the backslash.
N And the Arduino will be responsible for moving the servo to the correct position when it receives
open door and moving the servo to the closed position when it receives the closed door command.
Okay.
I could send directly the angle of the servo to the Arduino, but.
Well, actually this way may be better.
Okay.
We send open door closed door and the Arduino knows because the Arduino is closer to hardware, the
Arduino knows what is the angle to send the servo to, what is the speed to move the servo, etcetera.
Okay, so we are done with the servo and with the open and close door functionality is then when we
open and we close the door, we also want to set the Led the buzzer and the LCD.
So let's start with LCD.
We are going to send print, text, colon and then let's say this is some text backslash N So we have
already done that before.
We send the print text command with Colon, and then we're going to extract this from the command.
So this is an exact command.
We are going to check if it's equal to open door here.
We are going to check if the command starts with print text and then extract this and print this on
the LCD screen.
Now for the buzzer.
Well, we haven't used the buzzer in any activity before, so that's something new.
What can we do to send comment to the buzzer?
So we want to play a sound on the buzzer And to play a sound, we need to give two things the frequency
and the duration.
And so I'm going to put a comment.
Let's say play.
Buzzer column and then frequency.
Comma, duration backslash n.
So on the Arduino, we're going to first check that we have a command that starts with play Buzzer Colon
and then we're going to extract.
So this and we're going to find the index of the comma and then everything before the index is the frequency.
Everything after the index is the duration.
Okay?
So the frequency can be anything from, let's say, 20Hz to 20,000Hz.
And the duration also can be anything from one millisecond to whatever milliseconds you want.
And then we have set led because we want to set the RGB led with red, green and blue backslash n And
so here we're going to follow the protocol we have used previously in one of the other activity, which
is to say that each color will be exactly three characters.
Okay.
So as an example, we have set led, let's say you want to give three for the red and then 255 for the
green and then zero 50 for the blue.
Okay, You're going to make sure that each color gets three characters.
Okay.
And let's just actually do an example for the play buzzer.
The buzzer, let's say, for example, 201,000, so 200 frequency, 1000 milliseconds.
And so we're going to handle actually those two commands a bit differently in the code, in the Arduino
code.
So we have covered all the functionalities here and all the components between the Arduino and the Raspberry
Pi.
So we're going to keep this on the side.
And so when we work on the Arduino, we know what to send and what to receive.
And when we work on the Raspberry Pi, we know what to receive and what to send.
Okay?
We don't need to always compare the two codes.
We can just refer to this document.
And then we also need to define what command we are going to send and receive from Telegram.
So well, when we actually send the notification with a message and a photo, there is no specific comment
to agree on because we're just going to send a message on the chat using the chat ID, But when we receive
command, we need to check what command we receive so we can process them with a handler in the Python
code.
And so we're going to have the start command as always.
And then to open the door, we are going to use open like you could see in the demo and to close the
door actually to deny access, not to close the door, but to deny access, just deny.
So we start we can get a welcome message.
When we receive a notification we can send open to open the door or we can send deny to deny the access.
And well, that's pretty much it.
So I'm going to save control.
S this as protocol dot txt.
Okay.
And keep it on the side for the duration of the project.
And now that we have this we are ready to start writing some code with the next step.