1 of 217

EE 629 �Internet of Things �Lesson 2: Raspberry Pi

Kevin W. Lu

2024-09-28

2 of 217

Lesson 2: Raspberry Pi

  • Raspberry Pi OS imager and images
  • Virtual network computing (VNC) server and viewer
  • Raspberry Pi configuration and raspi-config
  • General-purpose input/output (GPIO) including
    • Serial or universal asynchronous receiver-transmitter (UART) to access either Linux console or other devices
    • Serial peripheral interface (SPI)
      • Main/microcontroller in secondary/sensor out (MISO)
      • Main/microcontroller out secondary/sensor in (MOSI)
      • Serial clock (SCLK) and chip enable (CE0/CE1)
    • Inter-integrated circuit (I2C) synchronous interface
      • Serial data line (SDA) and serial clock line (SCL)
    • 1-Wire interface with data input/output (DQ) signal line
  • Sensors, actuators, and communication modules

2

3 of 217

Lab 2A — GPIO and Serial

On the SSH Terminal, enter "sudo nano /boot/cmdline.txt"

  • Delete "console=serial0,115200" if found
  • Save the file with control-x y enter
  • Enter "sudo reboot"

Connect two serial pins (the 4th and 5th pins from the left of the top row) using one jump wire

  • Enter "sudo apt install minicom"
  • Enter "minicom -b 115200 -o -D /dev/ttyS0" for serial loopback test by typing
    • control-a a (to enable new line) then hello
    • control-a e (to enable echo) then hello
    • control-a x (to exit)

Optionally, perform serial test between two Raspberry Pi's using three jump wires

  • Connect TX of a Raspberry Pi to RX of the other
  • Connect GND of both Raspberry Pi's

3

4 of 217

Lab 2B — SPI

Connect the SPI MOSI and MISO pins (the 10th and 11th pins from the left of the bottom row) using one jump wire, and copy and paste the following three commands from Lesson 2 README.md on an SSH Terminal:

wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documentation/spi/spidev_test.c

gcc -o spidev_test spidev_test.c

./spidev_test -D /dev/spidev0.0

4

5 of 217

Lab 2C — Breadboard

  • Shorter lead (−) of the LED to a 330-Ω resistor then to Ground, the 3rd pin from the left of the top row
  • Longer lead (+) of the LED to GPIO 18, the 6th pin from the left of the top row

5

6 of 217

Lab 2D — LED

  • Connect an LED on a breadboard to the Raspberry Pi GPIO using two jump wires as shown in Lab C
  • On a Terminal, enter the following commands to switch an LED on/off

pi@raspberypi:~ $ sudo su

root@raspberypi:/home/pi# echo 18 > /sys/class/gpio/export

root@raspberypi:/home/pi# cd /sys/class/gpio/gpio18

root@raspberypi:/sys/class/gpio/gpio18# echo out > direction

root@raspberypi:/sys/class/gpio/gpio18# echo 1 > value

root@raspberypi:/sys/class/gpio/gpio18# echo 0 > value

root@raspberypi:/sys/class/gpio/gpio18# cd /home/pi

root@raspberypi:/home/pi# echo 18 > /sys/class/gpio/unexport

root@raspberypi:/home/pi# exit

exit

pi@raspberypi:~ $

6

7 of 217

Lab 2E — I2C

Connect I2C devices (ADXL345 and BMP180) to 3V3, GND, SDA, and SCL of a Raspberry Pi, install i2c-tools, and test I2C addresses (53 and 77) in use on an SSH Terminal:

sudo apt install i2c-tools python-smbus

sudo i2cdetect -y 1

7

8 of 217

Lab 2F — 1-Wire

Connect DS18B20 to Raspberry Pi as follows:

(1) GND to GND, (2) VDD to 3.3V or 5V, and (3) DQ to GPIO 4 (the 4th pin from the left of the bottom row) and through a 4.7kΩ resistor to VDD

pi@raspberrypi:~ $ sudo modprobe w1-gpio

pi@raspberrypi:~ $ sudo modprobe w1-therm

pi@raspberrypi:~ $ cd /sys/bus/w1/devices

pi@raspberrypi:/sys/bus/w1/devices $ ls

28-031868b2fbff w1_bus_master1

pi@raspberrypi:/sys/bus/w1/devices $ cd 28*

pi@raspberrypi:/sys/bus/w1/devices/28-031868b2fbff $ cat w1_slave

af 01 4b 46 7f ff 0c 10 35 : crc=35 YES

af 01 4b 46 7f ff 0c 10 35 t=26937

pi@raspberrypi:/sys/bus/w1/devices/28-031868b2fbff $ cd

pi@raspberrypi:~ $

8

9 of 217

Lab 2G — USB Webcam

  • Connect a USB webcam, install fswebcam, and save images:

sudo apt update

sudo apt install fswebcam

fswebcam image.jpg

fswebcam -r 1280x720 image2.jpg

fswebcam -r 1280x720 --no-banner image3.jpg

9

10 of 217

Raspberry Pi Foundation

10

11 of 217

Raspberry Pi

First released on February 29, 2012 by Raspberry Pi Foundation

  • Raspberry \ˈraz-ˌbə-rē\, a nostalgia for naming computers after fruit
    • Eponym: one for whom or which something is named
    • Namesake: someone or something that has the same name as another person or thing
  • Kids like blowing a raspberry
  • Let users see the guts of devices that they usually don’t see
  • "Pi is short for Python," said Eben Upton, co-founder

Feature Broadcom system on chip (SOC)

  • BCM2835 (2012-02) ARMv6Z (32-bit) 700-MHz Single-Core
  • BCM2836 (2015-02) ARMv7-A (32-bit) 900-MHz Quad-Core
  • BCM2837 (2016-02) ARMv8-A (64/32-bit) 1.2-GHz Quad-Core
  • BCM2837B0 (2018-03) ARMv8-A (64/32-bit) 1.4-GHz Quad-Core
  • BCM2711 (2019-06) ARMv8-A (64/32-bit) 1.5-GHz Quad-Core

Technical specifications for all models including Compute Modules

  • BCM2835, BCM2836, and BCM2837 are specific packages of BCM2708, BCM2709, and BCM2710 chip families, respectively

11

12 of 217

Computing Mechanisms

  • The Antikythera mechanism is one of the oldest known computing mechanisms, perhaps the first analog computer in history
  • After decades of research, historians determined that the mechanism was meant to show the position of the Sun and Moon and the movement of the planets across the sky, and to predict solar and lunar eclipses and even key events on Earth, such as the ancient Olympic Games

12

13 of 217

Charles Babbage 1791—1871

  • Charles Babbage announced his difference engine on 1822-06-14 in a paper to the Royal Astronomical Society, entitled "Note on the application of machinery to the computation of astronomical and mathematical tables"
  • First described in 1837, the Analytical Engine designed by Charles Babbage as a mechanical general-purpose computer that incorporated an arithmetic logic unit, control flow in the form of conditional branching and loops, and integrated memory, making it the first design for a general-purpose computer that could be described in modern terms as Turing completeness

13

14 of 217

Alan Turing 1912—1954

  • Alan Turing proposed a "universal computing machine" in his seminal 1936 paper in the Proceedings of the London Mathematical Society, "On Computable Numbers, with an Application to the Entscheidungsproblem (decision problem in German)" [PDF]
  • The fundamental concept of Turing's design is the stored program, where all the instructions for computing are stored in memory
  • Turing machines are to this day a central object of study in theory of computation
  • Except for the limitations imposed by their finite memory stores, modern computers are said to be Turing-complete, i.e., they have algorithm execution capability equivalent to a universal Turing machine

14

15 of 217

John von Neumann 1903—1957

  • John von Neumann authored the "First Draft of a Report on the EDVAC" [PDF] dated 1945-06-30 describing a design architecture for an electronic digital computer with these components:
    • A processing unit that contains an arithmetic logic unit and processor registers
    • A control unit that contains an instruction register and program counter
    • Memory that stores data and instructions
    • External mass storage
    • Input and output mechanisms
  • The data and instructions share a common bus in the von Neumann architecture in contrast to the Harvard architecture or the modified Harvard architecture

15

16 of 217

Steve Jobs 1955—2011

  • Steve Jobs and Steve Wozniak co-founded Apple Inc. in 1976 to sell the Apple I personal computer, followed by the Apple II microcomputer in 1977
  • The mouse-driven Xerox Alto with a graphical user interface (GUI) in 1979 led to the development of the Apple Lisa in 1983, followed by the Macintosh in 1984
  • The Macintosh introduced the desktop publishing industry in 1985 with the addition of the Apple LaserWriter, the first to feature vector graphics
  • Forced out of Apple in 1985, Steve Jobs found NeXT to develop workstations and funded Pixar, the Lucasfilm spin-off in 1986, which produced the first 3D computer animated film Toy Story (1995)
  • Apple acquired NeXT in 1997, and Steve Jobs became CEO and worked closely with designer Jony Ive to develop the iMac, iTunes, iTunes Store, Apple Store, iPod, iPhone, App Store, and iPad
  • In 2001, the original Mac OS was replaced with a completely new Mac OS X, based on the NeXTSTEP platform, giving the OS a modern Unix-based foundation for the first time

16

17 of 217

ARMv8 CPU

ARM, originally Acorn RISC Machine, later Advanced RISC Machine, is a family of reduced instruction set computing (RISC) architectures for computer processors

17

18 of 217

BCM2711

  • Raspberry Pi 4 is built around the Broadcom BCM2711 chip with the ARM Cortex-A72 microarchitecture
  • BCM2711 is a complete re-implementation of BCM283X on 28 nm — no more 40 nm CPUs but not 7 nm yet
  • The International Roadmap for Devices and Systems (IRDS) is a set of predictions about likely developments in electronic devices and systems and is established in 2016 as the successor to the International Technology Roadmap for Semiconductors (ITRS)
  • Semiconductor device fabrication
  • Die shrink provides more chips onto each wafer, resulting in lowered manufacturing costs per chip
  • Half-node shrink (e.g., 40 nm and 28 nm) refers to a stopgap between two ITRS-defined lithographic nodes (i.e., 45 nm, 32 nm, and 22 nm)
  • Must read: Samuel K. Moore, "A Better Way to Measure Progress in Semiconductors," July 21, 2020

18

19 of 217

Raspberry Pi 1B (2012-02)

19

