Building IoT applications
using Raspberry Pi
                       DR. SHWETA SHARMA
                      ASSISTANT PROFESSOR
            DEPT. OF COMPUTER ENGINEERING
                         NIT KURUKSHETRA
BASICS
   DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   2
Cache
        DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   3
       Locality of Reference
 Principle of Locality
 Tendency of a processor to access the same set of memory locations again and again
 Tendency of the computer program to access instructions whose addresses are near one
  another
                              DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   4
       Locality of Reference
 Instruction or data near to the current
  memory location that is being fetched,
  may be needed soon in the near future
 An Array is cache friendly while linked
  list is not
                              DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   5
         Levels of Cache memory
 Data flows from the RAM to the L3 cache,
  then the L2, and finally, L1
 When the processor is looking for data to
  carry out an operation, it first tries to find it
  in the L1 cache
 It then proceeds to find it in L2 and then L3.
                                     DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   6
       Shared Cache
 Shared among multiple processing units within a single computer system
 Serving as a common source that can be accessed by multiple processes and machines
 Instead of each core having its own private cache, multiple cores in a multi-core processor
share a common cache
 Lead to efficient memory utilization and improved overall system performance
                               DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   7
      Shared Cache
 Suppose you have a quad-core processor with a shared cache
 Cache is shared among all four cores
 When Core 1 accesses a specific memory location, the data from that location is fetched
 into the shared cache
 If Core 2 needs to access the same memory location shortly after, it can benefit from the
 fact that the data is already present in the shared cache
 This reduces the time it takes for Core 2 to retrieve the data compared to accessing it
 directly from main memory
                               DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   8
      Shared Cache
 Shared cache is beneficial for scenarios where multiple cores need to access the same data,
such as in parallel processing tasks
 It helps reduce cache misses and enhances overall system performance by allowing cores to
share cached data
                                DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   9
Raspberry Pi
      DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   10
          Introduction to Raspberry Pi
 Developed by Raspberry Pi Foundation
 Launched in 2012
 The name Raspberry Pi was chosen with
  “Raspberry” as an ode to tradition of
  naming early computer companies after
  fruit
 Here, "Pi" is for Python Programming
  Language
                             DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   11
       Introduction to Raspberry Pi
 A small single board computer
 Microprocessor
 By connecting peripherals like Keyboard, mouse, display to the Raspberry Pi, it will act as a
  mini personal computer
 Used for real time Image/Video Processing, IoT based applications and Robotics
  applications
 Slower than laptop or desktop
 Applications: Gaming devices, fitness gadgets, weather stations
                                DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   12
DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   13
Raspberry Pi Hardware
           DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   14
       Raspberry Pi Hardware
 CPU: Raspberry Pi 3 uses Broadcom BCM2837 SOC 64-bit quad-core ARM Cortex A53
  (ARMv8 CPU) with 512KB shared L2 cache
 Memory: Provided with 1 GB of RAM
 Wi-Fi Support: 802.11n Wireless LAN
 Bluetooth: Supports Bluetooth 4.1 Bluetooth Low Energy (BLE)
 USB Ports: 4-USB ports allow attaching 4 different USB devices- keyboard, mouse, etc.
 Ethernet Port: Standard Ethernet port to quickly setup and access internet. Useful to setup
  raspberry pi for the first time without a monitor
                               DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   15
      Raspberry Pi Hardware
 GPIO Pins: Raspberry Pi 3 supports 40 GPIO Pins General Purpose Input Output. These
  digital input/output pins can be used to drive LED, Switches, and Sensors etc.
 Full HDMI Port: Support HDMI port (High-Definition Multimedia Interface) which can be
  used to quickly connect raspberry pi to HDMI Monitor. With HDMI Cable and Monitor we
  can add Screen to Raspberry Pi
 Micro SD card slot: The Micro SD Card will hold the operating system which will boot while
  we power on Raspberry Pi 3
                               DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   16
       Raspberry Pi Hardware
 Audio/Video: Combined 3.5mm audio jack and composite video
 Display interface (DSI): enable us to interface Display Module
 Camera interface (CSI): enable us to interface Camera Module
 Graphics Support: Video Core IV 3D graphics core for advance graphics capabilities.
                               DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   17
      Raspberry Pi vs. Arduino
 Raspberry Pi is a single board computer with Microprocessor whereas Arduino is
  considered as Microcontroller unit
 The Raspberry Pi can run an OS (Linux Distribution) and also consumes more power. Since
  Arduino is microcontroller device it has no operating system and can only run a single
  program
                              DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   18
       OS for Raspberry Pi
 Raspberry Pi Foundation officially provides Debian based Raspbian OS
 Provides NOOBS OS for Raspberry Pi
 NOOBS: New Out Of the Box Software and is an easy to use bootloader for the Raspberry
  Pi
 Using NOOBS, users can easily install numerous operating systems to Raspberry Pi
 Users can even use NOOBS to install multiple operating systems to Raspberry Pi and to also
  boot from them
                               DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   19
       OS for Raspberry Pi
 Users can install several Third-Party versions of OS like Ubuntu, Archlinux, RISC OS,
  Windows 10 IOT Core, etc.
 Raspbian OS is official Operating System available for free to use
 This OS is efficiently optimized to use with Raspberry Pi
                                DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   20
         OS for Raspberry Pi
 Raspbian have GUI which includes tools for Browsing, Python programming, office, games,
  etc.
 SD card (minimum 8 GB recommended) to store the OS (operating System)
 Provides access to the on-chip hardware i.e. GPIOs for developing an application. By
  accessing GPIO, users can connect devices like LED, motors, sensors, etc. and can control
  them too
                              DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   21
      Versions of Raspberry pi models
