WEBVTT

00:00.110 --> 00:05.960
There is one more thing I wanted to add in this section, which I think is quite important.

00:05.960 --> 00:11.600
So basically what to do if the cell communication can't be established.

00:11.900 --> 00:18.860
So let's say you have something like uh, this is the wrong port or the Arduino is not connected.

00:18.890 --> 00:27.500
You run the script and you have this error with so huge stuff with basically serial exception could

00:27.500 --> 00:32.120
not open port okay or something that is similar.

00:33.280 --> 00:40.030
Well, in this lesson, I'm first going to go through the different things you can do to debug, and

00:40.030 --> 00:45.100
then you will see how to make your Python program automatically retry to connect.

00:45.100 --> 00:49.270
So here to the Arduino when it fails the first time.

00:49.270 --> 00:49.600
All right.

00:49.600 --> 00:51.310
So let's start with the debugging part.

00:51.310 --> 00:58.420
First of all make sure of course that your Arduino board is correctly plugged to your Raspberry Pi with

00:58.420 --> 00:59.440
the USB cable.

00:59.440 --> 01:04.930
Okay, that sounds quite obvious, but it has happened to me a few times that I was like, why is not

01:04.930 --> 01:05.380
working?

01:05.380 --> 01:09.190
Well, if you look on the side, the Arduino is not connected, that's why.

01:09.220 --> 01:15.760
Okay then of course, make sure that you have the correct port here that you can check on the terminal.

01:15.760 --> 01:25.060
So with um lhs slash dev slash tty like this and check the port is here.

01:25.060 --> 01:29.110
So you can connect, disconnect and find what is the difference in here.

01:29.110 --> 01:30.460
You're going to find this port.

01:31.150 --> 01:31.720
Make sure.

01:31.720 --> 01:33.550
Also you have the same baud rate.

01:33.670 --> 01:34.270
Okay.

01:34.950 --> 01:40.260
Well, if you have a different baud rate, the communication is gonna be opened anyway, but then everything

01:40.260 --> 01:42.600
is gonna not work, basically.

01:42.630 --> 01:45.330
Also, wait a few seconds, okay?

01:45.330 --> 01:50.820
After opening the communication so you don't get any garbage and reset the input buffer.

01:50.820 --> 01:56.100
So you start here the while loop with a fresh input buffer on the Raspberry Pi.

01:56.100 --> 02:02.760
And then when you run your program, well, if you are currently, for example, uploading the program,

02:02.760 --> 02:05.220
let's let's say use the serial monitor here.

02:05.220 --> 02:09.000
So I have the monitor which is a cell communication with the Arduino.

02:09.630 --> 02:10.080
Okay.

02:10.470 --> 02:13.500
On this pot you can see on this pot now I'm gonna run.

02:15.090 --> 02:18.060
The script, you can see we have the same error.

02:18.060 --> 02:21.210
Well, actually we don't have the exact same error.

02:21.210 --> 02:25.380
We have the error that says device or resource is busy.

02:25.530 --> 02:26.130
Why?

02:26.130 --> 02:29.790
It's busy because we are currently using the serial monitor.

02:29.790 --> 02:32.700
Or maybe we are currently uploading a code.

02:32.730 --> 02:40.020
Okay, so if I close the serial monitor and if I run again now, it's going to work.

02:40.050 --> 02:40.530
Why?

02:40.560 --> 02:43.200
Because the serial is actually free.

02:45.200 --> 02:50.000
So make sure you have only one program at a time that is using cell communication.

02:50.000 --> 02:52.730
So that can be uploading the sketch here.

02:52.730 --> 02:57.290
That can be using the sign monitor or that can be using the Python program here.

02:57.770 --> 02:58.190
All right.

02:58.190 --> 03:04.010
And one more thing also is of course make sure that uh, the program here is correctly uploaded to the

03:04.010 --> 03:04.670
Arduino.

03:05.000 --> 03:11.480
Don't forget to upload it before you try to communicate with it and make sure you have this line.

03:11.480 --> 03:11.780
Okay.

03:11.780 --> 03:12.830
So let's begin.

03:13.250 --> 03:13.490
Okay.

03:13.490 --> 03:17.810
If you don't begin this here on the Arduino anyway, that's not going to work on the Raspberry Pi.

03:17.960 --> 03:22.430
So well basically if you respect all of that it should work fine.
