Let's start with the hardware setup for serial communication.
So you have your Raspberry Pi here and you can see it's already powered on for me.
Okay.
And you have your Arduino and the USB cable.
So what you're simply going to do is connect the Arduino to the Raspberry Pi with the USB cable.
As you can see, you can do that when the Raspberry Pi is powered on or powered off, it doesn't really
matter.
And that's pretty much it.
Now, you can see also on the Arduino here, I'm going to unplug it here.
You can see you have some pins here on the Arduino Uno.
You have zero and one which are X and X, and those are also pins for serial communication.
So you could use those eventually with some Gpio on the Raspberry Pi.
But this is much more complex.
Okay.
You need a voltage level shifter between five volt and 3.3V.
It's also less robust, less reliable and well, USB cables are really working well.
Okay.
I've never had any problem with serial communication that way.
And one more thing is that.
So here I have an Arduino Uno.
You may have a different kind of board.
Okay.
And depending on the board, the USB connector here may be different.
So here I have like a standard classic one, but you may have a micro USB.
Well, it doesn't really matter as long as you can connect the USB connector here to the USB connector
here on the Raspberry Pi.
Everything is going to work correctly.
Now that the hardware setup is down, let's do the software setup and for that you go to your Raspberry
Pi desktop.
So make sure, of course, that you have correctly plugged your Arduino board to the Raspberry Pi using
the USB cable.
And so for the Arduino side, there is nothing to do.
Serial is already configured and ready to be used with the serial library on the Raspberry Pi board.
We will need to do a few setup steps.
So first of all, you can open a terminal here.
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
that starts with slash dev slash t, you press enter and you can see all of that.
So what is this?
Well, basically we are going to try to find the port of the Arduino on the Raspberry Pi.
Okay.
So the port is basically the name that is given to the port here so that we can recognize it and then
we can connect to it.
And.
Well, you have quite a few.
I'm going to give you the answer.
The port is that one.
Okay.
Slash dev slash t ACM zero.
So you should have something like this.
ACM or USB depends with a number that can be 0 or 1.
Well, usually you will start with this.
Now how to be sure you have this port.
Well, you simply disconnect your Arduino.
So I just unplugged my Arduino board.
Okay.
I just unplugged the USB cable and now I'm going to run this command again.
And you can see that here we don't have the T zero anymore.
I'm going to replug the Arduino.
The Arduino is plugged.
I run the command.
You can see now we have this.
So basically, you just disconnect your Arduino, you run that command, you connect your Arduino,
and you just find what is the new port that is here.
So now we know that this is the name of the port.
What you could also do is if you have the Arduino IDE installed.
Okay.
You can see here on Tools and Port, we can find also the same name.
All right.
So now we have the port.
I'm going to do clear on the terminal.
The second step we need to do is to make sure that our user so the Pi user, which is here, you can
see, has the permission to access to serial communication.
So we are going to do groups to see all the groups we are in.
Okay.
So as the Pi user, you can see we are already in the dial out group and this is the one that gives
you access to serial communication.
So if you don't have this when you type groups, so what you can do is sudo.
Add user and then the name of your user.
So here it's Pi and the name of the group.
You press enter and you can see here the user Pi is already a member of dial out.
But if it was not the case, it would add you to dialogue group.
Okay.
If you just added your user to the dialogue, you need to log out and log in.
So what you can do is log out, log in, or you can also reboot your Raspberry Pi so you can be sure.
All right.
That was the second step.
The third step is to install a python library.
So on the Arduino side, we have the C plus plus library called soil, which is already installed on
the Arduino.
But on the Raspberry Pi side, we need a python module and this python module is pi soil.
Okay.
So we are going to use the Pi serial module and to install it.
So first make sure you have pip3.
So if you don't have pip3 sudo apt install python three dash pip.
Okay.
It's already here.
And then pip3 install py serial like that.
Okay.
Press enter.
And already installed.
So actually it may already be installed on your Raspberry Pi.
So if that's the case, that's wonderful.
And then you can do Pip3 show pi serial.
Okay.
To see the version, to see more details and maybe the page with documentation and everything.
For this library.
And that's pretty much it.
Okay, great.
So now everything is correctly set up.
The Arduino board is plugged to the Raspberry Pi with the USB cable.
You have the correct permission on the Raspberry Pi and you also have a serial library ready to be used
on both sides.
Let's now initiate the communication.