WEBVTT

00:00.080 --> 00:02.690
This is step number six of the final project.

00:02.690 --> 00:07.340
And now what we're going to do is we're going to take a photo from the Raspberry Pi.

00:07.340 --> 00:12.710
When we have the command that the button has been pressed on the Arduino.

00:13.010 --> 00:20.450
And if you don't have the Raspberry Pi camera here at this point, well, you can skip this step and

00:20.450 --> 00:23.780
go to the next step where we send the message and the photo to Telegram.

00:23.780 --> 00:27.710
And actually you can just send the message without sending the photo.

00:27.710 --> 00:31.490
So of course it's better and the project will be complete with the camera.

00:31.490 --> 00:37.580
But if you don't have the camera at this time, you can still finish the project just by sending a text

00:37.580 --> 00:39.890
message to the telegram chat.

00:39.950 --> 00:40.370
All right.

00:40.370 --> 00:41.210
And let's start.

00:41.330 --> 00:47.030
So we already have our code structure with the setup of the serial.

00:47.060 --> 00:53.150
With our void loop, we receive data from Serial, and we can also send data to the Arduino.

00:53.150 --> 00:57.710
And we know, of course, that the Arduino is working correctly from the previous steps.

00:57.710 --> 00:59.180
So let's handle the camera.

00:59.180 --> 01:00.990
And this step is going to be pretty quick.

01:01.020 --> 01:01.760
Actually.

01:01.770 --> 01:15.510
Let's create a new and I'm just going to start here and save it as intercom comm step.

01:17.020 --> 01:18.010
Six.

01:21.260 --> 01:26.110
And so the first thing we are going to do is to initialize the camera.

01:26.120 --> 01:34.430
So from Pi camera, so from the Pi camera module, we import pi, camera object.

01:34.940 --> 01:37.880
And now where are we going to initialize this camera?

01:37.880 --> 01:43.460
So we first initialize cell and then we have a wait after setup.

01:43.550 --> 01:46.930
What I'm going to do is I'm going to initialize camera here.

01:46.940 --> 01:52.040
So init camera I'm going to put a print.

01:53.130 --> 01:54.780
So init.

01:54.810 --> 02:02.850
Camera so we know what we're doing and then camera is equal to pi camera.

02:03.570 --> 02:05.430
Let's choose a resolution.

02:05.430 --> 02:15.990
Camera dot resolution is equal to and let's give a tuple and let's use 640 by 480.

02:16.110 --> 02:23.370
Pretty low resolution, but big enough for us to see what we need to see on the image.

02:23.640 --> 02:30.300
And then camera rotation for me because my images are upside down.

02:30.300 --> 02:33.900
So adjust it depending on your camera.

02:34.560 --> 02:44.260
I'm going to create an image folder name, which is slash org slash api slash camera.

02:44.280 --> 02:51.690
Okay, let's use this camera folder in our home directory that doesn't necessarily exist.

02:51.690 --> 02:55.600
And so we're going to check if not OS.

02:55.600 --> 02:57.790
So if we use OS import.

02:58.920 --> 03:02.270
Twice, if not Dot.

03:03.820 --> 03:05.890
Path dot exists.

03:07.030 --> 03:17.860
So if this folder doesn't exist, we create it as dot mkdir image folder name and then we're going to

03:17.860 --> 03:24.940
create an image file name for the photos we're going to take, which is the folder name plus.

03:26.050 --> 03:27.820
So here we give the complete path.

03:28.840 --> 03:31.210
Let's name it dot.

03:32.850 --> 03:35.100
Camera dot jpg.

03:36.210 --> 03:39.600
Okay, let's try to give a more meaningful name than just image.

03:39.870 --> 03:44.010
And after that, we can say print camera.

03:44.040 --> 03:44.760
Okay.

03:46.600 --> 03:47.140
And then.

03:47.140 --> 03:52.780
Well, we need to wait for at least two seconds so the camera can adjust to the luminosity of the room.

03:53.080 --> 03:56.590
But as we are waiting for three seconds here, all ready for the sale.

03:56.800 --> 03:57.640
This is okay.

03:57.640 --> 04:01.540
So the time dot sleep will be useful for both the sale and the camera.

04:01.780 --> 04:08.290
Well, and then once the camera is initialized, the only thing we need to do is to take a picture when

04:08.290 --> 04:09.940
we have the open door request.

04:09.970 --> 04:11.520
Let's add another log here.

04:11.530 --> 04:12.790
Open the request.

04:13.450 --> 04:17.620
Taking a photo we send.

04:17.650 --> 04:26.830
Please wait for a few seconds on the Arduino and we do camera dot capture image file name.

04:27.820 --> 04:29.500
Okay, let's try this code.

04:29.500 --> 04:32.140
So code is still running on the arduino.

04:34.810 --> 04:36.850
I can see main loop is starting.

04:37.390 --> 04:43.150
Let's open file manager here and I'm going to open the camera folder.

04:43.360 --> 04:45.220
Let's clear everything I have for now.

04:45.220 --> 04:45.820
Here.

04:47.470 --> 04:49.540
And I'm going to press on the push button.

04:51.170 --> 04:56.300
And you can see we have open door requests taking a photo and we have a new photo here.

04:56.330 --> 04:59.740
We're going to open it and well, that's working.

04:59.750 --> 05:04.070
If I press on the push button again, let's do something else.

05:04.730 --> 05:08.720
You can see taking a photo and we have another photo.

05:09.110 --> 05:09.470
Okay.

05:09.470 --> 05:18.410
Every time you press on the button, you send a new request and you take a new photo that's going to

05:18.410 --> 05:19.760
replace the previous one.

05:19.910 --> 05:25.880
And now that we have this photo, we can go to the next step, which is to send it to Telegram.
