Unit IV
IoT Physical Devices & Endpoints
Outline
• Basic building blocks of an IoT Device
• Exemplary Device: Raspberry Pi
• Raspberry Pi interfaces
• Programming Raspberry Pi with Python
• Other IoT devices
What is an IoT Device
• A "Thing" in Internet of Things (IoT) can be any object that has a
unique identifier and which can send/receive data (including user
data) over a network (e.g., smart phone, smart TV, computer,
refrigerator, car, etc. ).
• IoT devices are connected to the Internet and send information
about themselves or about their surroundings (e.g. information
sensed by the connected sensors) over a network (to other devices or
servers/storage) or allow actuation upon the physical
entities/environment around them remotely.
IoT Device Examples
• A home automation device that allows remotely monitoring the
status of appliances and controlling the appliances.
• An industrial machine which sends information abouts its operation
and health monitoring data to a server.
• A car which sends information about its location to a cloud-based
service.
• A wireless-enabled wearable device that measures data about a
person such as the number of steps walked and sends the data to a
cloud-based service.
Basic building blocks of an IoT Device
• Sensing
• Sensors can be either on-board the IoT device or attached to the device.
• Actuation
• IoT devices can have various types of actuators attached that allow taking
• actions upon the physical entities in the vicinity of the device.
• Communication
• Communication modules are responsible for sending collected data to other
devices or cloud-based servers/storage and receiving data from other devices
and commands from remote applications.
• Analysis & Processing
• Analysis and processing modules are responsible for making sense of the
collected data.
Block diagram of an IoT Device
Exemplary Device: Raspberry Pi
• Raspberry Pi is a low-cost mini-computer with the physical size of a
credit card.
• Raspberry Pi runs various flavors of Linux and can perform almost all
tasks that a normal desktop computer can do.
• Raspberry Pi also allows interfacing sensors and actuators through
the general purpose I/O pins.
• Since Raspberry Pi runs Linux operating system, it supports Python
"out of the box".
Exemplary Device: Raspberry Pi
• Raspberry Pi is a low-cost mini-computer with the physical size of a
credit card.
• Raspberry Pi runs various flavors of Linux and can perform almost all
tasks that a normal desktop computer can do.
• Raspberry Pi also allows interfacing sensors and actuators through
the general purpose I/O pins.
• Since Raspberry Pi runs Linux operating system, it supports Python
"out of the box".
Raspberry Pi
Linux on Raspberry Pi
• Raspbian
• Raspbian Linux is a Debian Wheezy port optimized for Raspberry Pi.
• Arch
• Arch is an Arch Linux port for AMD devices.
• Pidora
• Pidora Linux is a Fedora Linux optimized for Raspberry Pi.
• RaspBMC
• RaspBMC is an XBMC media-center distribution for Raspberry Pi.
• OpenELEC
• OpenELEC is a fast and user-friendly XBMC media-center distribution.
• RISC OS
• RISC OS is a very fast and compact operating system.
Raspberry Pi GPIO
Raspberry Pi GPIO
When using the RPi.GPIO library in Python we have to call
import RPi.GPIO as GPIO
and then
GPIO.setmode(GPIO.BOARD)
or
GPIO.setmode(GPIO.BCM)
What is the difference between these two options?
Raspberry Pi GPIO
• The GPIO.BOARD option specifies that you are referring to the pins by the number
of the pin on the plug - i.e the numbers printed on the board (e.g. P1) and in the
middle of the diagrams below.
• The GPIO.BCM option means that you are referring to the pins by the "Broadcom
SOC channel" number, these are the numbers after "GPIO" in the green rectangles
around the outside of the below diagrams
Raspberry Pi GPIO
• Unfortunately the BCM numbers changed between versions of the Pi1 Model B, and
you'll need to work out which one. So it may be safer to use the BOARD numbers if you
are going to use more than one Raspberry Pi in a project.
• The Model B+ uses the same numbering as the Model B r2.0, and adds new pins (board
numbers 27-40).
• The Raspberry Pi Zero, Pi 2B, Pi 3B, and Pi 4B use the same numbering as the B+.
Raspberry Pi GPIO
Raspberry Pi GPIO
Raspberry Pi GPIO
Raspberry Pi GPIO
• Identification of the pin numberings via Linux command
• There is a Linux command to find out which name is for which GPIO pin. So in
that case, we do not have to worry about a tutorial or a cheat sheet to have by
our side to check out the pin numberings of the Raspberry Pi all the time.
• Type the following command in the terminal,
pinout
Raspberry Pi GPIO
Raspberry Pi Interfaces
Raspberry Pi Interfaces
Serial
• The serial interface on Raspberry Pi has receive (Rx) and transmit (Tx) pins
for communication with serial peripherals.
• GPIO 14 – UART Tx
• GPIO 15 – UART Rx
Raspberry Pi Interfaces
Serial Interface- UART
• UART (Universal Asynchronous Receiver/Transmitter) is a serial
communication protocol in which data is transferred serially bit by bit.
• Asynchronous serial communication is widely used for byte oriented
transmission.
• In asynchronous serial communication, a byte of data is transferred at a
time.
Frame Structure of UART
Raspberry Pi UART
Raspberry Pi Interfaces
SPI
• Serial Peripheral Interface (SPI) is a synchronous serial data protocol used
for communicating with one or more peripheral devices.
• In an SPI connection, there is one master device and one or more
peripheral devices.
Raspberry Pi Interfaces
• There are five pins on Raspberry Pi for SPI interface.
• MISO (Master In Slave Out) : Master Line for sending data to peripherals (GPIO 9).
• MOSI (Master Out Slave In) : Slave line for sending data to master (GPIO 10).
• SCK (Serial Clock) : Clock generated by master to synchronize data transmission (GPIO
11).
• CEO (Chip Enable 0) : To enable or disable devices (GPIO 8).
• CE1 (Chip Enable 1) : To enable or disable devices (GPIO 7).
Raspberry Pi Interfaces
I2C (Inter Integrated Circuit)
• It is a synchronous serial protocol that communicates data between two
devices
• It is a master slave protocol which may have one master or many master
and many slaves where as SPI has only one master
• It is generally used for communication over short distance.
Raspberry Pi Interfaces
I2C (Inter Integrated Circuit)
• The I2C interface pins on Raspberry Pi allows to connect hardware modules.
• I2C interface allows synchronous data transfer with just two pins –
SDA (I2C data line) GPIO 2 and SCL (I2C clock line) GPIO 3.
• It is used in many applications like reading RTC (Real Time Clock), assessing external
EEPROM memory and it is also used in sensor modules like gyro meter and
magnetometer.
Programming Raspberry Pi with Python
• Raspberry Pi runs Linux and supports Python Out of Box software.
• Therefore, we can run any python program that runs on a normal computer.
• GPIO pins provides capability on Raspberry Pi that makes useful devices for IoT.
• A wide variety of sensors and actuators can be interfaced with raspberry pi using the
GPIO pins and the SPI,I2C and serial interfaces.
• Input from the sensors connected to raspberry pi can be processed and various actions
can be taken, sending data to a server, sending an email, triggering a relay switch.
Raspberry Pi Example:
Interfacing LED and switch with Raspberry Pi
• In this example LED is connected to GPIO pin 18 and switch is connected to pin 25.
• In the infinite while loop the value of pin 25 is checked and the state of LED is toggled if
the switch is pressed.
• This example shows how to get input from GPIO pins and process the input and takes
action.
• The action in this example is toggling the state of an LED.
Raspberry Pi Example:
Interfacing LED and switch with Raspberry Pi
from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
#Switch Pin
GPIO.setup(25, GPIO.IN)
#LED Pin
GPIO.setup(18, GPIO.OUT)
state=false
def toggleLED(pin):
state = not state
GPIO.output(pin, state)
while True:
try:
if (GPIO.input(25) == True):
toggleLED(pin)
sleep(.01)
except KeyboardInterrupt:
exit()
Python Program for Sending an Email on Switch Press
Python Program for Sending an Email on Switch Press
Python Program for Sending an Email on Switch Press
Interfacing Light Sensor (LDR) with RPi
• Connect one side of LDR to 3.3V and other side to a1μF capacitor and also to a
GPIO pin (pin 18 in this example).
• An LED is connected to pin 18 which is controlled based on the light-level sensed.
• The read LDR() function returns a count which is proportional to the light level.
• In this function the LDR pin is set to output and low and then to input.
Interfacing Light Sensor (LDR) with RPi
• At this point the capacitor starts charging through the resistor (and a counter is
started) until the input pin reads high (this happens when capacitor voltage
becomes greater than 1.4V).
• The counter is stopped when the input reads high.
• The final count is proportional to the light level as greater the amount of light,
smaller is the LDR resistance and greater is the time taken to charge the
capacitor.
Interfacing Light Sensor (LDR) with RPi
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
ldr_threshold = 1000
LDR_PIN = 18
LIGHT_PIN = 25
def readLDR(PIN):
reading = 0
GPIO.setup(LIGHT_PIN, GPIO.OUT)
GPIO.output(PIN, false)
time.sleep(0.1)
GPIO.setup(PIN, GPIO.IN)
while (GPIO.input (PIN) ==Flase):
reading=reading+1
return reading
def switchOnLight(PIN):
GPIO.setup(PIN, GPIO.OUT)
GPIO.output(PIN, True)
def switchOffLight(PIN):
GPIO.setup(PIN, GPIO.OUT)
GPIO.output(PIN, False)
while True:
ldr_reading = readLDR(LDR_PIN)
if ldr_reading < ldr_threshold:
switchOnLight (LIGHT_PIN)
else:
switchOffLight(LIGHT_PIN)
time.sleep(1)
Interfacing Light Sensor (LDR) with RPi
Interfacing Light Sensor (LDR) with RPi
Other Devices
• pcDuino
• BeagleBone Black
• Cubieboard
Comparison of Single Board Mini Computers