ACT: SD Card Access, PWR: Power

FDX: Full Duplex, LNK: Link, 100: Mbps

ARMv6Z (32-bit) BCM2835 700-MHz Single-Core ARM1176JZF-S

26-Pin GPIO Header

  • PWR LED remains on after shutdown

20 of 217

Raspberry Pi 1B+ V1.2 (2014-07)

20

ARMv6Z (32-bit) BCM2835 700-MHz Single-Core ARM1176JZF-S

40-Pin GPIO Header, 512MB SDRAM (synchronous dynamic random-access memory)

PWR

ACT

  • PWR LED remains on after shutdown

21 of 217

Raspberry Pi 2B (2015-02)

21

V1.1 (2015-02): ARMv7-A (32-bit) BCM2836 900-MHz 32-bit Quad-Core ARM Cortex-A7

V1.2 (2016-10): ARMv8-A (64/32-bit) BCM2837 900-MHz 64-bit Quad-Core ARM Cortex-A53

1GB SDRAM (synchronous dynamic random-access memory)

PWR

ACT

  • PWR LED remains on after shutdown

22 of 217

Raspberry Pi 3B (2016-02)

22

ACT

PWR

  • PWR LED remains on after shutdown

Antenna

V1.2 (2016-02): ARMv8-A (64/32-bit) BCM2837 1.2-GHz 64-bit Quad-Core ARM Cortex-A53

1GB SDRAM, Wi-Fi, Bluetooth

23 of 217

Raspberry Pi Zero W (2017-02-28)

23

ARMv6Z (32-bit) BCM2835 1-GHz Single-Core ARM1176JZF-S

V1.2 (2015-11) and V1.3 (2016-05) have no Wi-Fi and Bluetooth

V1.2 has no Camera Serial Interface (CSI)

Only Zero WH (2018-01-12) has pre-soldered 40-Pin GPIO header

512 MB SDRAM

Mini-HDMI, Antenna, Micro-USB, and Power

  • CSI

  • ACT LED turns off after shutdown

24 of 217

Raspberry Pi 3B+ (2018-03-14)

24

ACT

PWR

  • PWR LED remains on after shutdown

Antenna

ARMv8-A (64/32-bit) BCM2837B0 1.4-GHz 64-bit Quad-Core ARM Cortex-A53

1 GB SDRAM, Wi-Fi, Bluetooth

  • Gigabit Ethernet

25 of 217

Raspberry Pi 3A+ (2018-11-15)

25

ARMv8-A (64-bit) BCM2837B0 1.4-GHz 64-bit Quad-Core ARM Cortex-A53

512 MB SDRAM, Wi-Fi, Bluetooth

26 of 217

Raspberry Pi 4B (2019-06-24)

26

ARMv8-A (64-bit) BCM2711B0 1.5-GHz 64-bit Quad-Core ARM Cortex-A72

VideoCore VI GPU (500 MHz), 1GB/2GB/4GB/8GB LPDDR4 SDRAM, Wi-Fi, Bluetooth

  • 5V/3A USB-C power connector and dual micro-HDMI at resolutions up to 4K
  • 2 USB 3.0
  • 2 USB 2.0
  • Gigabit Ethernet

27 of 217

Raspberry Pi Zero 2 W (2021-10-28)

27

RP3A0 (64-bit) BCM2710A1 (BCM2837) 1-GHz Quad-Core ARM Cortex-A53

512 MB SDRAM

Mini-HDMI, Antenna, Micro-USB, and Power

28 of 217

Raspberry Pi Pico W (2022-06-30)

28

Pico (2021-01-21)

RP2040, Data Sheet, Getting Started With MicroPython [PDF] and C/C++ Examples

29 of 217

Raspberry Pi 5 (2023-09-28)

29

ARMv8-A (64-bit) BCM2712 2.4-GHz 64-bit Quad-Core ARM Cortex-A76

VideoCore VII GPU (800 MHz), 4GB/8GB LPDDR4X SDRAM, Wi-Fi, Bluetooth

RP1 I/O Controller via 4 PCIe Gen 2.0 Lanes

  • 5V/3A USB-C power connector and dual micro-HDMI at resolutions up to 4K
  • 2 USB 3.0
  • 2 USB 2.0
  • Gigabit Ethernet

30 of 217

Raspberry Pi Pico 2 (2024-08-08)

30

31 of 217

More Than 60 Million Sold

31

32 of 217

Raspberry Pi Benchmarks

Benchmarks and thermal tests

  • LINPACK CPU
  • Speedometer 2.0 browser speed test
  • OpenArena Time Demo (GPU speed test)
  • Memory bandwidth by RAMspeed/SMP (system memory performance) tool
  • Memory throughput by sysbench
  • Python GPIO Zero
  • File compression
  • GIMP image editing
  • USB storage throughput
  • Ethernet throughput
  • Wireless LAN throughput
  • Power draw
  • Thermal performance

32

33 of 217

Meltdown, Spectre, and BlueBorne

  • Meltdown and Spectre exploit critical vulnerabilities in performance features such as caching and speculative execution common to many modern processors to leak data via a so-called side-channel attack
  • The ARM1176, Cortex-A7, and Cortex-A53 cores used in Raspberry Pi lack speculative execution thereby not susceptible to these vulnerabilities exploited by Meltdown and Spectre
  • BlueBorne is an attack vector by which hackers can leverage Bluetooth connections to penetrate and take complete control over ordinary computers, mobile phones, and the expanding realm of IoT devices including Amazon Echo and Google Home

33

34 of 217

Moore's Law

  • Gordon Moore, co-founder and chairman emeritus of Intel Corporation
  • His 1965 paper (PDF) described a doubling every year in the number of components per integrated circuit, and projected this rate of growth would continue for at least another decade
  • His 1975 paper (PDF) revised the forecast to doubling every two years

34

35 of 217

MicroSDHC Memory Cards

35

Raspberry Pi supports Secure Digital (SD)

High Capacity (HC), not Extended Capacity (XC)

36 of 217

Raspberry Pi 3B+ Power Supply

36

  • 5V 2.5A or 5.25V 2.4A with Micro-USB connector

37 of 217

Raspberry Pi 4B Power Supply

Raspberry Pi USB-C power supply features:

  • AC 100-240V 50/60Hz input
  • Short circuit, overcurrent, and over temperature protection
  • DC 5.1V 3A output
  • 15.3W maximum output power
  • 1.5m 18 AWG captive cable
  • USB-C output connector

37

38 of 217

Ferrite Beads

  • A power cable may have a small cylinder called ferrite bead
  • Cables can act like unintentional antennas, broadcasting electrical interference or picking it up
  • Ferrite beads are used as a passive low-pass filter with an impedance for high-frequency signals, attenuating high-frequency electromagnetic interference (EMI)
  • Ferrite beads can reduce interference from a cable to comply with regulatory requirements that specify how much interference a device is permitted to emit
  • Ferrite beads can also reduce electrical interference to a data cable, thereby enhancing the quality of data stream

38

39 of 217

Unix, GNU, POSIX, Linux, and Git

  • GNU \gə-ˈnü\ is a recursive acronym for "GNU's Not Unix"
  • GNU is an operating system and an extensive collection of computer software started in January 1984 by Richard Stallman who also named the POSIX (Portable Operating System Interface) or IEEE 1003.1 standard in 1985
  • Linus Torvalds released the first Linux kernel (version 0.02) on October 5, 1991, and the Linux Foundation was founded in 2000
  • Tux the penguin is the brand character of the Linux kernel
  • A typical Linux or Linux distribution (often abbreviated as distro) comprises a Linux kernel, GNU tools and libraries, additional software, documentation, a window system (e.g., X Window System), a window manager, and a desktop environment
  • See GNU/Linux naming controversy
  • Linux distributions have taken a variety of forms as shown in timeline
  • Linus Torvalds created Git in April 2005 for development of the Linux kernel, and turned over maintenance to Junio Hamano in July 2005

39

40 of 217

Gnu

  • A gnu \ˈnü\ or wildebeest is either one of the two species in Africa—the blue wildebeest and the black wildebeest (a.k.a. white-tailed wildebeest)

40

41 of 217

Debian and Raspberry Pi OS

  • Peter MacDonald co-developed early features of the Linux kernel, and created Softlanding Linux System (SLS), the first comprehensive Linux distribution, for testing in August 1992 and for general release in October 1992
  • The perceived poor maintenance in SLS motivated Patrick Volkerding to create Slackware in 1993
  • Similarly, Ian Murdock 1973—2015 started the Debian Project in 1993
    • Debian is a portmanteau of the first names of his then-girlfriend (later ex-wife) Debra Lynn and his own
    • Debian systems use the Linux kernel, the FreeBSD kernel, etc.
    • Debian 0.01 was released on September 15, 1993
    • The first stable release in 1996
  • Raspberry Pi OS (as of 2020-05-27, previously called Raspbian) is a Debian-based computer operating system for Raspberry Pi
    • Maintained by Mike Thompson, Peter Green, et al.
    • The initial build was completed in June 2012
    • Not affiliated with but officially supported by the Raspberry Pi Foundation

41

42 of 217

Debian Swirl

42

43 of 217

Coriolis Force

  • The mathematical expression for the Coriolis force appeared in an 1835 paper by Gaspard-Gustave de Coriolis 1792—1843
  • Because Earth rotates faster near the equator than near the poles (indicated by the varying lengths of the yellow arrows), moving air drawn to low-pressure areas at midlatitudes travels east either faster or slower than the low itself
  • As the low draws air in (white arrows), the difference in speeds causes the air to curve: counterclockwise in the Northern Hemisphere and clockwise in the Southern Hemisphere (purple arrows)

43

44 of 217

Debian Releases

Debian releases have been named after Toy Story characters because Bruce Perens was involved in the early development of Debian while working at Pixar

Stable, Oldstable, Oldoldstable, and Obsolete distributions are production releases

  • Debian 11 (2021-08-14) after Bullseye, the toy horse
  • Debian 10 (2019-07-06) after Buster, Andy's pet dachshund
  • Debian 9 (2017-06-17) after Stretch, the toy rubber octopus
  • Debian 8 (2015-04-26) after Jessie the Yodeling Cowgirl Jesse is the male variant of the name, e.g., Jesse James

Testing distribution contains packages that haven't been accepted into a stable release yet, but they are in the queue for the next major release

