Robert Tisma presents on baking a Raspberry PI with Chef Rob. He discusses the history and architecture of the Raspberry PI, how to install operating systems like Raspbian, and how to interface with sensors and actuators using communication protocols like I2C and GPIO. He demonstrates controlling the Raspberry PI through various methods and provides an overview of development options for creating code on the Raspberry PI.
2. ● B.Eng and M.Eng degree from McMaster
University in Electrical and Biomedical
Engineering
● Currently working as a Senior Software Developer
in Genome Informatics at the Ontario Institute for Cancer Research
● Love working with the Raspberry Pi (RPi) and talking about it!
About the Cook
3. ● Use caution when dealing with electronics, it can be dangerous!
● Consult an electrician when making adjustments to your home
● I am not responsible for any damage as a result of this talk
Disclaimer
4. ● History
● Architecture and Layout
● Installation and Configuration
● HW/SW Interfacing and Communication
● Simple Usage and Development
● Demos
Overview
6. Description
● Low-cost open-source single-board computer about the size of a hand, able to run
embedded linux where its hardware and software can be modified to interact with
the world
● Provides an ideal platform for Internet of Things (IoT) applications, as well as
robotics, cyber-physical systems, 3D printing and much much more
● Stitches together low-level electronics and high-level Linux software
RPi 3RPi 2
7. Brief History
● Developed by the charity, The Raspberry Pi Foundation in the UK, which was
founded in 2009
● Motivated by the decreasing number of CS applicants and increase in low-level
technical debt
● Idea was to develop a small and affordable computing platform to stimulate the
interest of students and teach them the basics of computer science
● Due to the boom of low-cost SOCs (System-On-a-Chip) for mobile applications in
2012, it was possible to deliver an affordable RPi platform
● First day sales resulted in more than 100,000 units sold!
● Tremendous impact resulting in more than 5 million RPi boards sold near the
beginning of 2015
9. Who supports the RPi?
● Raspberry Pi Organization consists of 2 branches:
○ Raspberry Pi Trading which is responsible for developing the technology
○ Raspberry Pi Foundation which is an educational charity that supports the teaching of
computer science in schools and developing countries
● Eben Upton, an ASIC Architect for Broadcom and one of the Founders, is currently
the CEO of the Trading branch
● The RPi developer community
10. When to Use a RPi
● To integrate high-level software with low-level electronics
● Building an automated home management system, robot, multimedia display,
Internet of Things (IoT) applications, Multimedia applications, such as HD video
● Leverage the Linux OS for embedded systems applications
○ Easier than traditional embedded systems like PIC and AVR microcontrollers
○ Support for USB peripherals
○ Control low-level HW with high-level SW
● May also be used for commercial applications
○ Some licensing agreements (i.e GPL) have specific requirements
11. Who should use it?
● Anyone interested in transforming an idea into a real electronics project
● Anyone that needs a low-end and low-power computing platform
● All levels of skill as the RPi community provides tools and hardware to simplify this
realization
● From electronics gurus with barely any programming experience, to software
experts that have never wired an LED
12. Who should NOT use it?
● Anyone interested in real-time processing
○ Interrupt latency
○ Scheduling latency
● RPi can be used to control or manage real-time microcontrollers (such as PIC or
AVR microcontrollers)
15. Specifications (Continued)
● Bluetooth (RPi 3: Bluetooth 4.1, RPi 3+: Bluetooth 4.2 LS and BLE)
● Storage: microSD
● GPIO: 40-pin header, populated
● Ports: HDMI, 3.5mm analogue audio-video jack, 4× USB 2.0, Ethernet, Camera
Serial Interface (CSI), Display Serial Interface (DSI)
● Power Consumption (@ 5V)
○ RPI 3
■ Idle: 300 mA (1.5 W)
■ Max Stress: 1340 mA (6.7 W)
○ RPi 3+
■ Idle: 459 mA (2.3W)
■ Max Stress: 1130 mA (5.7W)
16. Fun Fact
● What would it cost to run an RPi 3 under max stress non-stop for a year?
● Worst case scenario:
○ Alectra Utilities as of 2018-11-04, charges $0.132/kWh during peak hours
○ RPi 3 during max stress: 6.7 W or 0.0067 kW
● Calculation
○ (0.0067 kW) * ($0.132/kWh) * (24 h/day) * (365 days/year)
< $7.75 CAD per year!!!
19. Compute Module
● Purpose is to make an easy and low-cost option for developing customized
products using Raspberry Pi hardware and software
● Specifically designed for commercial and industrial applications
● Costs just as much as a regular RPi 3
● More compact access to the many interfaces of the BCM2837 SoC
Front Back
23. System-on-a-Chip (SoC)
● An integrated circuit (IC) that contains all the major components of a computer
system on a single chip
● Contains one or more CPU cores, a GPU and various digital, analog and
mixed-signal circuitry all under a single dense chip
● Increased power efficiency over microprocessor since it minimizes wiring and
electrical material
● Slightly larger than a microprocessor
● Not as powerful as a microprocessor
● RPi uses Broadcom SoCs (BCM283[5, 6, 7])
24. BCM2837 SoC at a Glance
● CPU
● GPU (Broadcom VideoCore IV)
● Memory
● Timers
● DMA (Direct Memory Access)
● Interrupt Controller
● GPIO (General Purpose Input Output)
● USB (Universal Serial Bus)
● PCM (Pulse Code Modulation)
● I2S (Inter-IC Sound)
● PWM (Pulse Width Modulation)
● Serial Communication
○ I2C (Inter-Integrated Circuit)
○ SPI (Serial Peripheral Interface)
○ UART (Universal Asynchronous
Receiver/Transmitter)
25. Camera Serial Interface (CSI)
● 15 flat wire port used to interface with the raspberry pi camera
● Typical camera modules can provide 5MP or 8MP images with 1080p HD video
● Useful for security monitoring or CV applications
26. Display Serial Interface (DSI)
● Serial communication protocol between RPi and display technology
● Typically used to display data on a LCD screen
● Kivy is an open source cross platform Python GUI development library, designed to
be used with touch screen devices
27. General Purpose Input/Output (GPIO)
● 2x 5 V pins, to power other devices attached to the RPi
● Several ground pins
● Digital I/O as well as analog I/O
● Pins can be OFF, LOW, or HIGH
● All GPIO banks use 3.3 V
○ dont go over this, otherwise you can risk destroying the board
○ should only source/sink approximately 2-3 mA from/to each pin
○ to prevent overheating, never source/sink more current from the pin than its programmed
limit
● Most pins have multiple or alternative functionality (I2C, SPI, UART, etc)
● Almost all GPIO pins can enable/disable internal pull-up and pull-down resistors
● Phenomenal GPIO pin documentation at pinout.xyz
28. Communication Protocols
● In order to interact with peripheral devices, data must be sent to and from the RPi
● Define the rules for transmitting data between 2 or more entities
● Parallel communication is much faster than serial, but it requires much more wiring
● Serial communication transmits data using a few wires, however is slower than
parallel
● Many ICs (Integrated Circuits), sensors and peripheral devices use common
communication protocols such as I2C, SPI, UART, and 1-Wire
● Using the RPis onboard communication protocols, a user can communicate with
the outside world!
29. Asynchronous Serial Communication - UART
● Universal Asynchronous Receiver and Transmitter (UART)
● Asynchronously receives and transmits data, bit by bit using a TX and RX pin
● Transmission speed (baudrate) and dataframe format must match between Rx and Tx
● Point-to-Point topology (Simplex/Half-Duplex/Full-Duplex)
● Transmission distance governed by transmission
protocols such as RS-232 (~15m) and RS-422
(~1000m)
● UART0 and UART1 on the RPi share the same pins
○ UART0 is used for serial communication
○ UART1 is used for console interaction with the RPi
○ UART type can be selected using raspi-config tool
● Supported by WiringPi (C) and WiringPi2 (python)
RS-232
Serial Port
30. Asynchronous Serial Communication - 1-Wire
● Asynchronous, low-speed communication protocol that encodes data using timed
pulses on a single dataline
● Half-duplex single-master/multi-slave
topology with addressable slaves
● Max speed of 16kbps
● Length up to 300m
● RPi supports 1-Wire which can be
configured using raspi-config
● Used in contact environments
(identification, authentication,
measurement, etc)
● In IDLE, data line is held HIGH and can
also power slaves
● HIGH (1) digital signal is represented
with a 1-15 μS LOW-pulse
● LOW (0) digital signal is represented
with a 60 μS LOW-pulse
32. ● Typical application is interfacing with
an ADC connected to an analog sensor
● SPI0 can be configured with the
raspi-config tool
● SPI1 can be enabled by modifying
/boot/config.txt
Synchronous Serial Communication - SPI
● Serial Peripheral Interface
● High-speed synchronous serial
communication
● Single-master/multi-slave topology
● Full-duplex
● Requires Slave Select (SS) line
(active low) == messy
● Transmission speeds as fast as
10Mbps
● Very short distances
● No receipt of acknowledgement
from slave
● Supported by WiringPi (C) and
spidev (python) libraries
33. ● Inter-integrated Circuit is a synchronous, multi-master, multi-slave,
packet-switched serial bus
● Half-duplex and slower than SPI, but requires only 2 wires: a clock and data line
● Up to 1008 slave devices (7 or 10 bit addressing) can be connected
● Speeds of 100, 400, 1000 and 3500 kbps
● ACK/NACK bit for acknowledging receipt
● 100 kbps for 1m distances, 10kbps for 10m
● Can be configured using the raspi-config tool
● Examples are temperature, acceleration,
Humidity sensors
● Supported by WiringPi (C) and
smbus (python) libraries
Synchronous Serial Communication - I2C
Master 1
SDA
SCL
Master 2
SDA
SCL
Slave 1
SDA
SCL
Slave 2
SDA
SCL
35. Installing Operating Systems - NOOBS
● Developed by the RPi Foundation for beginners
● New Out Of Box Software (NOOBS) is an easy operating system installation
manager for the Raspberry Pi
● Steps
○ Format a 8GB or larger SD card as a FAT filesystem
○ Just download the NOOBS software and unzip it
to the root directory of the SD card
● Contains the following
○ Raspbian (Full and Lite)
○ LibreELEC
○ OSMC
○ RecalBox
○ Lakka
○ RISC OS
○ Screenly OSE
○ Windows 10 IoT
○ TLXOS
36. Installing Operating Systems - Manually
● Useful for installing a particular image not available in NOOBS
● Steps
○ Download RPi image
○ Write it to SD card
■ Etcher is an open-source multi-platform tool that writes images to SD cards and USB
drives
37. Raspbian
● A version of Debian built and optimized for the RPi
● Officially supported by the RPi Foundation
● Current version is Debian 9 (Stretch) with Linux kernel version 4.14
● 2 versions available
○ Desktop
■ Uses PIXEL (Pi Improved X-Window Environment Lightweight) as its main desktop
environment,
■ Includes GUIs and many other tools
○ Lite
■ Boots to command line
■ Stripped down alternative to the Desktop version
■ Preferable for Linux users that live on the command line
39. Raspbian Configuration
● raspi-config is a configuration utility for raspbian
● Both GUI and CLI interfaces are available
● Can configure many interfaces and options on the RPi
● Configure wifi, camera, ssh, spi, i2c, serial as well as other advanced options
42. Docker
● Officially supported for the ARM architecture
● Easier deployment
● Only ARM based images can run on the RPi
○ amd64 docker images made on your laptop WILL NOT run on the RPi
● GPIO control via privileged mode
44. Sensors and Actuators
● Sensors
○ Device that detects events or changes in its surrounding environment and responds with
an electrical signal
○ Examples are temperature, humidity, acceleration, pressure sensors
● Actuators
○ Device that moves or controls some mechanism in response to a control signal
○ Examples are electromechanical relays, motors, heaters, hydraulic cylinders
● Interface
○ Typically communicate using one of the serial communication protocols
45. Raspberry Pi Hats
● HAT (Hardware Attached on Top)
● Third-party add-on board that attach directly to the RPi’s GPIO header
● RPi boards with 40 pin GPIO designed specifically with add-on boards in mind
● Boards conform to a HAT standard or set of rules
○ Auto board identification
○ Auto configuration of GPIO and drivers
● Extends functionality
● Simplifies design
46. The Sense HAT
● Add-on board for the RPi designed for the Astro Pi mission
● Astro Pi allows RPi-ers to write programs that run on RPi computers in the
International Space Station (ISS)
● The sense Python library provides easy access to the various devices
● 8×8 RGB LED matrix
● a five-button joystick and
includes the following sensors:
● Gyroscope
● Accelerometer
● Magnetometer
● Temperature
● Barometric pressure
● Humidity
49. Controlling the RPi
● Control using External Monitor
○ Need monitor, keyboard, mouse, hdmi cable
● Control using Console Cable
○ Need a PC and a USB -to-TTL cable
○ Connects PC USB port to the RPi 3 UART1 (miniUART) console port (default setting)
○ Cannot use UART0 port for serial communication
● Control using SSH
○ PC and RPi connected to the router/switch
○ PC connected to router via WiFi, and directly to RPi via Ethernet
■ RPi network interface supports Auto MDIX so no need for crossover cable
○ Just need a PC and an ethernet cable
50. Development
● Several options for developing RPi compatible code
○ Locally on RPi
○ Remote development
○ Cross-compile ARM binary on x86 (i.e arm-linux-gnueabi-gcc, golang)
○ RPi control via network on x86 (i.e pigpio)
● ARM emulation using QEMU
○ Build ARM binary/image on x86, run on RPi
○ Build ARM binary/image on x86, partially run on x86
51. Custom Raspbian Image
● Load local raspbian image using QEMU and docker
○ Installing software can be slow on RPi
○ Helps prepare an image on your PC before writing it to a SD card
○ GitHub - rtisma/raspberry-pi-qemu-docker-bootloader
● pi-gen
○ Tool used to create the raspberrypi.org Raspbian images
○ https://github.com/RPi-Distro/pi-gen
○ Can be used to create customized images
53. Demo 1: Wireless Relay - Description
● Objective
○ Use a RPi and a network connection to turn a
household light bulb on and off.
● Materials
○ 120V Relay board that can be controlled with 3.3V
○ Internet connection
○ RPi 3
○ 120V light bulb
○ 14 gauge wire
54. Demo 1: Wireless Relay - Design
● HW Design
○ NO (Normally Open) relay is:
■ OPEN with a HIGH
■ CLOSED with a LOW
● SW Design
○ Simple PHP script controlling gpio
(WiringPi) cli
○ Served using an Apache2 web server
○ Tunnelled using Ngrok for the PiRelay
android app
56. Demo 2: Slacking off with your PiBot
● Objective
○ Build on previous demo
○ Use slack to interface with a RPi to extract sensor
values and turn on relays (lightbulb)
● Materials
○ 120V Relay board that can be controlled with 3.3V
○ Internet connection
○ RPi 3
○ SenseHat
○ 120V light bulb
○ 14 gauge wire
57. Demo 2: Slacking off with your PiBot
● HW Design
○ NO (Normally Open) relay is:
■ OPEN with a HIGH
■ CLOSED with a LOW
● SW Design
○ Register a slack bot
○ Poll messages directed at the slack bot
○ Parse and interpret each message
○ Execute each command
○ Use pigpio for interfacing with lightbulb
○ Use the Sense HAT python module to
reading humidity data