More Related Content

PPTX
Physical design of io t
PPTX
Chapter-1 - Internet of Things: A Hands-on Approach
PDF
Chapter 7
PDF
Raspberry Pi
PDF
IoT Physical Servers and Cloud Offerings.pdf
PPTX
1. Introduction to IoT
PPTX
Ppt 3 - IOT logic design
PPTX
Python for IoT
Physical design of io t
Chapter-1 - Internet of Things: A Hands-on Approach
Chapter 7
Raspberry Pi
IoT Physical Servers and Cloud Offerings.pdf
1. Introduction to IoT
Ppt 3 - IOT logic design
Python for IoT

What's hot (20)

PDF
Chapter 5 IoT Design methodologies
PPTX
IOT Platform Design Methodology
PPTX
M2M technology in IOT
PPT
PPTX
IOT15_Unit6.pptx
PPTX
security and privacy-Internet of things
PPTX
Io t system management with
PDF
iot enabling technologies for IOT subject
PPTX
IOT and Characteristics of IOT
PDF
IoT Communication Protocols
PPTX
Data enrichment
PPTX
IOT DATA MANAGEMENT AND COMPUTE STACK.pptx
PPTX
Domain specific IoT
PDF
IOT and its communication models and protocols.pdf
PPTX
IOT PROTOCOLS.pptx
PPTX
IoT Levels and Deployment Templates
PDF
UNIT-5 IoT Reference Architecture.pdf
PPTX
Security services and mechanisms
PPTX
Web servers for the Internet of Things
PPTX
IOT System Management with NETCONF-YANG.pptx
Chapter 5 IoT Design methodologies
IOT Platform Design Methodology
M2M technology in IOT
IOT15_Unit6.pptx
security and privacy-Internet of things
Io t system management with
iot enabling technologies for IOT subject
IOT and Characteristics of IOT
IoT Communication Protocols
Data enrichment
IOT DATA MANAGEMENT AND COMPUTE STACK.pptx
Domain specific IoT
IOT and its communication models and protocols.pdf
IOT PROTOCOLS.pptx
IoT Levels and Deployment Templates
UNIT-5 IoT Reference Architecture.pdf
Security services and mechanisms
Web servers for the Internet of Things
IOT System Management with NETCONF-YANG.pptx
Ad