1. Raspberry Pi 1 Model A
2. Raspberry Pi 1 Model A+
3. Raspberry Pi 1 Model B
4. Raspberry Pi 1 Model B+
5. Raspberry Pi 2 Model B
6. Raspberry Pi 3 Model B
7. Raspberry Pi Zero
                             DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   22
       Versions of Raspberry pi models
                                                      Raspberry Pi 2                           Raspberry Pi 3
    Features       Raspberry Pi Model B+                                                                          Raspberry Pi zero
                                                        Model B                                  Model B
System-on-a-Chip         BCM2835                        BCM2836                                  BCM2837             BCM2835
      CPU                 ARM11                      Quad Cortex A7                         Quad Cortex A53           ARM11
Operating Freq.          700 MHz                           900 MHz                                      1.2 GHz        1 GHz
     RAM              512 MB SDRAM                   1 GB SDRAM        1 GB SDRAM         512 MB SDRAM
                                                  250MHz Videocore
      GPU          250 MHz Videocore IV                            400 MHz Videocore IV 250MHz Videocore IV
                                                          IV
    Storage              micro-SD                      Micro-SD          micro-SD            micro-SD
    Ethernet               Yes                           Yes               Yes                  No
    Wireless        WiFi and Bluetooth                          No                                        No             No
                                    DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA                         23
        Connect Raspberry Pi
 Check the slot on the underside
  of your Raspberry Pi to see
  whether an SD card is inside
 If no SD card is there, then
  insert an SD card with Raspbian
  installed (via NOOBS).
                                 DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   24
         Connect Raspberry Pi
 Install Rasperry Pi OS on your SD card with the Raspberry Pi Imager (if not pre-installed)
 https://www.raspberrypi.com/software/
                                  DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   25
        Connect Raspberry Pi
 Find the USB connector end of
  your mouse’s cable
 Connect the mouse to a USB
  port on Raspberry Pi (it doesn’t
  matter which port you use)
                                DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   26
       Connect Raspberry Pi
 Connect the keyboard in the
  same way
                           DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   27
        Connect Raspberry Pi
 Connect the screen to the single
  HDMI port (Raspberry 3)
                                DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   28
        Connect Raspberry Pi
 Connect the Pi to the Internet via Ethernet
 Use an Ethernet cable to connect the
  Ethernet port on the Raspberry Pi
 Or use wireless connectivity
                                 DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   29
        Connect Raspberry Pi
 If the screen has speakers, then Raspberry Pi
  can play sound through these
 Or connect headphones or speakers to the
  audio port
                                 DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   30
        Connect Raspberry Pi
 Plug the power supply into a socke
 Connect it to Raspberry Pi’s USB power port
 Users will see a red light on Raspberry Pi and
  raspberries on the monitor.
 Raspberry Pi then boots up into a graphical
  desktop
                                 DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   31
Communicate Raspberry Pi
           DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   32
     Programming on the Raspberry Pi
LED Blinking
                DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   33
         Programming on the Raspberry Pi
touch led.py
from gpiozero import LED
from signal import pause
led = LED(4)               #Create an instance of LED called led. Set the GPIO pin to 4
led.blink()                #Call the .blink() method on led
pause()                    #add a call to pause() to make sure the program doesn’t exit:
python3 led.py
                               DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   34
Thank You!
             DR. SHWETA SHARMA, DEPT. OF COMPUTER ENGINEERING, NIT KURUKSHETRA   35