Unstable distribution is where active development occurs

  • Permanently named after Sid, the emotionally unstable boy next door who regularly destroyed toys

44

45 of 217

Install Raspberry Pi OS

  • Models 1B+, 2B, Zero, Zero W, 3B, 3B+, and 4B use micro Secure Digital (SD) cards
  • Raspberry Pi only supports SDHC (High Capacity up to 32GB) cards with the FAT (File Allocation Table) file system
    • Raspberry Pi won't boot from SDXC (eXtended Capacity 32GB or larger) cards with the Extended FAT (exFAT) file system
  • On a laptop, download and open Raspberry Pi Imager
    • Insert a new or reformatted SD card, choose Raspberry Pi OS (32-bit) and the SD card, click WRITE, eject it properly, and insert it to the Pi SD card slot
  • Connect Raspberry Pi first to a monitor, keyboard, and mouse; then to power
    • Set country, language, and timezone
    • Select "Use English Language" and "Use US Keyboard" if applicable
    • Change password (default: raspberry)
    • Select if "this screen shows a black border around the desktop"
    • Select wireless network and enter wireless network password
    • Check and update software if necessary (this may involve a large download)
    • Click "Restart" to reboot

45

46 of 217

Raspberry Pi Imager

46

47 of 217

Raspberry Pi OS Release Notes

The Raspberry Pi OS release notes provide updated information including

  • Release date
  • Additions
  • Improvements
  • Replacements
  • Deletions
  • Software version numbers
  • Bug fixes
  • User interface (UI) tweaks
  • Raspberry Pi firmware version number
  • Linux kernel version number

47

48 of 217

Raspberry Pi Boot Modes

  • The Raspberry Pi has a number of boot modes
  • The Raspberry Pi GitHub documentation explains how the boot modes work
    • Bootflow describes the boot sequence
    • SD card boot as the default boot mode
    • USB boot
      • Device boot: Booting as a mass storage device
      • Host boot: Booting as a USB host
      • Mass storage boot: Boot from MSD, i.e., Mass Storage Device (tutorial)
    • Network boot: Boot from Ethernet (tutorial)

48

49 of 217

First Boot Configuration Wizard

49

50 of 217

Set Country

50

51 of 217

Change Password

51

52 of 217

Skip (or Set) Wi-Fi Network

52

53 of 217

Skip (or Check for) Updates

53

54 of 217

Update Complete

54

55 of 217

Reboot Again

55

56 of 217

Raspberry Pi Configuration

56

Open Applications Menu > Preferences > Raspberry Pi Configuration

Alternatively, click the rc_gui.desktop shortcut

57 of 217

Change System Configuration

57

Required changes in red

  • Default password was changed at first boot
  • Change hostname
  • Default OK
  • Uncheck auto login
  • ✓ to email IP at boot
  • Default OK

58 of 217

Change Display Configuration

58

  • Disable overscan or underscan to hide black outline on screen
  • Fine-tune other default settings

59 of 217

Hostnames

59

60 of 217

Change Default Credentials

  • Default credentials enabled the Mirai botnet behind distributed denial-of-service attacks (DDoS attacks) in 2016
  • Default usernames

666666, 888888, admin, admin1, administrator, guest, root, service, supervisor, support, tech, user

  • Default passwords

(none), 00000000, 1111, 1111111, 1234, 12345, 123456, 54321, 888888, admin, admin1234, default, guest, pass, password, root, service, supervisor, system, tech, user

  • The new Satori (or Mirai Okiru) infects SoC devices based on Argonaut RISC Core (ARC) for storage, home, mobile, automotive, and IoT applications in 2017
  • The Mirai attacks were a wake-up call for the security industry and a rallying call for more collaboration, e.g., Akamai, Cloudflare, Flashpoint, Google, RiskIQ, etc. teamed up to take down WireX Android DDoS botnet in August 2017

60

61 of 217

Protect Passwords

  • The strength of a password is more important than how often to change it
  • Never repeat the same password across different sites and services
  • Never share a password — be the only one who knows it
  • A password shall be difficult to guess
    • Has 12 characters or more
    • Includes numbers, symbols, capital letters, lower-case letters, and space
    • Avoid including name or common words — isn’t a dictionary word or combination of dictionary words
    • Doesn’t rely on obvious substitutions
  • Password managers save and generate secure passwords — only have to remember one password that opens the vault

61

62 of 217

Shell and Terminal

  • In computing, a shell is a user interface for access to services of an operating system
  • In general, operating system shells use either a command-line interface (CLI) or graphical user interface (GUI), depending on a computer's role and particular operation
  • It is named a shell because it is the outermost layer around the operating system kernel
  • On the Raspberry Pi (running Raspberry Pi OS), the default CLI terminal application is LXTerminal, the standard terminal emulator of LXDE (Lightweight X11 Desktop Environment)

62

63 of 217

Bourne Shell, Bash, and Zsh

  • The Thompson shell written by Ken Thompson at Bell Labs was the first Unix shell introduced in the first version of Unix in 1971
  • The Bourne shell developed by Stephen Bourne at Bell Labs was a replacement for the Thompson shell as the default shell for Version 7 Unix in 1979
  • The C shell (csh or the improved TENEX version, tcsh) was created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s, and has been widely distributed, beginning with the 1979 2BSD release of the Berkeley Software Distribution (BSD)
  • KornShell (ksh) is a Unix shell developed by David Korn at Bell Labs in the early 1980s and announced at the USENIX technical conference on July 14, 1983
  • The Bourne-again shell (the acronym Bash is also a noun and verb) first released in 1989 is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell
  • The Z shell (Zsh) was written by Paul Falstad in 1990 while a student at Princeton University — the default shell of macOS Catalina (10.15) is Zsh, replacing Bash with chsh -s /bin/zsh

63

64 of 217

History and Wildcard Characters

  • History allows users to recall previous commands and rerun them by typing only a few quick keystrokes, e.g.,
    • ↑ upwards (and downwards) arrows to recall previous commands
    • !! typed as a command and referred to as "bang, bang," causes the immediately preceding command to run
    • !$ means just the last argument of the previous command, allow bits and pieces of previous commands to be pasted together and edited to form a new command
  • Name globbing or wildcard matching
    • Tab key after the first part of a unique name to autocomplete
    • * matches any number of characters
    • ? matches any single character
    • [...] matches any of the characters inside the square brackets — ranges are allowed, using the hyphen
    • [^...] matches any character not in the set

64

65 of 217

Pipeline

  • The pipeline concept was championed by Douglas McIlroy at Bell Labs during the development of Unix
  • A pipeline is a set of processes chained together by their standard streams so that the output text of each process is passed directly as input to the next one, e.g.,

ls -l | grep key | less

A; B # Run A and then B, no matter A succeeded or failed

A && B # Run B if and only if A succeeded

A || B # Run B if and only if A failed

A & # Run A in background

65

66 of 217

List of Commands 0/1

$ cd # Change directory to /home/pi

$ cd dirname # Change directory to dirname

$ cd .. # Move up to parent directory

$ cp file1 file2 # Copy file1 and call it file2

$ history # Print the history list

$ history -c # Clear the history list

$ ls # List files and folders

$ mkdir dirname # Make directory dirname

$ mv filename new_filename # Rename file

$ nano filename # Edit file

$ rm filename # Remove file

$ rm -rf dirname # Remove directory and its contents

$ rmdir dirname # Remove empty directory

$ scrot # Take a screenshot

$ sudo apt install _ # Install software _

$ sudo apt update # Update package list index

$ sudo apt full-upgrade # Upgrade software packages

$ sudo apt autoremove # Remove software packages

$ sudo nano filename # Edit a file in root directory

$ sudo pip install _ # Install Python package _

$ sudo reboot # Reboot Raspberry Pi

$ sudo shutdown -h now # Shutdown Raspberry Pi

66

67 of 217

List of Commands 1/1

$ arp -a # Show IP addresses of devices

$ cat filename # Show file contents

$ df -Th # Show disk space usage

$ sudo dmesg # Display kernel ring buffer messages

$ env # List environment variables (PATH)

$ find filename # Find file in current directory

$ hostname -I # Show IP address of Raspberry Pi

$ ifconfig # Show interface configuration

$ ip addr show wlan0 # Show IP address on Wi-Fi

$ iwconfig # Show wireless configuration

$ lsusb # List USB devices

$ man program_name # Show program’s manual pages

$ more filename # Show file one page at a time

$ netstat -lntp # Show network statistics

$ ps # Show running processes

$ pwd # Print working directory

$ sudo raspi-config # Configure Raspberry Pi

$ tar -zxvf file.tar.gz # Extract files

$ uname -a # Information about current kernel

$ vncpasswd # Change VNC server password

$ vncserver :1 # Run VNC server on display 1

$ wget http://example.com/file.tar.gz

67

68 of 217

Disk Space Usage

pi@4B2G:~ $ df -Th

Filesystem Type Size Used Avail Use% Mounted on

/dev/root ext4 27G 14G 12G 53% /

devtmpfs devtmpfs 779M 0 779M 0% /dev

tmpfs tmpfs 908M 0 908M 0% /dev/shm

tmpfs tmpfs 908M 8.5M 900M 1% /run

tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock

tmpfs tmpfs 908M 0 908M 0% /sys/fs/cgroup

/dev/mmcblk0p6 vfat 253M 54M 199M 22% /boot

tmpfs tmpfs 182M 0 182M 0% /run/user/1000

pi@4B2G:~ $ df -Bm

Filesystem 1M-blocks Used Available Use% Mounted on

/dev/root 27138M 13537M 12200M 53% /

devtmpfs 779M 0M 779M 0% /dev

tmpfs 908M 0M 908M 0% /dev/shm

tmpfs 908M 9M 900M 1% /run

tmpfs 5M 1M 5M 1% /run/lock

tmpfs 908M 0M 908M 0% /sys/fs/cgroup

/dev/mmcblk0p6 253M 54M 199M 22% /boot

tmpfs 182M 0M 182M 0% /run/user/1000

pi@4B2G:~ $

68

69 of 217

Change Hostname or Password

  • Change hostname in two files

pi@raspberrypi ~ $ sudo nano /etc/hostname

pi@raspberrypi ~ $ sudo nano /etc/hosts

pi@raspberrypi ~ $ sudo reboot

  • Change password

pi@raspberrypi ~ $ passwd

Changing password for pi.

(current) UNIX password:

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