Similar to IoT Physical Devices and End Points.pdf (20)

PPT
IOT UNIT 4 KMIT standard.ppt n nnnnnnnnn
PPTX
M.Tech Internet of Things Unit - III.pptx
PPTX
IoT Unit-gsgsgsgasgGwaczxvxbxbbhhhh2.pptx
PPTX
Raspberry Pi Introductory Lecture
PPTX
IoT Heaps 5
PPTX
IOT notes ....,.........
PPTX
Unit 3 Complete.pptx
PDF
Baking a Raspberry PI with Chef Rob
PPTX
Raspberry pi
PDF
IRJET- IoT based Advanced Security Intelligence System using Python
PPTX
Raspberry Pi ppt.pptx
PPTX
Raspberry Pi ppt.pptx
PPTX
Raspberry pi led blink
PPTX
Building the Internet of Things with Raspberry Pi
PDF
Raspberry pi: Referencia de hardware de raspberry pi por warren gay
PPTX
IOT Experiment-2.pptx --- Hands on Approach & Easy to learn IOT Basics...
PPTX
IoT for data science Module 5 - Raspberry Pi.pptx
PDF
Embedded Systems: Lecture 9: The Pi Control ARM
PDF
RaspberryPi_Workshop and Programming with python.
PPTX
Using arduino and raspberry pi for internet of things
IOT UNIT 4 KMIT standard.ppt n nnnnnnnnn
M.Tech Internet of Things Unit - III.pptx
IoT Unit-gsgsgsgasgGwaczxvxbxbbhhhh2.pptx
Raspberry Pi Introductory Lecture
IoT Heaps 5
IOT notes ....,.........
Unit 3 Complete.pptx
Baking a Raspberry PI with Chef Rob
Raspberry pi
IRJET- IoT based Advanced Security Intelligence System using Python
Raspberry Pi ppt.pptx
Raspberry Pi ppt.pptx
Raspberry pi led blink
Building the Internet of Things with Raspberry Pi
Raspberry pi: Referencia de hardware de raspberry pi por warren gay
IOT Experiment-2.pptx --- Hands on Approach & Easy to learn IOT Basics...
IoT for data science Module 5 - Raspberry Pi.pptx
Embedded Systems: Lecture 9: The Pi Control ARM
RaspberryPi_Workshop and Programming with python.
Using arduino and raspberry pi for internet of things
Ad

