And now let's discuss the second side of the communication, which is good from your computer to your
Arduino.
This would be very useful when you want to make your program more dynamic.
For example, you want the user.
So, for example, you to give some data or some numbers or some text, etc. to the Alvino while the
program is running so you can modify the behavior of the program on the run.
And so in this lesson, I'm going to show you how to do that.
But first, if you're going to save money but we still have the old program running, well, I'm going
to just remove everything.
So the new program.
But this does nothing to you already know the same way, don't you do that here on this panel, you
will have the text from the original to your computer and you can see that on the top.
Here you have a DA, OK?
And this is where you can send some texts.
So say I said no, I want to send number 12 to my original.
I'm going to write 12 and then press enter on the send button.
And this will send the data from the computer to the audio.
As you can see for now.
Well, nothing happens because simply I haven't told the Alino to actually read the volume.
OK, you can just send volume, but they will not read.
All right.
So now how can we receive insight, know the value that we send from the sale monitor?
So the first step you should do, of course, is to initialize the site communication.
So when you do say the IT initializes the communication for both sending data and receiving data.
Now, what I'm going to do, I'm going to do this in the loop.
OK, so we can continuously check if we have new data available to know if you have data.
Actually, you have a function from the sale library sale that the label and you can see it.
All right.
OK.
Of course, with parentheses, they are not the variable.
We give you a number and this number corresponds to the number of bytes that are ready to be read.
So now it's quite easy how to know if we have data to read.
We simply need to check if the result we get from the sale of illegal function is greater, strictly
greater than zero.
OK.
If there is no data, this will give you zero, if you have some data, you will get a positive number.
And from there, we can read the data.
This is a two step process.
First to check if there is something valuable data.
And then you read the data and I'm going to show you a few different functions you can use to read the
data.
So let's say you expect an integer, let's limit var for viable if this is just a test for this.
Listen, if you wait for an integer, you can use the function of that bus int.
OK, so this will read the data from the sale and it will pass it as an integer and return an integer,
but you have an eight day like a..
Once you have this value, you can do whatever you want with it.
So, for example, we could just reprint the value, the standard print and then.
Winterville.
OK, so what have we done with this program?
Well, this is a simple eco program.
So you send the data and the science monitor here and then we receive the data and it will print the
data.
So the data you sent here, you will receive it here.
So let's make a try.
We are going to upload the program.
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
40 to a press, enter and I see 42.
OK, so what happened in the program?
So first we initialize this condition, right?
Nine thousand six hundred.
It's the same as here we enter the loop, then we check continuously very fast if there is some data
available from the site.
So of course, there is no data.
I send the number 42, the original receives the data and now say ALDRED available gives a positive
number.
So we intend if the function Sialkot percent we read the data 42, put it inside it to the viable here
and then we've sent the printer.
Then we just send back the value.
We received the contract with different numbers, etc. If we worked every time, if I said let's say
on text.
What happened?
Is that this is not the number, OK, OK, the information will simply return to zero, so we will get
to you.
And now one important thing to check is the option here you have at the bottom of this one.
So I have no line ending and this is what you should have.
This option is actually what the science monitor will do once you send an information here.
So with no line and we just send the data just like you writing.
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
have for it, but we have zero of.
Delights in another number, seven and zero.
But what happened here, what happened is that when you send a number, so if they send it to new line,
we add a new line character, the new line character is backslash.
And so this is what will be sent to the area and the admin when we first read in the number forty two.
And then it will read this character, which will be evaluated to zero.
So that's why you have the first character and then zero.
OK, so you have a new line, you have courage written and both new and I encourage written.
Make sure you select no line ending.
So when you send a number, you just have the number and not an additional zero.
OK, this is a quite common error you can get in your programs and you know how to solve that.
So now let's make a few experiments so we have an integer.
Let's say I want to send the big number.
So, you know, integer, the max value of integer is a thirty thousand something.
You don't need to be very precise.
You just need to know it's in that range.
Let's say you want to send fifty dollars.
I'm just going to press enter and oh we don't get fifty thousand, we get minus fifteen thousand five
hundred and thirty six.
This is because the integer here as overflowed.
So we have reached the maximum value.
And then what happened is that the value went back to the minimum and that's where you have a weird
number here.
So if you want to receive a larger number, you need to use long.
So let's send fifty thousand again and you will get the correct value.
OK, so you can receive integer long numbers, but you can also receive double float data type.
And to do that, instead of just means you will use Barth's float.
And it's quite easy not to make a mistake because this will turn.
All right.
Let's blow this.
And let's see, three point fourteen and we get the correct value, if I just sent an integer number,
you will see we have an integer, but this is actually represented as a float number.
OK, forty two point zero.
So you have bus and bus float.
And if you want to send a string, well, this is a bit different.
You have to use three train.
And of course, the data types would be drawing with a case.
Let's try this.
And let's send hello from the computer.
And we get hello from the computer, though that is quite convenient, but it does float and stream.
Make sure you have the correct data type and then you can process the data and whatever you want in
your program.
OK, just one thing I want to show you.
I'm just going to send back some text.
And just pay attention to the duration between the time when I send the data and the time when it is
printed here, I'm pressing.
And right now.
And you can see here the text the is after about one.
OK, one time again, a press enter.
And it's not directly here.
OK, it's here after but one again, and why is that?
This is because of the Celil time out.
So there is a time out for this terrible communication.
What is the time out?
Basically, when you do pass into past float or restring for those functions, for example.
So I will try to read and interpret the data.
And because it has a time out of once again, it will simply wait one complete so it can receive all
the information and then pass that information.
So these just in case the data is not just arriving at the same time and is a little bit delayed, which
can happen with any kind of communication.
But here for our use cases where we just send one piece of text or one integer, one float, and that
is send off very, very rapidly.
OK, so in order to reduce the time that is spent here on that function, we can do scenario that sit.
Time out again, turns around and said, time out in milliseconds, so the default one is one thousand
milliseconds next, but simply 10 milliseconds, it means that when we use the string function, this
will simply wait for 10 milliseconds.
To be sure, we received all the data and after ten milliseconds, any new data would be discarded.
But that's not a problem because when we send it here, the data will take less than 10 minutes to write.
So in this case, we will save almost one segment when using that function.
And one important thing is that first, so you do say at the beginning and it's the set time out, you
just do that once after saying, you know, let's apply the program.
And I'm just going to write some text again and I press enter and you can see the text here.
There's almost immediately.
Another time, OK, almost immediately.
In fact, it appears with a ten minute delay, and that is the same, so the time out will be the same
for the restringing, for bus float and for bus introductions.
All right.
So now you know how to receive and read the data from the cell communication on your arm in the world.
And just to show you how you can work with cell communication on Dinko Cazzo for the simulation.
Well, you have seen that in the science monitor here.
You would just see the data when you have and print print Allen, for example.
And here is actually where you will send data from the computer to the.
So that's quite similar to what you have with the science monitor.
With the two here is the same could have used to just done the simulation here to send a piece of string.
And so it goes to the other.
No, and then they are printed and you can see yellow on the side of Moniteau.