There is one more thing I wanted to add in this section, which I think is quite important.
So basically what to do if the cell communication can't be established.
So let's say you have something like uh, this is the wrong port or the Arduino is not connected.
You run the script and you have this error with so huge stuff with basically serial exception could
not open port okay or something that is similar.
Well, in this lesson, I'm first going to go through the different things you can do to debug, and
then you will see how to make your Python program automatically retry to connect.
So here to the Arduino when it fails the first time.
All right.
So let's start with the debugging part.
First of all make sure of course that your Arduino board is correctly plugged to your Raspberry Pi with
the USB cable.
Okay, that sounds quite obvious, but it has happened to me a few times that I was like, why is not
working?
Well, if you look on the side, the Arduino is not connected, that's why.
Okay then of course, make sure that you have the correct port here that you can check on the terminal.
So with um lhs slash dev slash tty like this and check the port is here.
So you can connect, disconnect and find what is the difference in here.
You're going to find this port.
Make sure.
Also you have the same baud rate.
Okay.
Well, if you have a different baud rate, the communication is gonna be opened anyway, but then everything
is gonna not work, basically.
Also, wait a few seconds, okay?
After opening the communication so you don't get any garbage and reset the input buffer.
So you start here the while loop with a fresh input buffer on the Raspberry Pi.
And then when you run your program, well, if you are currently, for example, uploading the program,
let's let's say use the serial monitor here.
So I have the monitor which is a cell communication with the Arduino.
Okay.
On this pot you can see on this pot now I'm gonna run.
The script, you can see we have the same error.
Well, actually we don't have the exact same error.
We have the error that says device or resource is busy.
Why?
It's busy because we are currently using the serial monitor.
Or maybe we are currently uploading a code.
Okay, so if I close the serial monitor and if I run again now, it's going to work.
Why?
Because the serial is actually free.
So make sure you have only one program at a time that is using cell communication.
So that can be uploading the sketch here.
That can be using the sign monitor or that can be using the Python program here.
All right.
And one more thing also is of course make sure that uh, the program here is correctly uploaded to the
Arduino.
Don't forget to upload it before you try to communicate with it and make sure you have this line.
Okay.
So let's begin.
Okay.
If you don't begin this here on the Arduino anyway, that's not going to work on the Raspberry Pi.
So well basically if you respect all of that it should work fine.