Install raspberry pi & Sensor
connect
通訊工程系
通訊網路實驗
Lab 3 家庭網路實驗 (IoT 實驗 )
Week 1
INSTALL RASPBERRY PI
Outline
Introduction
Build up system
Enable UART serial
Configure network
Connect to Pi (SSH and VNC)
3
Notice
The content of this slide is based on Pi 3 model B and
Raspbian March 2018 which was released on March 13,
2018.
If your Pi 3 is model B+, please visit the following URL to
see the difference.
[Link]
xt
4
Introduction
Raspberry Pi 3 model B Raspberry Pi 4 Model B
Release date 29 February 2016 24 June 2019
Operating system Raspbian, CentOS, Fedora, Ubuntu MATE, Kali Linux (incl Raspberry Pi OS), FreeBSD, NetBSD,
Linux, Ubuntu Core, Windows 10 IoT Core, OpenBSD, Plan 9, RISC OS, Windows 10
RISC OS, Slackware, Debian, Arch Linux ARM, ARM64, Windows 10 IoT Core and OS-less
Android Things, SUSE, FreeBSD, …. Embedded RTL's
System on a chip Broadcom BCM2837 Broadcom BCM2711B0
CPU 1.2 GHz 64/32-bit quad-core ARM Cortex-A53 1.5 GHz quad-core A72 64-bit
Memory 1 GB LPDDR2 RAM at 900 MHz 1, 2, 4, or 8 GB LPDDR4-3200 SDRAM
Storage MicroSDHC slot MicroSDXC slot, USB Mass Storage device
Graphics Broadcom VideoCore IV at higher clock Broadcom VideoCore VI 500 MHz
frequencies (300 MHz & 400 MHz) than
previous that run at 250 MHz
Power 1.5 W (average when idle) to 6.7 W 5 V; 3 A (for full power delivery to USB devices)
5
From [Link]
Introduction
Raspberry Pi 3 model B Raspberry Pi 4 model B
Ethernet
40 GPIO Pins
Micro SD
USB Port * 4
cad slot Micro SD
(on the cad slot
back of Pi) (on the
back of Pi)
USB Port * 4
micro USB power HDMI Ethernet
supply (2A, 5V) USB Type-c power HDMI
Camera interface (CSI) supply (3A, 5V) Type D Camera interface (CSI)
*2 6
From [Link]
Introduction
General-purpose input/output (GPIO)
Note that the physical PIN number is different from the GPIO
number.
7
From [Link]
Build up a system
Now, let we set up our Raspberry Pi system.
Method 1
First, we need to download a Raspberry Pi operating system
image file.
Then, we need to write that image to a SD card.
Method 2
We need to download a Raspberry Pi Imager to download
operating system image file and write that image to a SD card.
8
Build up a system
Method 1
Step 1 - Download OS
Download OS from
[Link]
9
Build up a system
Method 1
Step 2 - Writing an image to a SD card
To write an image to a SD card, the easy way is using
Etcher which works on Mac OS, Linux and Windows. (May
take long time to write the image)
10
Build up a system
Method 1
Step 2 - Writing an image to a SD card(Method 1)
Open Etcher and follow these 3 steps
11
Build up a system
Method 1
Step 2 - Writing an image to a SD card(Method 2 for
windows)
Format a SD card on Windows
Step1. Download this tool
Step2. Select your SD card
Step3. Format the SD card
12
Build up a system
Method 1
Step 2 - Writing an image to a SD card(Method 2 for
windows)
Write an image to SD card on Windows
Step1. Download this tool
[Link]
diskimager/?source=typ_redirect
Step2. Select your image file
Step3. Write the image to your SD card
13
Build up a system
Method 1
Step 2 - Writing an image to a SD card(Method 2 for MacOS)
Step1. Format the SD card
Disk Utility: Format the SD card to FAT32
Step2. install the image to the SD card
Terminal:
diskutil list: check the number of SD card
Ex: disk1s1
sudo diskutil unmount /dev/disk1s1
sudo dd bs=1m if=[image file path] of=[disk number]
Ex: sudo dd bs=1m if=2017XXX of=/dev/rdisk1
14
Build up a system
Method 2
Step 1 - Download Raspberry Pi Imager
Raspberry Pi Imager from
[Link]
15
Build up a system
Method 2
Step 2 – Select OS and SD card
1 3 4
16
What's next ?
As we eject the SD card after Raspbian has been installed
in it, we should consider how to operate Pi as Pi might not
connect to Internet.
Have a monitor with HDMI cable, a USB keyboard and mouse.
Yes No
1. Use UART to connect (TTL serial)
Operate Pi directly and have fun. 2. SSH connection with Internet (IP needed)
3. VNC connection with Internet (IP needed)
17
Enable UART
At the first time, your Raspberry pi has no Internet
connectivity and doesn't enable SSH.
So, we have to turn on the UART port (TTL serial) to
connect our Pi and then configure network settings and
enable SSH.
PL2303HXD
USB to TTL
We will use this PL2303HXD cable in this tutorial.
18
Enable UART
Before the next step
As we need to modify some files in the SD card, we
recommend to use Notepad++ or other editor to modify
files because the default Notepad of Windows might have
encoding issues with that file.
Notepad++
[Link]
Don't forget to inject your SD card into your computer
again.
19
Enable UART
Before the next step
If you are using Windows,
you will need Putty to
connect your Pi by
UART/TTL serial.
Download and install Putty.
[Link]
[Link]/~sgtatham/putt
y/[Link]
20
Enable UART
Step 1
Append the following lines
to /boot/[Link]
dtoverlay=pi3-miniuart-
bt
core_freq=250
enable_uart=1
21
Enable UART
Step 2
Delete "quiet" in
/boot/[Link]
Remove it
22
Enable UART
Step 3
Create file in
/boot/[Link]
pi:
$6$c70VpvPsVNCG0YR5$l5vWWL
sLko9Kj65gcQ8qvMkuOoRkEagI
90qi3F/
Y7rm8eNYZHW8CY6BOIKwMH7a3Y
YzZYL90zf304cAHLFaZE0
23
Enable UART
After we have modified /boot/[Link] and
/boot/[Link] in the SD card, we can eject the SD card
from our computer and inject it into a Raspberry Pi.
24
Enable UART
Step 3
Let Pi connect to TTL-to-
USB cable as follows
Pin6: black line
Pin8: white line
Pin10: green line
25
Enable UART
Step 4
Download PL2303 drive and install it
Windows:
[Link]
=41
If your OS is Windows10, you can forward to next step to check
that whether your computer could find COM port or not.
Mac OS:
[Link]
=41
26
Enable UART
Step 5
As PL2303 drive is installed, we should turn on Raspberry
Pi and connect it to our computer by USB to TTL cable.
Then, checking that our computer could find the USB to
TTL cable.
The different OS systems have different ways for
checking, thus the following are for Windows and Mac OS .
27
Enable UART
Step 6-1 (for Windows)
Open Device Manager and
make sure that PORTs(COM
& LPT) has USB-to-Serial
Comm Port (COM x)
We will use that port to
connect to Pi.
28
Enable UART The number you see in
USB-to-Serial Comm
Port (COM x)
Step 6-2 (for Windows)
Then, open Putty
1
3 Set Speed as
4
115200
29
Enable UART
Step 6 (for MacOS)
Open the terminal and type:
ls /dev/cu*
If /dev/[Link] appears,
we can connect to pi by
screen
screen /dev/[Link]
115200
Screen user's manual
[Link]
screen/manual/[Link]
30
Enable UART
(for Windows)
Step 7
If we connect to Pi
successfully, we could
type username and
password
Default setting
username: pi
(for MacOS)
password: raspberry
31
Common commands in Linux
terminal
Commands:
ls: list files in this directory
cd: change directory to other directory
e.g., cd home/pi/test
cd ..: change directory to the upper directory
cd ~: change directory to home/pi
sudo shutdown: shutdown the system
e.g., sudo shutdown –h now : shutdown the system immediately
sudo reboot: restart the system
Useful tips:
Press "↑": show the last command
Press "Tab": auto complete
32
Configure network
After we connect to our Pi by UART, we can configure the
network settings of Pi.
Now, let we configure the WiFi settings.
Before configure the WiFi, we should check our device has
WiFi Interface wlan0, type:
ifconfig
33
Configure network (Setup Hotspot)
Windows Hotspot Setting
If you have Wi-Fi connection, SKIP this part. If not, you can use notebook as hotspot.
Step1(Windows11) Step1(Windows10)
34
Configure network (Setup
Hotspot)
Windows Hotspot Setting
If you have Wi-Fi connection, SKIP this part. If not, you can use notebook as hotspot.
Step2(Windows11) Step2(Windows10)
35
Configure network (Setup
Hotspot)
Windows Hotspot Setting
If you have Wi-Fi connection, SKIP this part. If not, you can use notebook as hotspot.
Step3(Windows11) Step3(Windows10)
2
1
SSID
Password
1
SSID
Password
36
Configure WiFi
We can configure WiFi by these 2 ways
raspi-config
Modify wpa-supplicant configuration file
The following introduces how to configure WiFi by raspi-
config.
Type:
sudo raspi-config
37
Configure WiFi
Method 1 - Step 1
Select 1 System Options
38
Configure WiFi
Method 1 - Step 2
Select S1 Wireless LAN
39
Configure WiFi
Method 1 - Step 3 Step 4
Enter your WiFi AP's SSID Enter passphrase of that
SSID
40
Configure WiFi
Method 1 - Step 5
Verify whether your Pi has successfully connected.
Type
ifconfig wlan0
If inet address field has no address, redo the step 1-4
41
Configure WiFi
Method 2 - Step 1
Type sudo nano
/etc/wpa_supplicant/wpa_supplicant.conf
Check the following two fields are correct. If not, modify
them and reboot Pi
network={
ssid="SSID of AP"
psk="password"
…
}
42
Connect to Pi
After we have set up the network of Raspberry Pi, we can
connect that Pi by SSH or VNC without using TTL cable.
We recommend you using SSH.
Mac OS/Linux users use terminal and Windows users need
install SSH client
SSH clients on Windows
Putty
OpenSSH (Win10 can enable it)
43
Connect to Pi (SSH)
Before using SSH to login Pi, we have to enable SSH of Pi
first. sudo raspi-config
Type
44
Connect to Pi (SSH)
Select I2 SSH Enable SSH
45
Connect to Pi (SSH)
PUTTY
Then, we open Putty to connect Pi by SSH.
46
Connect to Pi (SSH)
Mac OS terminal
If we are using Unix-like system, just opening the terminal
and typing:
ssh pi@"your_Pi_IP"
47
Connect to Pi (VNC)
Before using VNC, we have to enable VNC of Pi first.
Type sudo raspi-config
48
Connect to Pi (VNC)
Select I3 VNC In addition to SSH, VNC
provides a remote desktop
environment.
49
從 GitHub 上索取程式碼
git clone [Link]
[Link]
50
SENSOR CONNECT
51
Outline
Introduction
Digital sensors
52
Introduction - Tool
Pi 3 / Pi 4 電源線 Pi cam
SD Card TTL DHT22
53
Introduction - Sensors
Collision sensor Pressure sensor Light sensor LED
Distance sensor Motion detector Gas sensor PM2.5 dust sensor
54
Introduction - Datasheet
55
From [Link]
Introduction - Digital & Analog
56
From [Link]
Introduction - GPIO
General-purpose input/output (GPIO)
Board Board
BCM
57
From [Link]
Introduction - Breadboard
58
From [Link]
Digital sensors - LED
Light-emitting diode (LED)
Features
Efficiency
Long lifetime
Cool light
… Vcc
GND
59
Digital sensors – LED Lab1: Blink Signal
Connecting Diagram(file: 02_3-led blink signal)
60
Digital sensors – LED Lab1: Blink Signal
If you download the
Code(file: 02_3-led blink signal)
import [Link] as GPIO
code from online in
page50, just run the
import time
[Link]([Link])
LED_PIN = 12
[Link](LED_PIN, [Link]) code in python.
pwm_led = [Link](LED_PIN, 100)
pwm_led.start(0)
duty = 1 python "gpio-game-
addormin = 1
try:
console/02_3-
led_blink_signal/02_
while True:
addormin = (duty == 100 and -1) or (duty == 1 and 1) or addormin
pwm_led.ChangeDutyCycle(duty)
duty += addormin
[Link](0.01)
except KeyboardInterrupt: 3-led blink
signal/.py"
print("Exception: KeyboardInterrupt")
finally:
pwm_led.stop()
[Link]()
61
Digital sensors – LED Lab2: Traffic Light
LED-Lab2 Connecting Diagram(file: 03_2-traffic_light)
pin11
pin12
pin13
62
Digital sensors – LED Lab2: Traffic Light
Code(file: 03_2-traffic_light)
import [Link] as GPIO
import time
[Link]([Link])
RED_PIN = 11 # GPIO17
YEL_PIN = 12 # GPIO18
GRN_PIN = 13 # GPIO27
[Link](RED_PIN, [Link], initial=[Link])
[Link](YEL_PIN, [Link], initial=[Link])
[Link](GRN_PIN, [Link], initial=[Link])
def TrafficLight(pin, duration):
[Link](pin, [Link])
[Link](duration)
[Link](pin, [Link])
try:
while True:
TrafficLight(RED_PIN, 4);
TrafficLight(YEL_PIN, 2);
TrafficLight(GRN_PIN, 4);
except KeyboardInterrupt:
print("Exception: KeyboardInterrupt")
finally:
[Link]()
63
課後練習
64
實驗一
Install raspberry pi & Sensor connect
課堂檢查點
1. SSH 連線到樹莓派螢幕截圖畫面
2. LED 紅綠燈實驗展示
結報題目
1. 請附上實驗結果照片
▸ <TTL(Putty) 有線接上樹莓派照片 >
▸ < 使用 VNC/SSH 連線到樹莓派螢幕截圖 >
2. 請詳述樹莓派從接上電腦到無線連線的過程
3. 請簡單列出五個樹莓派 terminal 的指令並說明功能為何?
65
Thank you