pi@raspberrypi:~ $

69

70 of 217

Change Interfaces Configuration

70

Required changes in red

  • Enable to use CSI
  • Enable SSH required
  • Enable to use VNC
  • Enable to use SPI
  • Enable to use I2C
  • Enable to use Serial Port
  • Disable Serial Console
  • Enable to use 1-Wire
  • Enable to remotely access the pigpio daemon

71 of 217

Default Performance Configuration

71

  • Default value in MB

72 of 217

Localization

72

  • en_US.UTF-8
  • America/New_York
  • United States > English (US)
  • US (United States)

73 of 217

Advanced Options by Raspi-Config

pi@raspberrypi:~ $ sudo raspi-config

73

74 of 217

Graphics Library (GL) Driver

Experimental OpenGL Driver for hardware acceleration is not for Pi 1 and Pi Zero

74

75 of 217

Graphics Library (GL) Driver

Select fake kernel mode setting (KMS) to enable GL and play Neverball game

Select legacy to disable GL after game so that Pi can have proper, complete shutdown

75

76 of 217

Point Wi-Fi Icon for IP Address

76

77 of 217

Classless Inter-Domain Routing

  • The Internet Engineering Task Force introduced Classless Inter-Domain Routing (CIDR) for allocating IP addresses and for IP routing in 1993 to replace the previous classful network addressing architecture on the Internet
  • Its goal was to slow the growth of routing tables on routers across the Internet, and to help slow the rapid exhaustion of IPv4 addresses
  • IPv4 CIDR blocks are identified using a syntax similar to that of IPv4 addresses: a dotted-decimal address, followed by a slash, then a number from 0 to 32, i.e., a.b.c.d/n
    • The dotted decimal portion is the IPv4 address
    • The number following the slash is the prefix length, the number of shared initial bits, counting from the most-significant bit of the address
  • When emphasizing only the size of a network, the address portion of the notation is usually omitted
  • Thus, a /24 block is a CIDR block with an unspecified 24-bit prefix

77

78 of 217

Click Wi-Fi Icon for Networks

78

79 of 217

Default Network Interfaces

pi@raspberrypi:~ $ cat /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd

# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:

source-directory /etc/network/interfaces.d

79

  • Dynamic Host Configuration Protocol (DHCP) Client Daemon (dhcpcd) Network Configurator

80 of 217

WPA Supplicant

Stevens login or password stored in /etc/wpa_supplicant/wpa_supplicant.conf can be updated by sudo nano:

pi@raspberrypi:~ $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

country=US

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

network={

ssid="Stevens"

key_mgmt=WPA-EAP

identity="STEVENS_LOGIN"

password="PASSWORD"

}

A Supplicant, one who supplicates, is a term applied to humble petitioners, and in particular to University of Oxford students who have qualified but not yet been admitted into their degree

80

  • WPA: Wi-Fi Protected Access
  • EAP: Extensible Authentication Protocol
  • Update login or password
  • Save file with control-x y enter

81 of 217

Hash for Password

The hash for the password can be generated as follows:

pi@raspberrypi:~ $ echo -n 'PASSWORD' | iconv -t utf16le | openssl md4

(stdin)= xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Edit /etc/wpa_supplicant/wpa_supplicant.conf to replace password='PASSWORD' with

password=hash:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

81

Contribution by Connor DePalma, 2019 Spring

82 of 217

Raspberry Pi MAC Address

Raspberry Pi Wi-Fi uses a 48-bit Extended Unique Identifier (EUI-48) for its media access control (MAC) address that includes the 3-octet organizationally unique identifier (OUI) — b8:27:eb or dc:a6:32 purchased from the IEEE Registration Authority, and another specific to the network interface controller (NIC)

82

83 of 217

Stevens-Media

If not getting access to the internet with the Stevens Wi-Fi IP address showing 169.254.9.183/16 or similar, run ifconfig to find the Raspberry Pi MAC address for wlan0, register it at MACTrac Devices for 150 days, click the network icon at the right of the menu bar to select Stevens-Media, enter the PSK password provided by the registration, and they will be automatically appended to /etc/wpa_supplicant/wpa_supplicant.conf :

pi@raspberrypi:~ $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

country=US

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

...

network={

ssid="Stevens-Media"

psk="PASSWORD"

key_mgmt=WPA-PSK

}

83

84 of 217

WPA GUI Graphical User Interface

Alternatively, install and run WPA GUI to manage Stevens Wi-Fi network

pi@raspberrypi:~ $ sudo apt install wpagui

pi@raspberrypi:~ $ wpa_gui

84

Stevens Username

Stevens Password

Contribution by Xiaolong Wang, 2015 Spring

  • No underline here
  • Only add a network once

85 of 217

Network Not Connected

85

86 of 217

Home Wi-Fi or Hotspot

  • To connect Raspberry Pi to Wi-Fi at home, click the network icon || at the right of the menu bar to run dhcpcd (Dynamic Host Configuration Protocol Client Daemon) Network Configurator, select home Wi-Fi or personal/portable Wi-Fi hotspot SSID (rename it without an apostrophe if necessary*), and click OK after entering Wi-Fi password to "Pre Shared Key"
  • SSID and password are stored in /etc/wpa_supplicant/wpa_supplicant.conf
  • If SSID or password is changed, sudo nano wpa_supplicant.conf

pi@raspberrypi:~ $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

network={

ssid="SSID"

psk="PRE_SHARED_KEY"

key_mgmt=WPA-PSK

}

  • Save file with control-x y enter

86

WPA: Wi-Fi Protected Access

PSK: Pre-Shared Key

x

x

* Contribution by Julie McEldoon, 2019 Fall

87 of 217

WPA_Passphrase Utility

For home Wi-Fi or hotspot, the wpa_passphrase utility uses the SSID and the password to generate the encrypted PSK

pi@raspberrypi:~ $ wpa_passphrase testing testingPassword

network={

ssid="testing"

#psk="testingPassword"

psk=131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531

}

pi@raspberrypi:~ $

Copy and paste the encrypted PSK in the wpa_supplicant.conf

87

88 of 217

Connected to Home Wi-Fi or Personal/Portable Wi-Fi Hotspot

88

89 of 217

Fing — Network Scanner

89

Contribution by Joseph Testa, 2016 Spring

Media Access Control (MAC) Address

90 of 217

Unsecured Network

If the network does not use a password, include key_mgmt=NONE in /etc/wpa_supplicant/wpa_supplicant.conf

network={

ssid="Stevens-Guest"

key_mgmt=NONE

}

90

91 of 217

Wi-Fi Access Point and Wi-Fi Direct

91

92 of 217

Add Bluetooth Device

92

93 of 217

Select Bluetooth Device

93

94 of 217

Pair Bluetooth Device

94

95 of 217

Bluetooth Device Connected

95

96 of 217

Advanced Package Tool (APT)

  • Advanced Package Tool (APT) is a set of tools for managing Debian packages
  • Update is always required before installing packages

pi@raspberrypi:~ $ sudo apt update

pi@raspberrypi:~ $ sudo apt install PACKAGE

pi@raspberrypi:~ $ sudo apt install PACKAGE_0 PACKAGE_1 PACKAGE_2

  • Upgrade may cause disruptions that require searching for similar error messages in Raspberry Pi Blog, Forums, or Help Guides and Resources to troubleshoot the problem

pi@raspberrypi:~ $ sudo apt update

pi@raspberrypi:~ $ sudo apt full-upgrade

pi@raspberrypi:~ $ sudo apt autoremove

96

97 of 217

Using apt Instead of apt-get

97

apt command

The command it replaces

Function of command

apt install

apt-get install

Installs a package

apt remove

apt-get remove

Remove a package

apt purge

apt-get purge

Removes package with configuration

apt update

apt-get update

Refreshes repository index

apt upgrade

apt-get upgrade

Upgrade all upgradable packages

apt autoremove

apt-get autoremove

Removes unwanted packages

apt full-upgrade

apt-get dist-upgrade

Upgrades packages with auto-handling of dependencies

apt search

apt-cache search

Searches for the program

apt show

apt-cache show

Shows package details

98 of 217

New apt Commands

98

New apt command

Function of the command

apt list

Lists of packages with criteria (installed, upgradeable, etc.)

apt edit-sources

Edits sources list

99 of 217

Shutdown or Reboot

  • Unplug the power without proper, complete shutdown can corrupt the file system on the SD card
  • Always go to Desktop Menu > Shutdown > Shutdown Options or use the following commands on a Terminal
  • Recommended shutdown command

pi@raspberrypi ~ $ sudo shutdown -h now

  • Although the halt command works on Raspberry Pi OS, it may not work the same way on other Linux distributions

pi@raspberrypi ~ $ sudo halt

  • Recommended reboot command

pi@raspberrypi ~ $ sudo reboot

  • Alternative reboot command with more typing

pi@raspberrypi ~ $ sudo shutdown -r now

  • Unplug the power after the Raspberry Pi green LED blinks ten times

99

100 of 217

Email IP Address at Boot

Raspberry Pi Configuration > System > Network at Boot > ✓ Wait for network

Clone the IoT repository, copy a file to /home/pi, and edit the credentials in bold

pi@raspberrypi:~ $ git clone https://github.com/kevinwlu/iot.git

pi@raspberrypi:~ $ cp ~/iot/lesson1/startup_mailer.py .

pi@raspberrypi:~ $ nano startup_mailer.py

to = 'RECIPIENT_EMAIL' # Email to send to

gmail_user = 'GMAIL USERNAME' # Email to send from (MUST BE GMAIL)

gmail_password = 'GOOGLE_APP_PASSWORD' # ... 16-letter App Password

...

my_ip_a = 'HOSTNAME %s IP address is %s' % (ip_type_a, ipaddr_a)

...

msg['Subject'] = 'IP address for HOSTNAME'

Save file with control-x y enter, then sudo nano /etc/rc.local by adding the line in bold

pi@raspberrypi:~ $ sudo nano /etc/rc.local

if [ "$_IP" ]; then

printf "My IP address is %s\n" "$_IP"

python3 /home/pi/startup_mailer.py

fi

Make /lib/systemd/system/rc-local.service executable

pi@raspberrypi:~ $ ls -l /lib/systemd/system/rc-local.service

pi@raspberrypi:~ $ sudo chmod +x /lib/systemd/system/rc-local.service

100

