WEBVTT

00:00.080 --> 00:04.190
Let's start with the hardware setup for serial communication.

00:04.190 --> 00:08.870
So you have your Raspberry Pi here and you can see it's already powered on for me.

00:08.900 --> 00:09.290
Okay.

00:09.290 --> 00:12.170
And you have your Arduino and the USB cable.

00:12.200 --> 00:19.390
So what you're simply going to do is connect the Arduino to the Raspberry Pi with the USB cable.

00:19.400 --> 00:25.400
As you can see, you can do that when the Raspberry Pi is powered on or powered off, it doesn't really

00:25.400 --> 00:26.040
matter.

00:26.060 --> 00:27.470
And that's pretty much it.

00:27.500 --> 00:32.060
Now, you can see also on the Arduino here, I'm going to unplug it here.

00:32.060 --> 00:35.450
You can see you have some pins here on the Arduino Uno.

00:35.480 --> 00:43.280
You have zero and one which are X and X, and those are also pins for serial communication.

00:43.280 --> 00:47.300
So you could use those eventually with some Gpio on the Raspberry Pi.

00:47.330 --> 00:49.940
But this is much more complex.

00:49.940 --> 00:50.180
Okay.

00:50.180 --> 00:54.800
You need a voltage level shifter between five volt and 3.3V.

00:54.830 --> 01:01.110
It's also less robust, less reliable and well, USB cables are really working well.

01:01.140 --> 01:01.410
Okay.

01:01.440 --> 01:05.270
I've never had any problem with serial communication that way.

01:05.280 --> 01:06.690
And one more thing is that.

01:06.690 --> 01:08.460
So here I have an Arduino Uno.

01:08.490 --> 01:11.160
You may have a different kind of board.

01:11.190 --> 01:11.490
Okay.

01:11.490 --> 01:15.120
And depending on the board, the USB connector here may be different.

01:15.120 --> 01:20.220
So here I have like a standard classic one, but you may have a micro USB.

01:20.490 --> 01:26.610
Well, it doesn't really matter as long as you can connect the USB connector here to the USB connector

01:26.640 --> 01:27.870
here on the Raspberry Pi.

01:27.900 --> 01:30.390
Everything is going to work correctly.

01:31.260 --> 01:37.110
Now that the hardware setup is down, let's do the software setup and for that you go to your Raspberry

01:37.110 --> 01:38.580
Pi desktop.

01:38.580 --> 01:44.100
So make sure, of course, that you have correctly plugged your Arduino board to the Raspberry Pi using

01:44.100 --> 01:45.360
the USB cable.

01:45.480 --> 01:48.900
And so for the Arduino side, there is nothing to do.

01:48.930 --> 01:56.280
Serial is already configured and ready to be used with the serial library on the Raspberry Pi board.

01:56.280 --> 01:59.100
We will need to do a few setup steps.

01:59.100 --> 02:03.180
So first of all, you can open a terminal here.

02:04.190 --> 02:16.130
I'll click on the terminal icon and do ls dash dev dash t and then this so we can list all of the stuff

02:16.130 --> 02:22.400
that starts with slash dev slash t, you press enter and you can see all of that.

02:22.400 --> 02:23.480
So what is this?

02:23.510 --> 02:29.630
Well, basically we are going to try to find the port of the Arduino on the Raspberry Pi.

02:29.660 --> 02:30.200
Okay.

02:30.380 --> 02:37.070
So the port is basically the name that is given to the port here so that we can recognize it and then

02:37.070 --> 02:38.660
we can connect to it.

02:38.780 --> 02:39.320
And.

02:39.320 --> 02:40.820
Well, you have quite a few.

02:41.360 --> 02:42.590
I'm going to give you the answer.

02:42.620 --> 02:44.030
The port is that one.

02:44.030 --> 02:44.240
Okay.

02:44.270 --> 02:47.300
Slash dev slash t ACM zero.

02:47.300 --> 02:49.340
So you should have something like this.

02:50.000 --> 02:56.060
ACM or USB depends with a number that can be 0 or 1.

02:56.090 --> 02:58.970
Well, usually you will start with this.

02:59.000 --> 03:02.330
Now how to be sure you have this port.

03:02.360 --> 03:05.820
Well, you simply disconnect your Arduino.

03:05.820 --> 03:08.940
So I just unplugged my Arduino board.

03:08.970 --> 03:09.530
Okay.

