Abstraction: An abstraction is a representation of an object or concept. It could be something such as a door, a speedometer, or a data structure in computer science. Abstraction decouples the design from the implementation. The gauges in an automobile are an abstraction of the performance of a car. A map is an abstraction of the earth.
Modularization: The concept of modularity is like building blocks. Each block (or module) can be put in or taken out from a bigger project. Each module has its own separate function that is interchangeable with other modules.
Simplicity: Simplicity allows a person to better understand hardware and software. Without the clutter of unnecessarily complicated code and interfaces, the software will be more understandable by people that will update the code when requirements change. It will be easier to understand by the testers and they will be able to spot problems sooner. By keeping software as simple and as focused as possible, the reliability and security is greatly increased.
Resource Encapsulation: Encapsulation is an object oriented concept where all data and functions required to use the resource are packaged into a single self-contained component. The goal is to only allow access or manipulation of the resource in the way the designer intended. An example, assume a flag pole is the object. There are fixed methods on how the flag pole is to be used. Put the flag on, take the flag off, raise or lower the flag. Nothing else can be done to the flag pole.
In this lesson, we will explore a cool hands-on technology called Raspberry Pi. Raspberry Pi follows a component-based design paradigm using GPIOs (or general purpose input/outputs) to let you easily write apps and connect them to hardware components. In this lesson, you will build your Raspberry Pi and connect it to a sensor. Raspberry Pi will be the central platform used for the rest of camp. Multiple other camp lessons build onto this one.
By the end of this module, you will be able to:
modularity
principle to component-based design frameworks like Raspberry PINone
First, open your Raspberry PI box. Take a second to look at the different components you have.
Here is a diagram of the different modular interfaces
on your PI.
Find your Quick Start Guide
and turn to page 03. Follow the steps shown to install the heatsinks
.
Once your heatsinks are installed, insert the SD Card
into the slot on the bottom of the board.
This SD card has an operating system called Raspbian
pre-installed on it. Raspbian is like other operating systems you may be familiar with like windows, linux, or MacOS.
The operating system also has several programs we will use during the camp pre-installed on it.
Next, we are going to configure your Pi to interface with a range of different components using GPIO
ports.
GPIO ports, an acronym for General-purpose input/output
ports are simplified interfaces that allow a device to read or write data to the PI. Programs on your PI can control the ports to allow code to interface
with sensors
or actuators
.
GPIO
is a form of modularity
that arises from using a standard interface. The nice part of standard interfaces is that it means the device doesn’t need to understand or know anything about what they are connected to. This is a great example of the modularity
cybersecurity first principle.
Your PI has a 40 pin GPIO header block
(See labeled diagram above). Since it can be tricky to directly connect to these pins, it is often easier to use a breadboard
. A breadboard is just a circuit board with multiple pin slots that can be used to wire components together.
Find your breadboard by unboxing your SunFounder Sensor Kit.
The breadboard is the component in the upper left of the diagram above.
Also locate your GPIO Extension Board
component. It is a read chip with multiple labels on it (third from top left in the diagram above.)
Finally, locate the ribbon cable
(rainbow colored cable on the lower left of the diagram above).
Carefully socket your GPIO Extension Board
into the broad board as shown below, then connect the ribbon cable
to the GPIO Extension Board
and finally, using the other end, carefully connect it to your Raspberry PI. The resulting setup should look like this:
Page 34 of your Sunfounder Sensor kit booklet also has additional information that you might want to read.
Next we will install a 4in LCD Touch Screen, so that you can see and interact with your PI.
Go ahead and open the box. The components inside, should look something like this:
I recommend you keep the packaging so that you can house your screen in it.
Locate a 2-pin red/black cable from your Sunfounder kit package. Connect the 2-pin cable
to the back of the LCD screen as follows.
Connect the ends of the 2-pin cable
to the breadboard
like as shown in the upper left of the image below. The black cable should connect to the -
sign and the red should connect to the +
symbol.
Now, use some additional male-to-male jumper cables
from your SunFounder kit to connect the 5VD
pin on the GPIO Extension Board
to the +
channels on your breadboard. Also connect the GND
pin to the -
channels on your breadboard.
Your setup should look like the image below. I like to use red cables to represent power (or 5v) and black to be the ground (GND).
Alright, we have a screen, we have a computer (the PI), now we need to connect the keyboard and mouse to the usb ports on the PI.
Once you have those connected, connect the power cable to the PI and turn it on, by flipping the switch.
Your PI should light up and start booting up.
Once your PI has booted up, it will step you through a wizard with a few screens to setup a password and configure the device.
It should look something like this:
We recommend you use a easy to remember password that you can share with the students or other device users in your classroom. For the purposes of this example, we recommend using nebraskagencyber
as the password and use the default username pi
.
In practice, if you were to deploy this device as an actual IoT device on a production network, you would want to follow a more secure configuration.
At this point, you can click skip
for updates and skip
for connecting to WiFi.
Once setup, you should see a Raspbian default desktop that looks like this:
bi-directional arrows
in the top right of the screen.command terminal
by clicking on the red Raspberry PI icon
on the upper left, then select accessories
, then select terminal
.ifconfig
wlan0
interface (shown in a red box), then find the mac address
information in the pink box next to the word ether
. Wlan0 is just a fancy name for the 0th wireless local area network interface
. The mac address is kind of like your device’s unique name that differentiates itself from all other devices. We are going to use this information to setup your connection. Just come talk to a Nebraska GenCyber staff member, bring us this address, and we will give you a password to connect to the NU-IoT WiFi network.bi-directional arrows
in the top right of the screen.NU-IoT
and then enter the password we give you as the pre-shared key
it asks for.Your Raspberry PI touch screen is by default in portrait mode.
We need to install a driver
to help your PI better use the screen and to allow it to use landscape mode
to make it easier to see.
To do this, go back to the terminal and type the following command:
sudo rm -rf LCD-show
git clone https://github.com/goodtft/LCD-show.git
chmod -R 755 LCD-show
cd LCD-show
sudo ./MPI4008-show
Wait a bit as the driver is installed. Once it is done, you can restart your PI and it should be in landscape mode.
Your Sunfounder box contains a whole range of sensors and actuators. A diagram of every part can be found on pages 1 to 8 of the Sunfounder guide booklet.
Each part is a component
. Components generally all need power
(often labeled as vcc
), ground
(labeled as gnd
), and a signal
(labeled sig
).
We will be wiring up the components to create inventions and solve problems in the internet of things.
Before we start working with our first components, we need to setup a few libraries. Go back to the terminal on your pi and type the following, one line at a time.
cd /tmp
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
cd ~
Then check to make sure you see v 2.52 when you type gpio -v
cd /home/pi
git clone https://github.com/sunfounder/SunFounder_SensorKit_for_RPi2
These instructions are also located in the SunFounder booklet on pages 37-39.
Now that we have our component libraries installed, lets try out some of the lessons from the SunFounder booklet to learn about individual components.
The booklet has numbered lessons, starting on page 40, that showcase each component. Each lesson includes a wiring diagram
, a code sample, and details about what the component does. Lets take a look at Lesson 1 for the LED module
.
The Lesson has you prepare a wiring diagram that looks like this:
Follow the instructions for the python code. We will be using python throughout the rest of the camp.
Run the code sample by executing the following commands on your terminal:
cd /home/pi/SunFounder_SensorKit_for_RPi2/Python/
sudo python3 01_dule_color_led.py
This should result in a flashing light like this:
Try out some other components in the box - find the lesson number for each one.
–>
For more information, investigate the following:
SunFounder GitHub Repository for Raspbery PI 4 Sensors
Matt Hale
Special thanks to Dr. Robin Gandhi for reviewing and editing this lesson.
Nebraska GenCyber
is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Overall content: Copyright (C) 2017-2021 Dr. Matthew L. Hale and Dr. Robin Gandhi.
Lesson content: Copyright (C) Dr. Matthew L. Hale 2021.
This lesson is licensed by the author under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.