Contribution by Aldin Llolla, 2019 Fall

101 of 217

Google App Password

  • startup_mailer.py requires a 16-digit "App Password," an application- specific password for less secure apps access
  • My Account > Sign-in & security > Signing in to Google >
    • 2-Step Verification > TURN ON > Select a second verification step > Authenticator app (Default)
    • App passwords > Select the app (Mail) and device (Raspberry Pi) > GENERATE
  • Enter the 16-digit "App Password" in startup_mailer.py

101

102 of 217

Secure Shell (SSH) from Laptop

Run SSH from a Terminal

$ ssh pi@192.168.1.209

The authenticity of host '192.168.1.209 (192.168.1.209)' can't be established.

ECDSA key fingerprint is SHA256:...

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.1.209' (ECDSA) to the list of known hosts.

pi@192.168.1.209's password:

Linux raspberrypi 5.10.11-v7l+ #1399 SMP Thu Jan 28 12:09:48 GMT 2021 armv7l

The programs included with the Debian GNU/Linux system are free software;

the exact distribution terms for each program are described in the

individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent

permitted by applicable law.

Last login: Wed Aug 26 12:17:34 2020 from 192.168.1.209

pi@raspberrypi:~ $

102

  • * (asterisk) is a wildcard character

103 of 217

SSH Client on Windows

  • Windows laptops require a terminal emulator such as PuTTY as an SSH client
  • Download, install, and run PuTTY
  • Right click the PuTTY icon and select "Pin to taskbar"

103

104 of 217

Catch-22

  • Catch-22 is a satirical war novel by American author Joseph Heller 1923—1999
  • He began writing it in 1953; the novel was first published in 1961
  • The novel is set during World War II, from 1942 to 1944
  • It mainly follows the life of antihero Captain John Yossarian, a U.S. Army Air Forces B-25 bombardier
  • A "Catch-22" is "a problematic situation for which the only solution is denied by a circumstance inherent in the problem or by a rule"
  • In the book, Catch-22 is a military rule typifying bureaucratic operation and reasoning, e.g., if one is crazy, one does not have to fly missions; and one must be crazy to fly; but one has to apply to be excused, and applying demonstrates that one is not crazy; as a result, one must continue flying, either not applying to be excused, or applying and being refused
  • The term "Catch-22" is also used more broadly to mean a tricky problem or a no-win or absurd situation

104

105 of 217

Git for Windows

  • Git for Windows provides software configuration management (SCM) via a BASH emulation used to run Git from the command line

105

106 of 217

Windows Subsystem for Linux

  • Installation Instructions for Windows Subsystem for Linux (WSL)
  • On Windows 10, open PowerShell as Administrator and run

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

  • Restart the computer
  • Open the Microsoft Store, choose Debian GNU/Linux or Ubuntu, and click "Get"
    • Once the download has completed, select "Launch"
    • Pin to taskbar
  • Create UNIX username and password
    • This user account can be different from, and has no relationship to, Windows username and password
  • Run SSH

106

Contribution by Touqeer Ahmad, 2016 Fall

107 of 217

Ubuntu

  • Ubuntu is one of the distribution systems of Linux built on the Debian architecture and infrastructure
  • The first release was Ubuntu 4.10 on October 20, 2004
  • Except the first two releases, alliterative code names are in alphabetical order using an adjective and an animal, e.g., "16.04 LTS Xenial Xerus," "18.04 LTS Bionic Beaver"
  • Development of Ubuntu is led by UK-based Canonical Ltd., a company founded by South African entrepreneur Mark Shuttleworth
  • Ubuntu means humanity in the Nguni languages of South Africa
  • In its "Circle of Friends" logo, Ubuntu affirms an ethic or humanist philosophy focusing on people's allegiances and relations with each other, similar to the Confucian concept of ren

107

108 of 217

Enable SSH on Ubuntu

~$ uname -a

Linux klu-Inspiron-5577 5.3.0-62-generic #56~18.04.1-Ubuntu SMP Wed Jun 24 16:17:03 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

~$ sudo apt update

...

~$ sudo apt install lsb-core

~$ lsb_release -a

LSB Version: core-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch

Distributor ID: Ubuntu

Description: Ubuntu 18.04.5 LTS

Release: 18.04

Codename: bionic

~$ sudo do-release-upgrade

Checking for a new Ubuntu release

There is no development version of an LTS available.

To upgrade to the latest non-LTS development release

set Prompt=normal in /etc/update-manager/release-upgrades.

~$ sudo apt install openssh-server

~$ sudo ufw allow ssh

~$ sudo systemctl status ssh

108

  • LSB: Linux Standard Base

109 of 217

Dual Boot Ubuntu with Windows

Steps to dual boot Ubuntu with Windows 10

  1. Make a backup (optional)
  2. Create a live USB of Ubuntu
  3. Make a partition where Ubuntu will be installed
  4. Disable fast startup in Windows 10
  5. Disable secureboot in Windows 10
  6. Installing Ubuntu along with Windows 10
  7. Restart the laptop and hold F12 for Boot Options
  8. Legacy options > Hard Drive

109

110 of 217

WSL 2 PowerShell

110

111 of 217

Chrome

Press Ctrl+Alt+T anywhere in Chrome OS to open crosh (Chrome Shell) and enter ssh

111

Contribution by Alhussain Almarhabi, 2017 Fall

112 of 217

Delete Old Keys in Known_Hosts

To use a different SD card or Wi-Fi dongle on Raspberry Pi at home, delete the previous ECDSA (or RSA) key in ~/.ssh/known_hosts on a laptop

$ ssh pi@192.168.1.x

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!

Someone could be eavesdropping on you right now (man-in-the-middle attack)!

It is also possible that a host key has just been changed.

The fingerprint for the ECDSA key sent by the remote host is

SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.

Please contact your system administrator.

Add correct host key in /Users/xxx/.ssh/known_hosts to get rid of this message.

Offending ECDSA key in /Users/xxx/.ssh/known_hosts:1

ECDSA host key for 192.168.1.x has changed and you have requested strict checking.

Host key verification failed.

$ sed -i '' '1d' ~/.ssh/known_hosts

$

112

  • Row number
  • Delete row or nano ~/.ssh/known_hosts and control-k at the end of the row

113 of 217

Elliptic-Curve Cryptography

  • The US National Security Agency (NSA) has categorized NSA cryptography items into four product types, and algorithms into two suites: Suite A and Suite B
  • Elliptic-curve cryptography (ECC), e.g., Elliptic Curve Digital Signature Algorithm (ECDSA) in Suite B, is an approach to public-key cryptography based on the algebraic structure of elliptic curves over finite fields
  • The primary benefit promised by elliptic curve cryptography is a smaller key size, reducing storage and transmission requirements
  • Post-quantum cryptography refers to new cryptographic algorithms being prepared for a time when quantum computing becomes a threat
    • Lattice-based cryptography
    • Multivariate cryptography
    • Hash-based cryptography
    • Code-based cryptography
    • Supersingular elliptic curve isogeny cryptography
    • Symmetric key quantum resistance

113

114 of 217

Serveo Port Forwarder

On a Raspberry Pi, copy two files and edit sshscript.sh and /etc/rc.local

pi@UNIQUE_NAME:~ $ cp ~/iot/lesson1/startup.cnf .

pi@UNIQUE_NAME:~ $ cp ~/iot/lesson1/sshscript.sh .

pi@UNIQUE_NAME:~ $ sudo nano sshscript.sh

#!/bin/bash

while :

do

ssh -R UNIQUE_NAME:22:localhost:22 serveo.net

sleep 10

done

pi@UNIQUE_NAME:~ $ chmod +x sshscript.sh && sshscript.sh

pi@UNIQUE_NAME:~ $ sudo nano /etc/rc.local

...

if grep -q "RunServeoSSHOnStartup=1" /home/pi/startup.cnf; then

sudo /home/pi/sshscript.sh &

fi

exit 0

On a laptop, run the following command

$ ssh -J serveo.net pi@UNIQUE_NAME

114

Contribution by Pridhvi Myneni, 2019 Fall

115 of 217

Run VNC Server on Raspberry Pi

pi@raspberrypi:~ $ vncserver

VNC(R) Server 6.4.1 (r40826) ARMv6 (Mar 13 2019 16:35:06)

Copyright (C) 2002-2019 RealVNC Ltd.

RealVNC and VNC are trademarks of RealVNC Ltd and are protected by trademark

registrations and/or pending trademark applications in the European Union,

United States of America and other jurisdictions.

Protected by UK patent 2481870; US patent 8760366; EU patent 2652951.

See https://www.realvnc.com for information on VNC.

For third party acknowledgements see:

https://www.realvnc.com/docs/6/foss.html

OS: Raspbian GNU/Linux 10, Linux 4.19.118, armv7l

On some distributions (in particular Red Hat), you may get a better experience

by running vncserver-virtual in conjunction with the system Xorg server, rather

than the old version built-in to Xvnc. More desktop environments and

applications will likely be compatible. For more information on this alternative

implementation, please see: https://www.realvnc.com/doclink/kb-546

Running applications in /etc/vnc/xstartup

VNC Server catchphrase: "xxxxxx xxxxxx xxxxx. xxxxx xxxxxx xxxxxx."

signature: xx-xx-xx-xx-xx-xx-xx-xx

Log file is /home/pi/.vnc/raspberrypi:1.log

New desktop is raspberrypi:1 (155.246.x.x:1)

115

116 of 217

Run VNC Viewer on Laptop

  • Install and run VNC Viewer on laptop https://www.realvnc.com/download/viewer
  • Enter the IP address of Raspberry Pi and VNC server display number (:1)

such as 155.246.x.x:1, and click "OK"

  • Enter Raspberry Pi username pi, then password, and click "OK"

116

117 of 217

VNC Viewer

117

118 of 217

VNC Cloud Connectivity

  • VNC Connect is included with the latest Raspberry Pi OS for non-commercial use
  • Sign up for a free RealVNC account (need to be over 16) by an email address
  • On the Raspberry Pi desktop, click the VNC Server icon at the right of the menu bar and sign in to enable cloud connectivity
  • On a laptop, sign in to VNC Viewer

118

Contribution by Xingyuan Guo, 2018 Fall

119 of 217

Warning about Default Password

119

120 of 217

Appearance Settings

120

121 of 217

Select Wallpaper

121

122 of 217

Change Wallpaper

