r22 Iot Unit 3 Notes
r22 Iot Unit 3 Notes
r22 Iot Unit 3 Notes
Introduction to raspberry pi
What is Raspberry Pi?
The Raspberry Pi is a device: which is fully functional computer in a tiny and low-cost package.
The Raspberry Pi is known as a single-board computer, which means exactly what it sounds
like: it’s a computer, just like a desktop, laptop, or smartphone, but built on a single printed
circuit board. Like most single-board computers, the Raspberry Pi is small – roughly the same
footprint as a credit card – but that doesn’t mean it’s not powerful: a Raspberry Pi can do
anything a bigger and more power-hungry computer can do, though not necessarily as quickly.
in simply Raspberry PI is a:
• Computer in your palm.
• Single-board computer.
• Low cost.
• Easy to access.
Fig 1: Raspberry PI
Specifications:
The GPIO pins on the Raspberry Pi are divided into the following groups:
Power: Pins that are labelled 5.0v supply 5 volts of power and those labelled 3V3 supply 3.3
volts of power. There are two 5V pins and two 3V3 pins.
GND: These are the ground pins. There are eight ground pins.
Input/Output pins: These are the pins labelled with the # sign, for example, #17, #27, #22,
etc. These pins can be used for input or output.
UART: The Universal Asynchronous Receiver/Transmitter allows your Raspberry Pi to be
connected to serial peripherals. The UART pins are labelled TXD and RXD.
SPI: The Serial Peripheral Interface is a synchronous serial communication interface
specification used for short distance communication, primarily in embedded systems. The SPI
pins are labelled MOSI, MISO, SCLK, CE0, and CE1.
• MISO (Master In Slave Out): Master line for sending data to the master.
• MOSI ( Master Out Slave In): Slave line for sending data to the Peripherals.
• SCK ( Serial Clock): Clock generated by master to synchronize data transmission.
• CE0 ( chip Enable 0): to enable or disable devices.
• CE1 ( chip Enable 1): to enable or disable devices.
ID EEPROM: Electrically Erasable Programmable Read-Only Memory is a user-modifiable
read-only memory that can be erased and written to repeatedly through the application of higher
than normal electrical voltage. The two EEPROM pins on the Raspberry Pi (EED and EEC)
are also secondary I2C ports that primarily facilitate the identification of Pi Plates (e.g.,
Raspberry Pi Shields/Add-On Boards) that are directly attached to the Raspberry Pi.SPI (Serial
peripheral interface)
I2C (Inter Integrated chip)
The I2C interface pins on raspberry pi allow you to connect hardware modules. I2C interface
allow synchronous data transfer with two pins -SDA (data line) and SCL (clock line).
Serial
The serial interface on Raspberry Pi has receive (Rx) and Transmit (Tx) pins for
communication with serial peripherals.
Basic Architecture
Raspberry Pi GPIO
• Act as both digital output and digital input.
• Output: turn a GPIO pin high or low.
• Input: detect a GPIO pin high or low.
Operating System
Official Supported OS:
• Raspbian
• NOOBS
Some of the third-party OS:
• UBUNTU mate
• Snappy Ubuntu core
• Windows 10 core
• Pinet
• Risc OS
Raspberry Pi Setup
Download Raspbian:
• Download latest Raspbian-image from raspberry pi official site:
https://www.raspberrypi.org/downloads/
• Unzip the file and end up with an .imgfile
Raspberry Pi OS Setup
Write Raspbian in SD card:
• Install “Win32 Disk Imager” software in windows machine.
• Run Win32 Disk Imager
• Plug SD card into your PC
• Select the “Device”
• Browse the “Image File” (Raspbian image)
• Write
Popular Applications
• Media streamer
• Home automation
• Controlling BOT
• VPN
• Light weight web server for IOT
• Tablet computer
Program:
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function from the time module
GPIO.setmode(GPIO.BCM/BOARD) # Use physical pin numbering
GPIO.setup(18, GPIO.OUT) # Set pin 18 to be an output pin
while True: # Run forever
GPIO.output(18, GPIO.HIGH) # Turn on
sleep(1) # Sleep for 1 second
GPIO.output(18, GPIO.LOW) # Turn off
sleep(1) # Sleep for 1 second
Connection: Fan
Connect the Li-po battery in series with the fan
NO terminal of the relay -> positive terminal of the Fan.
Common terminal of the relay -> Positive terminal of the battery
Negative terminal of the battery -> Negative terminal of the fan.
Run the existing code. The fan should operate when the surrounding temperature is greater than
the threshold value in the sketch
Result
The fan is switched on whenever the temperature is above the threshold value set in the code.
Notice the relay indicator turned on.