03:09.540 --> 03:14.130
I just unplugged the USB cable and now I'm going to run this command again.

03:15.470 --> 03:22.250
And you can see that here we don't have the T zero anymore.

03:22.700 --> 03:25.250
I'm going to replug the Arduino.

03:25.730 --> 03:27.140
The Arduino is plugged.

03:27.740 --> 03:28.610
I run the command.

03:28.610 --> 03:30.260
You can see now we have this.

03:30.260 --> 03:35.360
So basically, you just disconnect your Arduino, you run that command, you connect your Arduino,

03:35.360 --> 03:38.980
and you just find what is the new port that is here.

03:38.990 --> 03:41.330
So now we know that this is the name of the port.

03:41.360 --> 03:46.850
What you could also do is if you have the Arduino IDE installed.

03:49.180 --> 03:49.450
Okay.

03:49.450 --> 03:55.680
You can see here on Tools and Port, we can find also the same name.

03:55.690 --> 03:56.410
All right.

03:58.870 --> 04:00.270
So now we have the port.

04:00.280 --> 04:02.380
I'm going to do clear on the terminal.

04:02.410 --> 04:08.860
The second step we need to do is to make sure that our user so the Pi user, which is here, you can

04:08.860 --> 04:13.780
see, has the permission to access to serial communication.

04:14.050 --> 04:18.430
So we are going to do groups to see all the groups we are in.

04:18.430 --> 04:18.700
Okay.

04:18.700 --> 04:26.290
So as the Pi user, you can see we are already in the dial out group and this is the one that gives

04:26.290 --> 04:28.660
you access to serial communication.

04:28.660 --> 04:33.310
So if you don't have this when you type groups, so what you can do is sudo.

04:34.720 --> 04:37.690
Add user and then the name of your user.

04:37.690 --> 04:41.110
So here it's Pi and the name of the group.

04:41.350 --> 04:46.780
You press enter and you can see here the user Pi is already a member of dial out.

04:46.780 --> 04:51.370
But if it was not the case, it would add you to dialogue group.

04:51.790 --> 04:52.030
Okay.

04:52.030 --> 04:56.320
If you just added your user to the dialogue, you need to log out and log in.

04:56.320 --> 05:01.030
So what you can do is log out, log in, or you can also reboot your Raspberry Pi so you can be sure.

05:01.060 --> 05:01.480
All right.

05:01.480 --> 05:02.770
That was the second step.

05:02.770 --> 05:07.030
The third step is to install a python library.

05:07.150 --> 05:12.760
So on the Arduino side, we have the C plus plus library called soil, which is already installed on

05:12.760 --> 05:13.330
the Arduino.

05:13.330 --> 05:20.950
But on the Raspberry Pi side, we need a python module and this python module is pi soil.

05:20.980 --> 05:21.220
Okay.

05:21.220 --> 05:24.910
So we are going to use the Pi serial module and to install it.

05:24.910 --> 05:27.520
So first make sure you have pip3.

05:27.550 --> 05:35.150
So if you don't have pip3 sudo apt install python three dash pip.

05:37.110 --> 05:37.410
Okay.

05:37.410 --> 05:38.550
It's already here.

05:38.550 --> 05:45.150
And then pip3 install py serial like that.

05:45.180 --> 05:45.720
Okay.

05:45.930 --> 05:47.220
Press enter.

05:49.230 --> 05:50.730
And already installed.

05:50.730 --> 05:54.960
So actually it may already be installed on your Raspberry Pi.

05:54.990 --> 05:57.120
So if that's the case, that's wonderful.

05:57.120 --> 06:02.050
And then you can do Pip3 show pi serial.

06:02.500 --> 06:02.880
Okay.

06:04.380 --> 06:10.150
To see the version, to see more details and maybe the page with documentation and everything.

06:10.170 --> 06:12.420
For this library.

06:12.540 --> 06:14.400
And that's pretty much it.

06:14.550 --> 06:15.300
Okay, great.

06:15.300 --> 06:17.790
So now everything is correctly set up.

06:17.820 --> 06:21.900
The Arduino board is plugged to the Raspberry Pi with the USB cable.

06:21.930 --> 06:28.650
You have the correct permission on the Raspberry Pi and you also have a serial library ready to be used

06:28.650 --> 06:30.340
on both sides.

06:30.360 --> 06:33.000
Let's now initiate the communication.