More from GVNSK Sravya (12)

PDF
Python.pdf
PDF
IoT & M2M.pdf
PDF
Introduction to Internet of Things.pdf
PDF
Unit 4 DGPS
PDF
Unit II GPS Signal Characteristics
PDF
Unit1 GPS Introduction
PDF
Unit III GPS Receivers and Errors
PDF
EMI Unit IV
PDF
EMI Unit 5 Bridges and Measurement of Physical Parameters
PDF
EMI Unit 3 CRO
PDF
EMI Unit II
PDF
Emi Unit 1
Python.pdf
IoT & M2M.pdf
Introduction to Internet of Things.pdf
Unit 4 DGPS
Unit II GPS Signal Characteristics
Unit1 GPS Introduction
Unit III GPS Receivers and Errors
EMI Unit IV
EMI Unit 5 Bridges and Measurement of Physical Parameters
EMI Unit 3 CRO
EMI Unit II
Emi Unit 1

Recently uploaded (20)

PPTX
Soft Skills Unit 2 Listening Speaking Reading Writing.pptx
PDF
ST MNCWANGO P2 WIL (MEPR302) FINAL REPORT.pdf
PPT
Unit - I.lathemachnespct=ificationsand ppt
PDF
Artificial Intelligence_ Basics .Artificial Intelligence_ Basics .
PDF
Mechanics of materials week 2 rajeshwari
PPTX
SE unit 1.pptx by d.y.p.akurdi aaaaaaaaaaaa
PPTX
22ME926Introduction to Business Intelligence and Analytics, Advanced Integrat...
PPTX
Research Writing, Mechanical Engineering
PDF
B461227.pdf American Journal of Multidisciplinary Research and Review
PDF
IAE-V2500 Engine Airbus Family A319/320
PDF
BBC NW_Tech Facilities_30 Odd Yrs Ago [J].pdf
PDF
VTU IOT LAB MANUAL (BCS701) Computer science and Engineering
PPTX
Unit IImachinemachinetoolopeartions.pptx
PDF
Performance, energy consumption and costs: a comparative analysis of automati...
PPTX
SC Robotics Team Safety Training Presentation
PPTX
1. Effective HSEW Induction Training - EMCO 2024, O&M.pptx
PDF
V2500 Owner and Operatore Guide for Airbus
PDF
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
PPTX
ARCHITECTURE AND PROGRAMMING OF EMBEDDED SYSTEMS
PPTX
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
Soft Skills Unit 2 Listening Speaking Reading Writing.pptx
ST MNCWANGO P2 WIL (MEPR302) FINAL REPORT.pdf
Unit - I.lathemachnespct=ificationsand ppt
Artificial Intelligence_ Basics .Artificial Intelligence_ Basics .
Mechanics of materials week 2 rajeshwari
SE unit 1.pptx by d.y.p.akurdi aaaaaaaaaaaa
22ME926Introduction to Business Intelligence and Analytics, Advanced Integrat...
Research Writing, Mechanical Engineering
B461227.pdf American Journal of Multidisciplinary Research and Review
IAE-V2500 Engine Airbus Family A319/320
BBC NW_Tech Facilities_30 Odd Yrs Ago [J].pdf
VTU IOT LAB MANUAL (BCS701) Computer science and Engineering
Unit IImachinemachinetoolopeartions.pptx
Performance, energy consumption and costs: a comparative analysis of automati...
SC Robotics Team Safety Training Presentation
1. Effective HSEW Induction Training - EMCO 2024, O&M.pptx
V2500 Owner and Operatore Guide for Airbus
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
ARCHITECTURE AND PROGRAMMING OF EMBEDDED SYSTEMS
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS

IoT Physical Devices and End Points.pdf

  • 1. Unit IV IoT Physical Devices & Endpoints
  • 2. Outline • Basic building blocks of an IoT Device • Exemplary Device: Raspberry Pi • Raspberry Pi interfaces • Programming Raspberry Pi with Python • Other IoT devices
  • 3. What is an IoT Device • A "Thing" in Internet of Things (IoT) can be any object that has a unique identifier and which can send/receive data (including user data) over a network (e.g., smart phone, smart TV, computer, refrigerator, car, etc. ). • IoT devices are connected to the Internet and send information about themselves or about their surroundings (e.g. information sensed by the connected sensors) over a network (to other devices or servers/storage) or allow actuation upon the physical entities/environment around them remotely.
  • 4. IoT Device Examples • A home automation device that allows remotely monitoring the status of appliances and controlling the appliances. • An industrial machine which sends information abouts its operation and health monitoring data to a server. • A car which sends information about its location to a cloud-based service. • A wireless-enabled wearable device that measures data about a person such as the number of steps walked and sends the data to a cloud-based service.
  • 5. Basic building blocks of an IoT Device • Sensing • Sensors can be either on-board the IoT device or attached to the device. • Actuation • IoT devices can have various types of actuators attached that allow taking • actions upon the physical entities in the vicinity of the device. • Communication • Communication modules are responsible for sending collected data to other devices or cloud-based servers/storage and receiving data from other devices and commands from remote applications. • Analysis & Processing • Analysis and processing modules are responsible for making sense of the collected data.
  • 6. Block diagram of an IoT Device
  • 7. Exemplary Device: Raspberry Pi • Raspberry Pi is a low-cost mini-computer with the physical size of a credit card. • Raspberry Pi runs various flavors of Linux and can perform almost all tasks that a normal desktop computer can do. • Raspberry Pi also allows interfacing sensors and actuators through the general purpose I/O pins. • Since Raspberry Pi runs Linux operating system, it supports Python "out of the box".
  • 8. Exemplary Device: Raspberry Pi • Raspberry Pi is a low-cost mini-computer with the physical size of a credit card. • Raspberry Pi runs various flavors of Linux and can perform almost all tasks that a normal desktop computer can do. • Raspberry Pi also allows interfacing sensors and actuators through the general purpose I/O pins. • Since Raspberry Pi runs Linux operating system, it supports Python "out of the box".
  • 10. Linux on Raspberry Pi • Raspbian • Raspbian Linux is a Debian Wheezy port optimized for Raspberry Pi. • Arch • Arch is an Arch Linux port for AMD devices. • Pidora • Pidora Linux is a Fedora Linux optimized for Raspberry Pi. • RaspBMC • RaspBMC is an XBMC media-center distribution for Raspberry Pi. • OpenELEC • OpenELEC is a fast and user-friendly XBMC media-center distribution. • RISC OS • RISC OS is a very fast and compact operating system.
  • 12. Raspberry Pi GPIO When using the RPi.GPIO library in Python we have to call import RPi.GPIO as GPIO and then GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM) What is the difference between these two options?
  • 13. Raspberry Pi GPIO • The GPIO.BOARD option specifies that you are referring to the pins by the number of the pin on the plug - i.e the numbers printed on the board (e.g. P1) and in the middle of the diagrams below. • The GPIO.BCM option means that you are referring to the pins by the "Broadcom SOC channel" number, these are the numbers after "GPIO" in the green rectangles around the outside of the below diagrams
  • 14. Raspberry Pi GPIO • Unfortunately the BCM numbers changed between versions of the Pi1 Model B, and you'll need to work out which one. So it may be safer to use the BOARD numbers if you are going to use more than one Raspberry Pi in a project. • The Model B+ uses the same numbering as the Model B r2.0, and adds new pins (board numbers 27-40). • The Raspberry Pi Zero, Pi 2B, Pi 3B, and Pi 4B use the same numbering as the B+.
  • 18. Raspberry Pi GPIO • Identification of the pin numberings via Linux command • There is a Linux command to find out which name is for which GPIO pin. So in that case, we do not have to worry about a tutorial or a cheat sheet to have by our side to check out the pin numberings of the Raspberry Pi all the time. • Type the following command in the terminal, pinout
  • 21. Raspberry Pi Interfaces Serial • The serial interface on Raspberry Pi has receive (Rx) and transmit (Tx) pins for communication with serial peripherals. • GPIO 14 – UART Tx • GPIO 15 – UART Rx
  • 22. Raspberry Pi Interfaces Serial Interface- UART • UART (Universal Asynchronous Receiver/Transmitter) is a serial communication protocol in which data is transferred serially bit by bit. • Asynchronous serial communication is widely used for byte oriented transmission. • In asynchronous serial communication, a byte of data is transferred at a time.
  • 25. Raspberry Pi Interfaces SPI • Serial Peripheral Interface (SPI) is a synchronous serial data protocol used for communicating with one or more peripheral devices. • In an SPI connection, there is one master device and one or more peripheral devices.
  • 26. Raspberry Pi Interfaces • There are five pins on Raspberry Pi for SPI interface. • MISO (Master In Slave Out) : Master Line for sending data to peripherals (GPIO 9). • MOSI (Master Out Slave In) : Slave line for sending data to master (GPIO 10). • SCK (Serial Clock) : Clock generated by master to synchronize data transmission (GPIO 11). • CEO (Chip Enable 0) : To enable or disable devices (GPIO 8). • CE1 (Chip Enable 1) : To enable or disable devices (GPIO 7).
  • 27. Raspberry Pi Interfaces I2C (Inter Integrated Circuit) • It is a synchronous serial protocol that communicates data between two devices • It is a master slave protocol which may have one master or many master and many slaves where as SPI has only one master • It is generally used for communication over short distance.
  • 28. Raspberry Pi Interfaces I2C (Inter Integrated Circuit) • The I2C interface pins on Raspberry Pi allows to connect hardware modules. • I2C interface allows synchronous data transfer with just two pins – SDA (I2C data line) GPIO 2 and SCL (I2C clock line) GPIO 3. • It is used in many applications like reading RTC (Real Time Clock), assessing external EEPROM memory and it is also used in sensor modules like gyro meter and magnetometer.
  • 29. Programming Raspberry Pi with Python • Raspberry Pi runs Linux and supports Python Out of Box software. • Therefore, we can run any python program that runs on a normal computer. • GPIO pins provides capability on Raspberry Pi that makes useful devices for IoT. • A wide variety of sensors and actuators can be interfaced with raspberry pi using the GPIO pins and the SPI,I2C and serial interfaces. • Input from the sensors connected to raspberry pi can be processed and various actions can be taken, sending data to a server, sending an email, triggering a relay switch.
  • 30. Raspberry Pi Example: Interfacing LED and switch with Raspberry Pi • In this example LED is connected to GPIO pin 18 and switch is connected to pin 25. • In the infinite while loop the value of pin 25 is checked and the state of LED is toggled if the switch is pressed. • This example shows how to get input from GPIO pins and process the input and takes action. • The action in this example is toggling the state of an LED.
  • 31. Raspberry Pi Example: Interfacing LED and switch with Raspberry Pi from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) #Switch Pin GPIO.setup(25, GPIO.IN) #LED Pin GPIO.setup(18, GPIO.OUT) state=false def toggleLED(pin): state = not state GPIO.output(pin, state) while True: try: if (GPIO.input(25) == True): toggleLED(pin) sleep(.01) except KeyboardInterrupt: exit()
  • 32. Python Program for Sending an Email on Switch Press
  • 33. Python Program for Sending an Email on Switch Press
  • 34. Python Program for Sending an Email on Switch Press
  • 35. Interfacing Light Sensor (LDR) with RPi • Connect one side of LDR to 3.3V and other side to a1μF capacitor and also to a GPIO pin (pin 18 in this example). • An LED is connected to pin 18 which is controlled based on the light-level sensed. • The read LDR() function returns a count which is proportional to the light level. • In this function the LDR pin is set to output and low and then to input.
  • 36. Interfacing Light Sensor (LDR) with RPi • At this point the capacitor starts charging through the resistor (and a counter is started) until the input pin reads high (this happens when capacitor voltage becomes greater than 1.4V). • The counter is stopped when the input reads high. • The final count is proportional to the light level as greater the amount of light, smaller is the LDR resistance and greater is the time taken to charge the capacitor.
  • 37. Interfacing Light Sensor (LDR) with RPi import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) ldr_threshold = 1000 LDR_PIN = 18 LIGHT_PIN = 25 def readLDR(PIN): reading = 0 GPIO.setup(LIGHT_PIN, GPIO.OUT) GPIO.output(PIN, false) time.sleep(0.1) GPIO.setup(PIN, GPIO.IN) while (GPIO.input (PIN) ==Flase): reading=reading+1 return reading def switchOnLight(PIN): GPIO.setup(PIN, GPIO.OUT) GPIO.output(PIN, True) def switchOffLight(PIN): GPIO.setup(PIN, GPIO.OUT) GPIO.output(PIN, False) while True: ldr_reading = readLDR(LDR_PIN) if ldr_reading < ldr_threshold: switchOnLight (LIGHT_PIN) else: switchOffLight(LIGHT_PIN) time.sleep(1)
  • 38. Interfacing Light Sensor (LDR) with RPi
  • 39. Interfacing Light Sensor (LDR) with RPi
  • 40. Other Devices • pcDuino • BeagleBone Black • Cubieboard
  • 41. Comparison of Single Board Mini Computers