WEBVTT

00:00.180 --> 00:07.200
And now let's discuss the second side of the communication, which is good from your computer to your

00:07.200 --> 00:07.690
Arduino.

00:08.250 --> 00:12.420
This would be very useful when you want to make your program more dynamic.

00:12.900 --> 00:14.580
For example, you want the user.

00:14.580 --> 00:22.440
So, for example, you to give some data or some numbers or some text, etc. to the Alvino while the

00:22.440 --> 00:27.800
program is running so you can modify the behavior of the program on the run.

00:28.410 --> 00:31.080
And so in this lesson, I'm going to show you how to do that.

00:31.610 --> 00:38.670
But first, if you're going to save money but we still have the old program running, well, I'm going

00:38.670 --> 00:41.610
to just remove everything.

00:43.460 --> 00:44.570
So the new program.

00:46.310 --> 00:53.380
But this does nothing to you already know the same way, don't you do that here on this panel, you

00:53.390 --> 00:58.730
will have the text from the original to your computer and you can see that on the top.

00:58.730 --> 01:00.340
Here you have a DA, OK?

01:00.740 --> 01:04.690
And this is where you can send some texts.

01:04.700 --> 01:09.410
So say I said no, I want to send number 12 to my original.

01:09.800 --> 01:14.810
I'm going to write 12 and then press enter on the send button.

01:15.440 --> 01:20.240
And this will send the data from the computer to the audio.

01:21.290 --> 01:22.330
As you can see for now.

01:22.670 --> 01:30.050
Well, nothing happens because simply I haven't told the Alino to actually read the volume.

01:30.280 --> 01:34.070
OK, you can just send volume, but they will not read.

01:34.610 --> 01:35.000
All right.

01:35.030 --> 01:42.330
So now how can we receive insight, know the value that we send from the sale monitor?

01:42.560 --> 01:47.620
So the first step you should do, of course, is to initialize the site communication.

01:47.630 --> 01:54.430
So when you do say the IT initializes the communication for both sending data and receiving data.

01:54.780 --> 01:58.280
Now, what I'm going to do, I'm going to do this in the loop.

01:58.310 --> 02:05.030
OK, so we can continuously check if we have new data available to know if you have data.

02:05.030 --> 02:12.590
Actually, you have a function from the sale library sale that the label and you can see it.

02:13.190 --> 02:13.700
All right.

02:13.800 --> 02:14.030
OK.

02:14.590 --> 02:17.600
Of course, with parentheses, they are not the variable.

02:17.600 --> 02:24.600
We give you a number and this number corresponds to the number of bytes that are ready to be read.

02:25.160 --> 02:29.180
So now it's quite easy how to know if we have data to read.

02:29.390 --> 02:37.460
We simply need to check if the result we get from the sale of illegal function is greater, strictly

02:37.460 --> 02:39.020
greater than zero.

02:39.410 --> 02:39.730
OK.

02:41.340 --> 02:47.410
If there is no data, this will give you zero, if you have some data, you will get a positive number.

02:47.970 --> 02:50.690
And from there, we can read the data.

02:50.940 --> 02:52.870
This is a two step process.

02:52.890 --> 02:55.580
First to check if there is something valuable data.

02:55.800 --> 03:01.890
And then you read the data and I'm going to show you a few different functions you can use to read the

03:01.890 --> 03:02.190
data.

03:02.220 --> 03:09.220
So let's say you expect an integer, let's limit var for viable if this is just a test for this.

03:09.450 --> 03:18.960
Listen, if you wait for an integer, you can use the function of that bus int.

03:20.330 --> 03:28.250
OK, so this will read the data from the sale and it will pass it as an integer and return an integer,

03:28.580 --> 03:31.790
but you have an eight day like a..

03:32.210 --> 03:36.140
Once you have this value, you can do whatever you want with it.

03:36.500 --> 03:41.990
So, for example, we could just reprint the value, the standard print and then.

03:43.390 --> 03:44.050
Winterville.

03:44.680 --> 03:47.170
OK, so what have we done with this program?

03:47.230 --> 03:49.650
Well, this is a simple eco program.

03:50.110 --> 03:58.060
So you send the data and the science monitor here and then we receive the data and it will print the

03:58.060 --> 03:58.380
data.

03:58.390 --> 04:01.520
So the data you sent here, you will receive it here.

04:02.140 --> 04:03.100
So let's make a try.

04:03.790 --> 04:05.560
We are going to upload the program.

