line. First, we will see the simplest program to understand how to execute python code. Then
we will get into the syntax and learn more about python.
Let’s start our first program. We will begin with “Hello World!”.
For the sake of this first exercise, we will simply use the Python interpreter, which permits
us to test our code on the command line one at a time.
Open a terminal window, and type the following command
python
Once you press enter, you will be presented with three greater-than signs >>>
On that prompt type the following command
Print(“Hello World”)
And after pressing enter, you will see “Hello World” back on the terminal window.
You can come out of this interpreter window by entering the following command
exit()
As you can see, how easy it is to run python commands. However, this approach is only suitable
for testing out commands. For the serious type of programming, you can create a file and add
all the commands into that. Once you are done, save the file and close.
Now, let’s see how it works. Create a new file in any text editor you like. If you are on a full
desktop mode, use Leafpad application. If you are using the lite version, use nano editor to cre-
ate file. Enter the commands into a new file and save it with a name “helloworld.py”.
Once you saved the file, on command prompt type the following command to run this file.
python helloworld.py
This will print “Hello World” on the command prompt. It is beyond the scope of this book
to cover Python in details. Hence, I would recommend you to learn the basic of Python.
Exercises
1. Create a basic Raspberry Pi diagram and label its components with their uses.
2. Connect external sources with Pi and test their working.
3. Similar to St Joseph’s case study in the educational sector, a case study for a Pi-related
to manufacturing.
4. What Is PiNet? Explain it in detail.
5. Make a robot by using Raspberry Pi. This time, use Python for programming.
6. What is Arduino? Provide two real-world examples for its effective use.
7. Explain the working and features of an Arduino board other than Uno with a labeled
diagram.
8. Write a user-defined function which displays your name on any screening device.
9. Use an array to get input from a sensor and compute an output.
10. Create a simple example using Boolean values (ON/OFF).
11. Build a program which uses pinMode function and writes an example featuring both
input and output.
Chapter 13 Hands-On Examples of IoT Experiments 337
Internet_of_Things_CH13_pp327-348.indd 337 9/3/2019 10:17:04 AM
Get Internet of Things now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.