WEBVTT

00:00.110 --> 00:02.890
This is the first activity of this course.

00:02.900 --> 00:08.750
What I'm going to do now is to give you a challenge and explain some steps or give you some tips to

00:08.750 --> 00:10.040
solve the challenge.

00:10.040 --> 00:13.340
In the next video, you will find the solution.

00:13.340 --> 00:19.520
Of course, I really encourage you to try to do the activity by yourself before you go to the solution.

00:19.520 --> 00:22.820
That's the only way to make progress.

00:22.820 --> 00:27.860
And if you have some doubts, feel free to rewatch some of the previous lessons.

00:28.100 --> 00:28.520
All right.

00:28.520 --> 00:36.440
So your challenge for this activity is to power on or power off an on the Arduino from the Raspberry

00:36.440 --> 00:36.770
Pi.

00:37.220 --> 00:44.030
So on the Arduino, we actually well, we haven't created a circuit yet, but we have the built in Led.

00:44.030 --> 00:50.980
So you have the built in Led, which is on PIN 13.

00:51.890 --> 00:52.050
Okay.

00:52.100 --> 00:59.810
So you can first create, for example, a define for that and then use pin mode with 13 and output and

00:59.910 --> 01:08.550
then what you are going to do in the void loop is basically to read string from Serial.

01:08.550 --> 01:14.610
So you're going to check if you have some data with Serial available, you're going to read the string.

01:14.610 --> 01:21.900
And then depending on the value of that string, you are going to power on or power off the Led.

01:21.930 --> 01:28.590
So of course you will need to agree on a common value you receive here and the value you send here.

01:28.620 --> 01:28.830
Okay.

01:28.830 --> 01:31.830
You need to send the same value that you're going to receive here.

01:31.830 --> 01:36.150
So for example, that can be on and that can be off.

01:36.150 --> 01:43.230
So when you receive on from you power on the Led, when you receive off from serial, you power off

01:43.230 --> 01:43.860
the Led.

01:44.190 --> 01:44.760
All right.

01:44.760 --> 01:47.190
So that would be the code on the Arduino.

01:47.580 --> 01:49.230
Now on the Raspberry Pi.

01:49.260 --> 01:54.210
So first you are going to init communication.

01:54.600 --> 01:55.770
So you have two choices.

01:55.770 --> 01:56.640
Do we need the communication?

01:56.640 --> 02:02.340
You can just open the serial and see what's happening, if it works or not, or you can also use the

02:02.340 --> 02:06.270
try again mechanism that you have just coded in the previous section.

02:06.270 --> 02:12.750
And then well, what you are going to do is you are going to send so you're going to send on.

02:13.920 --> 02:17.070
Or off and how you are going to send that?

02:17.070 --> 02:23.910
Well, what you could do is, for example, send on every second and then send off and then send on

02:23.910 --> 02:24.210
again.

02:24.210 --> 02:25.380
Send off every second.

02:25.410 --> 02:25.800
All right.

02:25.800 --> 02:31.170
But what we are going to do here is we are going to use the input function.

02:31.170 --> 02:31.380
Okay.

02:31.380 --> 02:36.600
So the input function in Python as a reminder, will ask for the user.

02:36.600 --> 02:40.320
So in the terminal we ask for the user to give some data.

02:40.320 --> 02:45.060
So for example, the string and then you can get the string into your code.

02:45.150 --> 02:45.410
Okay?

02:45.420 --> 02:54.780
So you can put for example, input with select on or off like this with maybe some quotes.

02:55.540 --> 02:58.060
So you can ask the user to select on or off.

02:58.060 --> 03:03.220
And then you read that and if the user gives on you, send on to the Arduino.

03:03.250 --> 03:07.180
If the user gives off, you send off to the Arduino.

03:07.330 --> 03:07.920
Okay.

03:07.930 --> 03:11.890
So what you can do is put that input function inside a while.

03:11.920 --> 03:12.540
True loop.

03:12.550 --> 03:12.740
Okay.

03:12.790 --> 03:16.270
To make kind of a void loop like we have on the Arduino.

03:16.270 --> 03:23.080
So you first initialize communication and then you create a while loop to continuously get the user

03:23.080 --> 03:23.440
input.

03:23.440 --> 03:27.670
And whenever you get the user input, you send that input to the Arduino.

03:28.150 --> 03:28.570
All right.

03:28.570 --> 03:35.680
So here what we are going to be able to do is to get user input on the Raspberry Pi to power on a hardware

03:35.680 --> 03:37.510
component on the Arduino.

03:37.510 --> 03:38.170
All right.

03:38.320 --> 03:43.510
And now once again, make sure to work on that challenge before you watch the solution.

03:43.510 --> 03:43.900
Okay.

03:43.900 --> 03:46.770
So spend some time working on this.

03:46.780 --> 03:50.860
However, don't stay stuck for hours and hours, okay?

03:50.860 --> 03:56.120
If you can't make it work, no worries at all because, well, for this course, the activities have

03:56.120 --> 03:58.580
picked can be quite challenging.

03:58.580 --> 04:04.100
So in this case, if you can't make it work, just watch the solution and then try to do the activity

04:04.130 --> 04:06.950
again on your own a bit later.