04:07.410 --> 04:13.200
Well, make sure the problem is that the to the army and then so I'm going to send a no let's say send

04:13.200 --> 04:17.660
40 to a press, enter and I see 42.

04:18.140 --> 04:20.050
OK, so what happened in the program?

04:21.090 --> 04:23.910
So first we initialize this condition, right?

04:24.090 --> 04:25.620
Nine thousand six hundred.

04:25.620 --> 04:33.240
It's the same as here we enter the loop, then we check continuously very fast if there is some data

04:33.240 --> 04:34.430
available from the site.

04:34.450 --> 04:35.880
So of course, there is no data.

04:36.480 --> 04:43.440
I send the number 42, the original receives the data and now say ALDRED available gives a positive

04:43.440 --> 04:43.800
number.

04:43.810 --> 04:52.410
So we intend if the function Sialkot percent we read the data 42, put it inside it to the viable here

04:52.740 --> 04:54.410
and then we've sent the printer.

04:54.410 --> 04:57.420
Then we just send back the value.

04:57.870 --> 05:04.860
We received the contract with different numbers, etc. If we worked every time, if I said let's say

05:05.340 --> 05:06.000
on text.

05:07.190 --> 05:07.970
What happened?

05:09.020 --> 05:16.310
Is that this is not the number, OK, OK, the information will simply return to zero, so we will get

05:16.310 --> 05:16.730
to you.

05:16.910 --> 05:23.140
And now one important thing to check is the option here you have at the bottom of this one.

05:23.750 --> 05:28.040
So I have no line ending and this is what you should have.

05:28.580 --> 05:35.170
This option is actually what the science monitor will do once you send an information here.

05:35.630 --> 05:40.630
So with no line and we just send the data just like you writing.

05:41.150 --> 05:49.310
But if you have a new line, let's say I have the new option and I send for it to again and oh, we

05:49.310 --> 05:51.170
have for it, but we have zero of.

05:53.020 --> 05:56.700
Delights in another number, seven and zero.

05:57.690 --> 06:04.200
But what happened here, what happened is that when you send a number, so if they send it to new line,

06:04.200 --> 06:08.430
we add a new line character, the new line character is backslash.

06:08.470 --> 06:15.840
And so this is what will be sent to the area and the admin when we first read in the number forty two.

06:16.170 --> 06:21.520
And then it will read this character, which will be evaluated to zero.

06:21.870 --> 06:25.200
So that's why you have the first character and then zero.

06:26.010 --> 06:32.190
OK, so you have a new line, you have courage written and both new and I encourage written.

06:32.760 --> 06:35.020
Make sure you select no line ending.

06:35.040 --> 06:40.620
So when you send a number, you just have the number and not an additional zero.

06:40.650 --> 06:46.100
OK, this is a quite common error you can get in your programs and you know how to solve that.

06:46.230 --> 06:50.420
So now let's make a few experiments so we have an integer.

06:50.550 --> 06:52.260
Let's say I want to send the big number.

06:52.330 --> 06:57.960
So, you know, integer, the max value of integer is a thirty thousand something.

06:57.960 --> 06:59.280
You don't need to be very precise.

06:59.280 --> 07:01.470
You just need to know it's in that range.

07:01.710 --> 07:04.740
Let's say you want to send fifty dollars.

07:05.080 --> 07:13.350
I'm just going to press enter and oh we don't get fifty thousand, we get minus fifteen thousand five

07:13.350 --> 07:14.340
hundred and thirty six.

07:14.730 --> 07:18.300
This is because the integer here as overflowed.

07:18.630 --> 07:20.760
So we have reached the maximum value.

07:20.760 --> 07:27.630
And then what happened is that the value went back to the minimum and that's where you have a weird

07:27.630 --> 07:28.330
number here.

07:28.980 --> 07:33.450
So if you want to receive a larger number, you need to use long.

07:36.710 --> 07:42.710
So let's send fifty thousand again and you will get the correct value.

07:43.190 --> 07:51.830
OK, so you can receive integer long numbers, but you can also receive double float data type.

07:52.250 --> 07:57.080
And to do that, instead of just means you will use Barth's float.

07:57.440 --> 08:01.000
And it's quite easy not to make a mistake because this will turn.

08:01.050 --> 08:01.580
All right.

08:02.060 --> 08:03.140
Let's blow this.

08:04.570 --> 08:12.880
And let's see, three point fourteen and we get the correct value, if I just sent an integer number,

08:13.480 --> 08:18.470
you will see we have an integer, but this is actually represented as a float number.