122

123 of 217

Edit Terminal Preferences

123

124 of 217

Increase Font Size

124

125 of 217

Insert USB Flash Disk

125

126 of 217

File Manager

126

127 of 217

Eject USB Flash Disk

127

128 of 217

Select USB Flash Disk

128

129 of 217

Remove USB Flash Disk

129

130 of 217

USB Webcam

No need to enable camera serial interface (CSI) for USB webcam

Install fswebcam

pi@raspberrypi:~ $ sudo apt update

pi@raspberrypi:~ $ sudo apt install fswebcam

pi@raspberrypi:~ $ fswebcam image.jpg

--- Opening /dev/video0...

Trying source module v4l2...

/dev/video0 opened.

No input was specified, using the first.

Adjusting resolution from 384x288 to 352x288.

--- Capturing frame...

Captured frame in 0.00 seconds.

--- Processing captured image...

Writing JPEG image to 'image.jpg'.

pi@raspberrypi:~ $ fswebcam -r 1280x720 image2.jpg

pi@raspberrypi:~ $ fswebcam -r 1280x720 --no-banner image3.jpg

130

131 of 217

Raspberry Pi Camera Module

Enable camera serial interface (CSI) to use a Raspberry Pi camera module

pi@raspberrypi:~ $ raspistill -o image4.jpg

131

132 of 217

Solderless Breadboards

132

Full Size (830 or 840 Tie Points)

Half Size (400 Tie Points)

Separate Power Rails

133 of 217

Preformed 22 AWG Wires

133

PVC Insulation

Length (Inch)

PVC Insulation

Length (Inch)

No Insulation

0.1

Gray

0.8

Red

0.2

White

0.9

Orange

0.3

Brown

1.0

Yellow

0.4

Red

2.0

Green

0.5

Orange

3.0

Blue

0.6

Yellow

4.0

Violet

0.7

Green

5.0

134 of 217

DuPont Connectors

134

135 of 217

GPIO Extension Board or Cobbler

135

T-Type

U-Type

136 of 217

T-Type Extension Board Widths

136

1.0 cm

1.8 cm

137 of 217

Streamlined GPIO Extension Board

137

Consolidated 3V3, 5V, and GND pins

138 of 217

Ribbon Cable

138

139 of 217

Breadboard for Raspberry Pi

139

140 of 217

Breadboard for Raspberry Pi

140

141 of 217

Hammer-In Solderless Pin Headers

141

142 of 217

Pin Headers

142

Source: Jameco

143 of 217

General-Purpose Input/Output

143

5V0

5V0

G

N

D

14

15

18

G

N

D

23

24

G

N

D

25

8

7

ID

SC

G

N

D

12

G

N

D

16

20

21

TX

RX

P1

P4

P5

P6

CE0

CE1

P26

P27

P28

P29

3V3

2

3

4

G

N

D

17

27

22

3V3

10

9

11

G

N

D

ID

SD

5

6

13

19

26

G

N

D

SDA

SCL

P7

P0

P2

P3

CO PI

CI

PO

SC

LK

P21

P22

P23

P24

P25

Power

Ground

Serial

(UART)

SPI

I2C

GPIO

Streamlined

Extension

Board

GPIO

I2C ID

EEPROM

Shorting power pins to any other pin can damage Raspberry Pi

144 of 217

RPi 4B GPIO Alternate Functions

See Figure 3 and Table 5 of the Raspberry Pi 4 Model B Datasheet, Release 1, June 2019

In addition to the standard peripheral options found on legacy Pis, extra I2C, UART and SPI peripherals have been added to the BCM2711 chip and are available as further mux options on the Pi4

pi@raspberrypi:~ $ pinout

...

Revision : a03111

SoC : BCM2711

RAM : 1024Mb

Storage : MicroSD

USB ports : 4 (excluding power)

Ethernet ports : 1

Wi-fi : True

Bluetooth : True

Camera ports (CSI) : 1

Display ports (DSI): 1

...

For further information, please refer to https://pinout.xyz/

144

145 of 217

Serial (UART)

Raspberry Pi serial (UART) has two mutually exclusive uses

  • Connecting to a PC with a serial-to-USB console cable to allow access to the Linux console
    • Helps fix problems during boot, or login to Raspberry Pi without a monitor and network
  • Connecting to a microcontroller or other peripheral that has a serial (UART) interface
    • Useful for Raspberry Pi to communicate with another device

145

146 of 217

Serial-to-USB Console Cable

  • Install driver on laptop

Prolific > SIO (Smart-IO) > USB to UART/Serial/Printer > PL2303HXD

  • Connect a serial-to-USB console cable from a laptop USB to Raspberry Pi GPIO as follows:
    • Black to GND
    • White to TXD
    • Green to RXD
  • Windows > PuTTY > Serial with the Prolific COM port number and speed 115200
  • macOS (or Linux) > Terminal with the device name and speed 115200, e.g.,

$ screen /dev/cu.usbserial 115200

  • Connect either of the following but not both:
    • Red to 5V
    • Micro-USB power cable

146

147 of 217

Console Login

Menu>Preferences>Raspberry Pi Configuration>Interfaces>Enable Serial Console (enabled by default)>Shutdown

After connecting GND, TXD, and RXD with a serial-to-USB console cable to a laptop, first run PuTTY or the screen command on laptop then connect Raspberry Pi to 5V

$ screen /dev/cu.usbserial 115200

Uncompressing Linux... done, booting the kernel.

Welcome to the rescue system

recovery login: pi

...

Raspbian GNU/Linux 9 ioto ttyAMA0

ioto login: pi

Password:

...

pi@ioto:~ $ sudo raspi-config

...

pi@ioto:~ $ sudo shutdown -h now

...

control-a k

Really kill this window [y/n]y

[screen is terminating]

147

  • ttyS0 for Raspberry Pi 3B, 3B+, 4B, and Zero W
  • ttyAMA0 for Raspberry Pi 1B, 1B+, 2B, and Zero
  • Number 0, not letter O

148 of 217

TTY

  • A teleprinter, teletypewriter, teletype, or TTY was an electromechanical typewriter paired with a communication channel and adapted to provide a user interface to early mainframe computers and minicomputers, sending typed data to the computer and printing the response
  • TTY has continued to be used as the name for the text-only console such as PuTTY http://www.putty.org/

pi@4B2G:~ $ cd /dev

pi@4B2G:/dev $ ls

...

ttyAMA0

...

ttyS0

...

pi@4B2G:/dev $

148

  • Number 0, not letter O
  • Number 0, not letter O

149 of 217

AMA is Short for AMBA

149

150 of 217

Disable Console to Use UART

Menu>Preferences>Raspberry Pi Configuration>Interfaces>Enable Serial Port and Disable Serial Console

Alternatively, delete "console=serial0,115200" in /boot/cmdline.txt then reboot

pi@4B2G ~ $ sudo nano /boot/cmdline.txt

console=tty1 console=serial0,115200 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles

control-x y enter

pi@4B2G:~ $ sudo reboot

...

pi@4B2G:~ $ cat /boot/config.txt

...

enable_uart=1

pi@4B2G:~ $ cd /dev

pi@4B2G:/dev $ ls

...

ttyAMA0

...

ttyS0

...

150

  • Raspberry Pi 1B, 1B+, 2B, and Zero use ttyAMA0 for UART
  • 3B, 3B+, 4B, and Zero W use ttyAMA0 for Bluetooth and ttyS0 for UART

151 of 217

Serial Loopback Test

151

Connect serial TXD and RXD with a jump wire

152 of 217

Minicom Commands

pi@4B2G:~ $ sudo apt install minicom

+-------------------------------------------------------------------+

| Minicom Command Summary |

| |

| Commands can be called by CTRL-A <key> |

| |

| Main Functions Other Functions |

| |

| Dialing directory..D run script (Go)....G | Clear Screen.......C |

| Send files.........S Receive files......R | cOnfigure Minicom..O |

| comm Parameters....P Add linefeed.......A | Suspend minicom....J |

| Capture on/off.....L Hangup.............H | eXit and reset.....X |

| send break.........F initialize Modem...M | Quit with no reset.Q |

| Terminal settings..T run Kermit.........K | Cursor key mode....I |

| lineWrap on/off....W local Echo on/off..E | Help screen........Z |

| Paste file.........Y Timestamp toggle...N | scroll Back........B |

| Add Carriage Ret...U |

| |

| Select function or press Enter for none. |

+-------------------------------------------------------------------+

152

153 of 217

Serial Loopback Test: 115200 Baud

pi@4B2G:~ $ minicom –b 115200 –o –D /dev/ttyS0

Welcome to minicom 2.7.1

OPTIONS: I18n

Compiled on Aug 13 2017, 15:25:34.

Port /dev/ttyS0

Press CTRL-A Z for help on special keys

control-a a

Hello

control-a e

HHeelllloo

control-a x

+----------------------+

| Leave Minicom? |

| Yes No |

+----------------------+

CTRL-A Z for help | 115200 8N1 | NOR | Minicom 2.7 | VT102 | Offline | ttyS0

153

  • -b: baud rate (maximum bits/sec)*
  • -o: no initialization
  • -D: device
  • ttyS0 (number 0, not letter O) for Raspberry Pi 3B, 3B+, 4B, and Zero W
  • ttyAMA0 for Raspberry Pi 1B, 1B+, 2B, and Zero

154 of 217

Serial Loopback Test: 9600 Baud

pi@4B2G:~ $ minicom –b 9600 –o –D /dev/ttyS0

Welcome to minicom 2.7.1

OPTIONS: I18n

Compiled on Aug 13 2017, 15:25:34.

Port /dev/ttyS0, 14:27:48

Press CTRL-A Z for help on special keys

control-a a

Hello

control-a e

HHeelllloo

control-a x

+----------------------+

| Leave Minicom? |

| Yes No |

+----------------------+

CTRL-A Z for help | 9600 8N1 | NOR | Minicom 2.7 | VT102 | Offline | ttyS0

154

  • -b: baud rate (maximum bits/sec)*
  • -o: no initialization
  • -D: device
  • ttyS0 (number 0, not letter O) for Raspberry Pi 3B, 3B+, 4B, and Zero W
  • ttyAMA0 for Raspberry Pi 1B, 1B+, 2B, and Zero

155 of 217

