Introduction to Components

Cybersecurity First Principles in this lesson

Introduction

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.

Goals

By the end of this module, you will be able to:

Materials Required

Prerequisite lessons

None

Table of Contents

Step 1: Unbox it!

First, open your Raspberry PI box. Take a second to look at the different components you have.

unbox

Here is a diagram of the different modular interfaces on your PI.

unbox

Step 2: Gotta start somewhere

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.

sdcard

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.

Step 3: Setting up the bread board

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.

unbox

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:

sdcard

Page 34 of your Sunfounder Sensor kit booklet also has additional information that you might want to read.

Step 4: Install the LCD Touch Screen Display

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:

lcd unbox

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.

lcd screen

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.

lcd screen

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).

lcd screen

Step 4: Peripherals, Power, and First Boot-up

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.

Step 5: Password and OS Setup

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: pi wizard setup

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.

Step 6: Welcome to your Raspbian Desktop and Connecting to the internet

Once setup, you should see a Raspbian default desktop that looks like this:

pi desktop

Step 7: Landscape Screen Setup

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.

Step 8: Ready for some component-based design action!

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: led lesson

credit SunFounder_SensorKit_for_RPi2 manual

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: led lesson

Self Exploration

Try out some other components in the box - find the lesson number for each one.

–>

Additional Resources

For more information, investigate the following:

SunFounder GitHub Repository for Raspbery PI 4 Sensors

Lead Author

Matt Hale

Acknowledgements

Special thanks to Dr. Robin Gandhi for reviewing and editing this lesson.

License

Nebraska GenCyber Creative Commons License
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.
Creative Commons License
This lesson is licensed by the author under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.