CS664 IoT System Design
July 7th, 2018
Lab Exercise 4
Getting Familiar with Raspberry Pi 3
I. Setting up (Initialization) Raspberry PI
Following items are required for the basic setup of Raspberry PI:
VGA to HDMI Cable
Monitor
USB Keyboard
USB Mouse
2A (2,000 mAh) microUSB power supply, charger or adapter
Min. 8GB micro SDCard
Use following steps to load the UbuntuMate OS into Raspberry PI:
Step 1. Download the Ubuntu Mate from https://ubuntu-mate.org/download/
Step 2. Unzip the file and end up with an .img file
Step 3. Download and install Win32DiskImager https://sourceforge.net/projects/win32diskimager/ in
Windows OS
Step 4. Run the Win32DiskImager
Step 5. Plug the SD Card into your PC
Step 6. Select the Device and browse the Image File as in step # 2
Step 7. Click on Write button
II. Enabling SSH in Ubuntu Mate
Follow below steps to enable ssh in Ubuntu Mate:
Step 1. Open the terminal and enter the command sudo raspi-config
Step 2. Navigate to SSH in the Interfacing Options.
Step 3. Enable SSH
III. Accessing Raspberry Pi GPIO Pins
Raspberry PI board has 40 GPIO pins on one edge of the board. All GPIOs can be configured as either
digital output or digital input. When a GPIO pin is configured as digital output, onboard controller can
turn it high or low. An external digital signal can be sensed by the controller when applied to GPIO which
is configured as input. Visit following link for details on the GPIO pins available on Raspberry Pi board:
https://www.raspberrypi.org/documentation/usage/gpio/
Image source: https://www.jameco.com
IV. Connect to Raspberry PI using VNC viewer
You can connect to your RPi remotely, using VNC viewer. VNC viewer is used for remote accessing
desktop of other PC. Follow these steps to install VNC viewer on your laptop PC and connect to RPi:
Step 1. Download and install the VNCViewer from the
https://www.realvnc.com/en/connect/download/viewer/ .
Step 2. Run the VNCViewer and type the IP address of your Raspberry Pi board. (Press Enter)
(Ask your instructor for the IP address of your board.)
Step 3. It will prompt login dialog box. Enter the following credentials
Username: gts-pc
Password: gts
Step 4. Now you can access RPi’s desktop
V. Lab Exercise (i) : Blinking LED
In this exercise you have to configure one of the GPIO pins as digital output, and blink the LED.
Following additional items are required:
1 LED
2 Male To Female Jumper Wires (optional)
1 Breadboard (optional)
Laptop/PC
The LED's terminal should be connected to RPi as shown in the below table
LED’s terminal PI pin
Negative 14 (GND)
Positive 13 (GPIO 17)
Here is a LED's terminal connected to the RPi’s GPIO header
Image Source: https://commons.wikimedia.org/wiki/File:Raspberry_Pi_3_illustration.svg
Follow these steps to run the Python script on RPi for blinking the LED:
Step 1: Connect to RPI’s desktop using VNC Viewer
Step 2: Download blinking_led.py directly on RPi, from the following URL:
https://drive.google.com/open?id=1rH0rHAdRSaP3RTBukamBg5bEiLdzY5lj .
Step 3: Go through blinking_led.py. Make sure that you understand the process of configuring GPIO as
output and toggling it at regular interval. (What is the on and off time of the LED?)
Step 4: Open the terminal and run the blinking_led.py
sudo python blinking_led.py
Step 5: Check whether LED is blinking or not.
VI. Lab Exercise (ii): Real-time plot of temperature and humidity on PC
As part of this lab exercise, you would configure GPIO as input (Choose a different pin this time), hook
up a temperature and humidity sensor to it, retrieve the data on your laptop and finally plot it in real-
time.
You would need following additional items for setup:
5 Male To Female Jumper Wires
1 Breadboard
DHT11 temperature and humidity sensor (Go through the datasheet)
10k ohm resistor
Laptop/PC
Q: What is the operating voltage of DHT11? Does it give analog output?
The 3 pins of DHT11 sensor should be connected to the Pi as shown in the below table.
DHT’s pin Signal Pi’s pin
VCC 3.3 V 1
Data /Output Data/Out 11 (GPIO 17)
GND Ground 9
Here is DHT’s pin connected to the Pi’s GPIO header
Image Source: https://commons.wikimedia.org/wiki/File:Raspberry_Pi_3_illustration.svg
You also need to carry out following steps to do software setting on RPi, for retrieving data from sensor
(PLEASE SKIP THESE STEPS. ALREADY DONE.):
Step 1. Update the package list and install the git
sudo apt-get update
sudo apt-get install git
Step 2. Then clone Adafruit library from repository and install it
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo python setup.py install
Python script for Raspberry Pi
DHT11_sensor.py - https://drive.google.com/open?id=1N5WSwvAfyZFESnIvx7MnrMbRcEbmrltB
Download the file directly on RPi board. It allows RPi to
- act as a socket server and
- send temperature and humidity data to client on PC whenever the data is available.
Python script for Laptop
Temp_n_Humdity_Monitor.py - https://drive.google.com/open?id=11EiddOTzJE2uP1GHHxKZCs3-Y-
x1UqpS
Download the file on laptop/PC. It allows the laptop/PC to
- receive temperature and humidity data from RPi's
- plot the graph and
- log the data in a file
Follow the below mentioned steps to run the platform.
Step 1: Connect to RPI’s desktop using VNCViewer
Step 2: In RPi, open the terminal (through VNC Viewer) and run the DHT11_sensor.py
sudo python DHT11_sensor.py
Step 3: In PC/laptop, open the terminal and run the Temp_n_Humdity_Monitor.py
sudo python Temp_n_Humdity_Monitor.py
VII. Lab Exercise (iii): Blink the LED when temperature exceeds certain
threshold
1. LED should blink only when the temperature rises above certain threshold. The threshold
temperature will be given to you by instructor or TA. The LED should blink with 25% duty cycle,
i.e. 0.5 sec on time and 1.5 sec off time. (Show the outcome to TA or instructor.)
2. Modify the design such that LED blinking frequency increases with increase in temperature.
VIII. For submission:
1. Present comparative study between Arduino and Raspberry Pi, in tabular form. You have to
compare the two on 10 points. So, choose these 10 points judiciously. Please restrict the study
to one page only.