Émile Baudot 1845—1903

  • Jean-Maurice-Émile Baudot was a French telegraph engineer and inventor of the first means of digital communication Baudot code and a multiplexed printing telegraph system (U.S. Patent 388,244 1888) that used his code and allowed multiple transmissions over a single line
  • The baud unit for symbol rate or modulation rate was named after him

155

156 of 217

Crystal Oscillator Frequencies

  • A crystal oscillator is an electronic oscillator circuit that uses the mechanical resonance of a vibrating crystal of piezoelectric material to create an electrical signal with a constant frequency
  • This frequency is often used to keep track of time, as in quartz wristwatches, to provide a stable clock signal for digital integrated circuits, and to stabilize frequencies for radio transmitters and receivers
  • The most common type of piezoelectric resonator used is the quartz crystal
  • Quartz crystals are manufactured for frequencies from a few tens of kilohertz to hundreds of megahertz
  • Using frequency dividers, frequency multipliers, and phase locked loop circuits, it is practical to derive a wide range of frequencies from one reference frequency, e.g., 7.3728 MHz / 64 = 115,200 baud
  • Most crystals are used for consumer devices such as wristwatches, clocks, radios, computers, and cellphones
  • Quartz crystals are also found inside test and measurement equipment, such as counters, signal generators, and oscilloscopes

156

157 of 217

KNX — ISO/IEC 14543-3

  • The KNX standard is an OSI-based network communications protocol for home/building control and automation administered by the KNX Association
  • KNX defines several physical communication media:
    • Twisted pair wiring
    • Powerline networking
    • Radio (KNX-RF)
    • Infrared
    • Ethernet
  • The Engineering Tool Software (ETS) is a part of the KNX standard for designing and configuring installations

157

158 of 217

Low-Rate Wireless Personal Area Networks

158

Topology

Point-to-point, star, tree, mesh

Point-to-point, star, mesh

Mesh

Mesh

Mesh

Frequency in US

2.4 GHz

2.4 GHz

2.4 GHz, 915 MHz

2.4 GHz, 915 MHz

908.42 MHz

Max. Data Rate

60 kb/s

2 Mb/s

250 kb/s

250 kb/s

100 kb/s

Max. Range

30 m

600 m

100 m

100 m

100 m

Standards

Garmin

Bluetooth SIG

IETF 6LoWPAN

IEEE 802.15.4

IEEE 802.15.4

Sigma Designs

159 of 217

Bluetooth

  • Ericsson initiated Bluetooth technology development in 1989, and named its standard specification in 1997 after Scandinavian king, Harald I of Denmark, also known as Harald "Blåtand" Gormsson 935—985
  • The logo is formed from his initials HB in runes
  • Bluetooth is the English translation of his epithet "Blåtand" perhaps for his regular consumption of blueberries that stained his teeth blue
  • Harold Bluetooth completed his father’s work of unifying various tribes into one kingdom around 970
  • Bluetooth was meant to offer a set unified standard, replacing a variety of competing protocols

159

160 of 217

Waggle Dance of Honey Bees

  • The 1927 book by Karl von Frisch 1886—1982 describes that a honey bee performs a waggle dance that instructs the rest of the hive where to find a distant food source
    • Waggle run
    • Turn to the right
    • Return to start point
    • Waggle run
    • Turn to the left
    • Return to start point
  • The zenith angle 𝛼 of the waggle run indicates the direction in relation to the sun
  • The duration of the waggle run signifies the distance

160

Start Point

161 of 217

Hedy Lamarr 1914—2000

  • Hedwig Eva Maria Kiesler, an Austrian and American film actress, co-invented "Secret Communication System" U.S. Patent 2,292,387 in 1941 with American composer and pianist George Antheil 1900—1959
  • Using a method similar to the way paper player piano rolls work, they drafted designs for a new frequency-hopping, spread-spectrum technology
  • Although the technology wasn't adopted until 1962, the principles are now incorporated into Bluetooth, CDMA, Wi-Fi, ZigBee, etc.

161

162 of 217

XBee ZigBee Modules

162

XBee ZB with PCB antenna

ZigBee/IEEE 802.15.4 module

and adapter for breadboard

3.3V

USB to serial adapter

e.g., support Digi XCTU over usbserial-AL0046V6

5V

Breakout board

5V

163 of 217

XBee Pinout

163

1

VCC (3V3)

AD0/DIO0

20

2

DOUT

AD1/DIO1

19

3

DIN/CONFIG

AD2/DIO2

18

4

DIO12

AD3/DIO3

17

5

RESET

RTS/DIO6

16

6

RSSI PWM/DIO10

Associate/DIO5

15

7

DIO11

VREF

14

8

[reserved]

ON/SLEEP/DIO9

13

9

DTR/SLEEP_RQ/DIO8

CTS/DIO7

12

10

GND

DIO4

11

Minimum

connections

highlighted

Low-asserted

signals

overlined

RSSI: Received Signal Strength Indicator

PWM: Pulse Width Modulation

DTR: Data Terminal Ready

AD: Analog-to-Digital

DIO: Digital Input/Output

RTS: Request-to-Send

CTS: Clear-to-Send

164 of 217

XBee Setup

164

165 of 217

XBee Configuration 0/1

  • Install and run Digi XCTU Configuration & Test Utility on PC http://www.digi.com/products/xbee-rf-solutions/xctu-software/xctu
  • Attach an XBee module (e.g., Digi XB24-ZB Series 2) with USB-to-serial adapter (e.g., FTDI FT232R USB UART) to PC
    • XBee modules ship with Router AT firmware
      • Update to the newest firmware if needed
      • Update one XBee module with the newest Coordinator AT firmware
      • If update fails, run Recovery
    • No need to change default parameter values (e.g., PAN ID=0) for a single network

165

166 of 217

XBee Configuration 1/1

166

167 of 217

XBee M2M Demo

RaspberryPi is COORDINATOR

pi@raspberrypi:~ $ minicom -b 9600 -o -D /dev/ttyS0

control-a a

control-a e

Hello from COORDINATOR

control-a x

4B1G is ROUTER_1

pi@4B1G:~ $ minicom -b 9600 -o -D /dev/ttyS0

control-a a

control-a e

Hello from ROUTER_1

control-a x

4B2G is ROUTER_2

pi@4B2G:~ $ minicom -b 9600 -o -D /dev/ttyS0

control-a a

control-a e

Hello from ROUTER_2

control-a x

167

  • ttyS0 for Raspberry Pi 3B, 3B+, 4B, and Zero W

168 of 217

Analog-to-Digital Converter (ADC)

168

3V3

3V3

GND

SPI/SCLK

SPI/MISO

SPI/MOSI

SPI/CE0

GND

_______

CS/SHDN: Chip Select/Shutdown

169 of 217

Inclusive Terminology

  • In May 2014, Django replaced "master/slave" with "primary/replica" and this has also been adopted by Drupal, Microsoft, and Amazon Web Services/Amazon Relational Database Service
  • In 2018, Python replaced uses of the term "master" variously with "main", "parent", and "server"; "slave" with "worker", "child", and "helper", depending on the context; and the Linux kernel has adopted a similar policy to use more specific terms in new code or documentation
  • In June 2020, the Open Source Hardware Association (OSHWA) resolved to "controller/peripheral"
  • In July 2020, MySQL announced that it would replace "master/slave" with "source/replica" in future releases
  • In Oct. 2020, GitHub started renaming the default branch from master to "main"
  • In December 2020, IEEE SA Standards Board resolutions included "IEEE standards should be written in such a way as to avoid non-inclusive and insensitive terminology and other deprecated terminology ..."
  • Adafruit has used "main/secondary" or "microcontroller/sensor"

169

170 of 217

SPI Loopback Test

SPI enabled by Menu > Preferences > Raspberry Pi Configuration > Interfaces

pi@4B2G:~ $ cat /boot/config.txt

dtparam=spi=on

pi@4B2G:~ $ wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documentation/spi/spidev_test.c

pi@4B2G:~ $ gcc -o spidev_test spidev_test.c

Put a wire between MOSI and MISO for spidev-test

pi@4B2G:~ $ ./spidev_test -D /dev/spidev0.0

spi mode: 0

bits per word: 8

max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF

40 00 00 00 00 95

FF FF FF FF FF FF

FF FF FF FF FF FF

FF FF FF FF FF FF

DE AD BE EF BA AD

F0 0D

170

  • Device tree parameter
  • GCC: GNU Compiler Collection

171 of 217

1-kΩ 4-Band and 5-Band Resistors

171

  • 1
  • 0
  • x 100
  • 1
  • 0
  • x 10
  • 0

172 of 217

Resistor Color Code

172

Color

Band 1, 2, (3)

Multiplier

Tolerance

Temperature

Black

0

100

Brown

1

101

±1%

100 ppm/°K

Red

2

102

±2%

50 ppm/°K

Orange

3

103

15 ppm/°K

Yellow

4

104

25 ppm/°K

Green

5

105

±0.5%

Blue

6

106

±0.25%

Violet

7

107

±0.1%

Grey

8

108

±0.05%

White

9

109

Gold

10-1

±5%

Silver

10-2

±10%

None

±20%

173 of 217

Light-Dependent Resistor (LDR)

  • LDR or photoresistor is a light-controlled variable resistor
  • Resistance decreases with increasing incident light intensity
  • LDR resistance as high as several megohms (MΩ) in the dark, and as low as a few hundred ohms in the light

173

174 of 217

LDR, ADC, and Lux

  • LDR can be used with or without an ADC
  • MCP3008, a 10-bit ADC, reads values from 0 to 1023

v_ldr=(light_level*3.3)/1023

  • In contrast, the analog pins of the Particle IoT hardware read values from 0 to 4095 (12-bit resolution)
  • One lux (of illuminance) is one lumen per square meter

lux=500/r_ldr

v_ldr=3.3*r_ldr/(R+r_ldr)

r_ldr=(R*v_ldr)/(3.3-v_ldr)

lux=500*(3.3-v_ldr)/(R*v_ldr)

174

175 of 217

LDR with or without ADC

175

C=1μF

RLDR

VIN=3.3V

GND

VC

VC=VIN/(1+RLDRC)

RLDR

R=10KΩ

VIN=3.3V

GND

VLDR

VLDR=VINRLDR/(R+RLDR)

176 of 217

LDR with ADC

176

177 of 217

LDR without ADC

177

LDR

178 of 217

Light-Emitting Diodes (LEDs)

178