08:18.490 --> 08:20.940
OK, forty two point zero.

08:21.370 --> 08:23.800
So you have bus and bus float.

08:24.250 --> 08:27.720
And if you want to send a string, well, this is a bit different.

08:27.730 --> 08:30.010
You have to use three train.

08:31.200 --> 08:35.190
And of course, the data types would be drawing with a case.

08:36.150 --> 08:37.140
Let's try this.

08:39.670 --> 08:43.450
And let's send hello from the computer.

08:46.190 --> 08:53.690
And we get hello from the computer, though that is quite convenient, but it does float and stream.

08:54.590 --> 09:00.200
Make sure you have the correct data type and then you can process the data and whatever you want in

09:00.200 --> 09:00.800
your program.

09:01.130 --> 09:03.220
OK, just one thing I want to show you.

09:03.230 --> 09:05.120
I'm just going to send back some text.

09:06.360 --> 09:13.500
And just pay attention to the duration between the time when I send the data and the time when it is

09:13.500 --> 09:16.120
printed here, I'm pressing.

09:16.140 --> 09:17.220
And right now.

09:18.210 --> 09:22.680
And you can see here the text the is after about one.

09:23.190 --> 09:26.370
OK, one time again, a press enter.

09:27.960 --> 09:29.570
And it's not directly here.

09:29.680 --> 09:33.660
OK, it's here after but one again, and why is that?

09:34.020 --> 09:36.770
This is because of the Celil time out.

09:37.200 --> 09:40.720
So there is a time out for this terrible communication.

09:40.740 --> 09:41.700
What is the time out?

09:41.700 --> 09:47.390
Basically, when you do pass into past float or restring for those functions, for example.

09:47.730 --> 09:52.530
So I will try to read and interpret the data.

09:52.830 --> 10:00.150
And because it has a time out of once again, it will simply wait one complete so it can receive all

10:00.150 --> 10:03.870
the information and then pass that information.

10:04.180 --> 10:11.160
So these just in case the data is not just arriving at the same time and is a little bit delayed, which

10:11.160 --> 10:13.770
can happen with any kind of communication.

10:13.950 --> 10:22.800
But here for our use cases where we just send one piece of text or one integer, one float, and that

10:22.800 --> 10:24.660
is send off very, very rapidly.

10:24.690 --> 10:35.160
OK, so in order to reduce the time that is spent here on that function, we can do scenario that sit.

10:36.660 --> 10:46.680
Time out again, turns around and said, time out in milliseconds, so the default one is one thousand

10:46.770 --> 10:55.200
milliseconds next, but simply 10 milliseconds, it means that when we use the string function, this

10:55.200 --> 10:57.300
will simply wait for 10 milliseconds.

10:57.660 --> 11:03.470
To be sure, we received all the data and after ten milliseconds, any new data would be discarded.

11:03.870 --> 11:10.050
But that's not a problem because when we send it here, the data will take less than 10 minutes to write.

11:10.380 --> 11:14.790
So in this case, we will save almost one segment when using that function.

11:14.970 --> 11:21.210
And one important thing is that first, so you do say at the beginning and it's the set time out, you

11:21.210 --> 11:27.030
just do that once after saying, you know, let's apply the program.

11:28.840 --> 11:35.810
And I'm just going to write some text again and I press enter and you can see the text here.

11:36.000 --> 11:37.900
There's almost immediately.

11:38.990 --> 11:42.510
Another time, OK, almost immediately.

11:42.530 --> 11:50.330
In fact, it appears with a ten minute delay, and that is the same, so the time out will be the same

11:50.330 --> 11:55.290
for the restringing, for bus float and for bus introductions.

11:55.580 --> 11:55.970
All right.

11:55.970 --> 12:02.570
So now you know how to receive and read the data from the cell communication on your arm in the world.

12:03.140 --> 12:08.640
And just to show you how you can work with cell communication on Dinko Cazzo for the simulation.

12:09.020 --> 12:11.600
Well, you have seen that in the science monitor here.

12:11.600 --> 12:17.080
You would just see the data when you have and print print Allen, for example.

12:17.510 --> 12:22.790
And here is actually where you will send data from the computer to the.

12:23.770 --> 12:27.050
So that's quite similar to what you have with the science monitor.

12:27.050 --> 12:38.300
With the two here is the same could have used to just done the simulation here to send a piece of string.

12:38.990 --> 12:41.030
And so it goes to the other.

12:41.030 --> 12:45.530
No, and then they are printed and you can see yellow on the side of Moniteau.
