This is the first activity of this course.
What I'm going to do now is to give you a challenge and explain some steps or give you some tips to
solve the challenge.
In the next video, you will find the solution.
Of course, I really encourage you to try to do the activity by yourself before you go to the solution.
That's the only way to make progress.
And if you have some doubts, feel free to rewatch some of the previous lessons.
All right.
So your challenge for this activity is to power on or power off an on the Arduino from the Raspberry
Pi.
So on the Arduino, we actually well, we haven't created a circuit yet, but we have the built in Led.
So you have the built in Led, which is on PIN 13.
Okay.
So you can first create, for example, a define for that and then use pin mode with 13 and output and
then what you are going to do in the void loop is basically to read string from Serial.
So you're going to check if you have some data with Serial available, you're going to read the string.
And then depending on the value of that string, you are going to power on or power off the Led.
So of course you will need to agree on a common value you receive here and the value you send here.
Okay.
You need to send the same value that you're going to receive here.
So for example, that can be on and that can be off.
So when you receive on from you power on the Led, when you receive off from serial, you power off
the Led.
All right.
So that would be the code on the Arduino.
Now on the Raspberry Pi.
So first you are going to init communication.
So you have two choices.
Do we need the communication?
You can just open the serial and see what's happening, if it works or not, or you can also use the
try again mechanism that you have just coded in the previous section.
And then well, what you are going to do is you are going to send so you're going to send on.
Or off and how you are going to send that?
Well, what you could do is, for example, send on every second and then send off and then send on
again.
Send off every second.
All right.
But what we are going to do here is we are going to use the input function.
Okay.
So the input function in Python as a reminder, will ask for the user.
So in the terminal we ask for the user to give some data.
So for example, the string and then you can get the string into your code.
Okay?
So you can put for example, input with select on or off like this with maybe some quotes.
So you can ask the user to select on or off.
And then you read that and if the user gives on you, send on to the Arduino.
If the user gives off, you send off to the Arduino.
Okay.
So what you can do is put that input function inside a while.
True loop.
Okay.
To make kind of a void loop like we have on the Arduino.
So you first initialize communication and then you create a while loop to continuously get the user
input.
And whenever you get the user input, you send that input to the Arduino.
All right.
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
component on the Arduino.
All right.
And now once again, make sure to work on that challenge before you watch the solution.
Okay.
So spend some time working on this.
However, don't stay stuck for hours and hours, okay?
If you can't make it work, no worries at all because, well, for this course, the activities have
picked can be quite challenging.
So in this case, if you can't make it work, just watch the solution and then try to do the activity
again on your own a bit later.