+-++

or -+--

  • flat spot
  • larger plate inside
  • Shorter lead

179 of 217

Switch an LED on/off

pi@4B2G:~ $ sudo su

root@raspberypi:/home/pi# echo 18 > /sys/class/gpio/export

root@raspberypi:/home/pi# cd /sys/class/gpio/gpio18

root@raspberypi:/sys/class/gpio/gpio18# echo out > direction

root@raspberypi:/sys/class/gpio/gpio18# echo 1 > value

root@raspberypi:/sys/class/gpio/gpio18# echo 0 > value

root@raspberypi:/sys/class/gpio/gpio18# cd /home/pi

root@raspberypi:/home/pi# echo 18 > /sys/class/gpio/unexport

root@raspberypi:/home/pi# exit

exit

pi@4B2G:~ $

179

180 of 217

Relay (Songle SRD-05VDC-SL-C)

180

NO: Normally Open

NC: Normally Close

Common

181 of 217

DC Motor Driver (Keyes L298)

181

Connect GND to the Raspberry Pi GND

182 of 217

IoT Sensor Examples

182

Accelero-

meter

Orienta-

tion

Air

Gas

Dust

Particle

Distance

Gesture

Motion

Proximity

Light

Magnet

Water

Sound

Temp.

Temp.

Humidity

Temp.

Pressure

ADC

SPI

MQ-7 MQ-135

TCRT5000

LDR

A930 YL-38/

XD-28

YL-69

ADMP401 INMP401

LM393

SPW2430

LM35

MAX6675

TMP36

I2C

ADXL335 ADXL345

BNO055

GY-521

LSM9DS0

MPU-6050

MPU-9250

APDS-9960

SHT31-D

BMP085 BMP180 BMP280

MSP100

1-Wire

DS18B20

GPIO

PPD42NS

DYP-ME003

HC-SR04 HC-SR501

Door Switch Set

SparkFun Sound Detector

AM2302 DHT11 DHT22

183 of 217

Additional Sensors

  • Benewake TFmini LiDAR and PulsedLight LIDAR-Lite v2
  • Keyes KY-026 flame sensors
  • Leap Motion controller
  • Particle/dust sensors
    • OneAir A4
    • PlanTower PMS 1003, 3003, 5003, 6003, 7003, and A003
    • Samyoung DSM501 and MDG501
    • Sharp GP2Y1010AU0F and DN7C3CA006
    • Shinyei PPD42NJ, PPD20V, PPD60PV, and PM sensors
  • Piezoelectric vibration sensors, force-sensing resistor (FSR), micro load cell
  • PN532 RFID / near field communication (NFC)
  • Raspberry Pi Sense HAT (Hardware Attached on Top)
  • Rhiot app on Android phone
  • Texas Instruments SimpleLink SensorTag
  • Waveshare sound detection module with LM386 audio power amplifier
  • ZFM-60 fingerprint sensor detection recognition module

183

184 of 217

Sensors with 3.3V Supply Voltage

184

DHT11,

DHT22, or

AM2302

(GPIO) Temperature

/Humidity

Sensor

BMP085 or BMP180 (I2C)

BMP280 (I2C)

Pressure/Temperature Sensor

ADXL345 (I2C)

Accelerometer

YL-38 with XD-28 or YL-69 (SPI)

Hygrometer/Moisture Sensor

185 of 217

Sensors with 5V Supply Voltage

185

MQ-7 (SPI)

CO Gas Sensor

MQ-135 (SPI)

CO2/NOx/Alcohol/Ammonia

/Benzene/Smoke Sensor

HC-SR04 (GPIO)

Ultrasonic Ranging Module

DYP-ME003 or HC-SR501 (GPIO)

Passive Infrared (PIR) Motion Sensor

186 of 217

Canaries in the Coal Mine

  • By holding air in extra sacs, canaries get a double dose of air and any poisons the air might contain when they inhale and exhale
  • Sentinel species are organisms, often animals, used to detect risks to humans by providing advance warning of a danger
  • A bioindicator is any species (an indicator species) or group of species whose function, population, or status can reveal the qualitative status of the environment

186

187 of 217

Batteries for IoT Devices

187

188 of 217

Install i2c-tools

I2C enabled by Menu > Preferences > Raspberry Pi Configuration > Interfaces

pi@4B2G:~ $ cat /boot/config.txt

...

dtparam=i2c_arm=on

...

pi@4B2G:~ $ cat /etc/modules

...

i2c-dev

pi@4B2G:~ $ sudo apt install i2c-tools python-smbus

pi@4B2G:~ $ sudo reboot

188

  • SMBus: System Management Bus
  • i2c-dev kernel module loaded at boot time
  • Device tree parameter

189 of 217

BMP180 Setup

189

190 of 217

ADXL345 Setup

190

191 of 217

Detect I2C Chips 0/5

Nothing connected with I2C SDA and SCL on Raspberry Pi

pi@4B2G:~ $ sudo i2cdetect -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

191

192 of 217

Detect I2C Chips 1/5

MSP100 pressure transducer such as MSJ-00000U-250PG connected with 5V (red), GND (green), SDA (white), and SCL (black) on Raspberry Pi

pi@4B2G:~ $ sudo i2cdetect -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- 28 -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

192

193 of 217

Detect I2C Chips 2/5

ADS1115 16-bit (ADS1015 12-bit) 4-channel analog-to-digital converter (ADC) connected with I2C SDA and SCL on Raspberry Pi

pi@4B2G:~ $ sudo i2cdetect -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --

50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

193

194 of 217

Detect I2C Chips 3/5

ADXL345 3-axis accelerometer connected with I2C SDA and SCL on Raspberry Pi

pi@4B2G:~ $ sudo i2cdetect -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- -- 53 -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

194

195 of 217

Detect I2C Chips 4/5

MLX90614 digital non-contact infrared thermometer connected with 5V, GND, and I2C SDA and SCL on Raspberry Pi

pi@4B2G:~ $ sudo i2cdetect -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- -- -- -- -- -- -- -- -- 5a -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

195

196 of 217

Detect I2C Chips 5/5

BMP180 and BMP280 barometric pressure sensor connected with I2C SDA (SDI) and SCL (SCK) on Raspberry Pi

pi@4B2G:~ $ sudo i2cdetect -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- 77

196

197 of 217

1-Wire Digital Thermometer

  • Enable 1-Wire interface to use Dallas Semiconductor DS18B20 temperature sensors (waterproof version on the right)
  • Follow the tutorial to test DS18B20

197

198 of 217

Testing 1-Wire in Use 0/1

Connect DS18B20 to Raspberry Pi as follows:

(1) GND to GND, (2) VDD to 3.3V or 5V, and (3) DQ to GPIO 4 (the 4th pin from the left of the bottom row) and through a 4.7kΩ resistor to VDD

198

199 of 217

Testing 1-Wire in Use 1/1

pi@4B2G:~ $ sudo modprobe w1-gpio

pi@4B2G:~ $ sudo modprobe w1-therm

pi@4B2G:~ $ cd /sys/bus/w1/devices

pi@4B2G:/sys/bus/w1/devices $ ls

28-031868b2fbff w1_bus_master1

pi@4B2G:/sys/bus/w1/devices $ cd 28*

pi@4B2G:/sys/bus/w1/devices/28-031868b2fbff $ cat w1_slave

af 01 4b 46 7f ff 0c 10 35 : crc=35 YES

af 01 4b 46 7f ff 0c 10 35 t=26937

pi@4B2G:/sys/bus/w1/devices/28-031868b2fbff $ cd

pi@4B2G:~ $

199

  • CRC: Cyclic Redundancy Check

200 of 217

HATs and pHATs

  • HAT stands for Hardware Attached on Top
  • Top 10 HATs for the Raspberry Pi, e.g., Sense HAT
  • HATs are designed to work with standard Raspberry Pi computers, while pHATs are designed to work with the Raspberry Pi Zero, e.g., pHAT BEAT

200

201 of 217

Lesson 2 Summary

  • Two commonly encountered problems with Raspberry Pi
    • Changing Wi-Fi password requires manual update to ~/etc/wpa_supplicant/wpa_supplicant.conf
    • Use a different SD card or Wi-Fi dongle requires manual update to ~/.ssh/known_hosts
  • Raspberry Pi serial has two mutually exclusive uses
    • Serial console for login
    • Serial digital read and write
      • Use ADC with spidev to read analog input
  • Always double-check GPIO numbering and wiring to avoid damaging Raspberry Pi

201

202 of 217

Splash Screen

202

203 of 217

Image Screen

203

204 of 217

Click Wi-Fi Network

204

205 of 217

Connect to Stevens Wi-Fi

205

206 of 217

Select Raspberry Pi OS (32-bit)

206

207 of 217

More Operating Systems

207

208 of 217

Select US Language and Keyboard

208

209 of 217

Click OK to Confirm Installation

209

210 of 217

Installation in Progress

210

211 of 217

Click OK to Reboot

211

212 of 217

Raspberry Pi OS Screen

212

213 of 217

Raspberry Pi OS Console

213

214 of 217

PIXEL Screen

214

PIXEL (Pi Improved Xwindows Environment, Lightweight) Desktop

215 of 217

Low-voltage Indicator

215

Low-voltage indicator →

due to inadequate USB cable or power supply

216 of 217

SSH IPQoS Option

Only if SSH doesn’t work because of Raspberry Pi Wi-Fi, add IPQoS option to the end of /etc/ssh/sshd_config

pi@raspberrypi:~ $ sudo nano /etc/ssh/sshd_config

...

IPQoS cs0 cs0

control-x y enter

pi@raspberrypi:~ $ sudo service ssh restart

  • The first value for interactive sessions
  • The second value for non-interactive sessions

216

217 of 217

Date/Time Synchronization

Only if the date command shows incorrect date/time, add the following command in /etc/rc.local so that Raspberry Pi can forward ntpd (Network Time Protocol Daemon) packets with ToS (Type of Service) 0xc0 as 0x00

pi@raspberrypi:~ $ date

Tue Sep 6 17:09:10 EDT 2016

pi@raspberrypi:~ $ sudo nano /etc/rc.local

...

/sbin/iptables -t mangle -I POSTROUTING 1 -o wlan0 -p udp --dport 123 -j TOS --set-tos 0x00

...

exit 0

control-x y enter

pi@raspberrypi:~ $ sudo reboot

217