SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
Sensors, actuators and the
Raspberry PI
Programming GPIO using Python
Raspberry PI vs Desktop PC
• Smaller footprint
• Slower processor

Less memory

Non-standard peripherals
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Using GPIO – output mode
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # refer to GPIO pins
GPIO.setwarnings(False) # ignore warnings
GPIO.setup(pin, GPIO.OUT) # make GPIO pin for output
GPIO.output(pin, GPIO.HIGH) # turn ON GPIO pin
GPIO.output(pin, GPIO.LOW) # turn OFF GPIO pin
Using GPIO – input mode
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # refer to GPIO pins
GPIO.setwarnings(False) # ignore warnings
GPIO.setup(pin, GPIO.IN) # make GPIO pin for input
val = GPIO.input(pin) # read GPIO pin
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Relay Connections
Relay board Raspberry PI
GND 6
IN1 15 (GPIO 22)
IN2 16 (GPIO 23)
IN3 18 (GPIO 24)
IN4 22 (GPIO 25)
VCC 2
Sensors, actuators and the Raspberry PI using Python
Relay controller sample code
import RPi.GPIO as GPIO
import time
pins = [22,23,24,25]
for p in pins:
GPIO.setup(p, GPIO.OUT)
while True:
for q in pins:
GPIO.output(q, GPIO.HIGH)
time.sleep(5)
for q in pins:
GPIO.output(q, GPIO.LOW)
time.sleep(5)
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Sensor Connections
Sensor board Raspberry PI
GND 6
OUT 11 (GPIO 17)
VCC 2
Sensor sample code
pin = 17
GPIO.setup(pin, GPIO.IN) # make GPIO pin for input
state = GPIO.input(pin) # read GPIO pin
while True:
time.sleep(1)
r = GPIO.input(pin)
if (r != state):
state = r
print "state changed"
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
AD/DA board connections
AD/DA board Raspberry PI
SDA 3
SCL 5
VCC 2
GND 6
Convertor sample code
import smbus
def read(a):
bus.read_byte_data(0x48, a)
return bus.read_data(0x48)
bus = smbus.SMBus(1)
control = read(0)
light = read(1)
temperature = read(2)
custom = read(3)
bus.write_byte(self.addr, 99)
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Zener Diodes.ppt
 Zener Diodes.ppt Zener Diodes.ppt
Zener Diodes.ppt
 
Arduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the ArduinoArduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the Arduino
 
Analog to digital converters, adc
Analog to digital converters, adcAnalog to digital converters, adc
Analog to digital converters, adc
 
Hybrid Parameter in BJT
Hybrid Parameter in BJTHybrid Parameter in BJT
Hybrid Parameter in BJT
 
(Main)astable square wave generator
(Main)astable square wave generator(Main)astable square wave generator
(Main)astable square wave generator
 
Lambda design rule
Lambda design ruleLambda design rule
Lambda design rule
 
Mosfet
MosfetMosfet
Mosfet
 
Two port networks
Two port networksTwo port networks
Two port networks
 
Voltage Source Inverter
Voltage Source InverterVoltage Source Inverter
Voltage Source Inverter
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
Inverter
InverterInverter
Inverter
 
Clipper and Clamper
Clipper and ClamperClipper and Clamper
Clipper and Clamper
 
1.1.6 diode resistance
1.1.6 diode resistance1.1.6 diode resistance
1.1.6 diode resistance
 
Adc and dac
Adc and dacAdc and dac
Adc and dac
 
Small signal analysis of bjt amplifiers
Small signal analysis of bjt amplifiersSmall signal analysis of bjt amplifiers
Small signal analysis of bjt amplifiers
 
bode_plot By DEV
 bode_plot By DEV bode_plot By DEV
bode_plot By DEV
 
Interfacing stepper motor
Interfacing stepper motorInterfacing stepper motor
Interfacing stepper motor
 
Op amp
Op ampOp amp
Op amp
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
Unit-1 Power Semiconductor devices
Unit-1 Power Semiconductor devicesUnit-1 Power Semiconductor devices
Unit-1 Power Semiconductor devices
 

Destaque

Sensors and Actuators
Sensors and Actuators Sensors and Actuators
Sensors and Actuators Aamir Shaikh
 
Internet of Things
Internet of ThingsInternet of Things
Internet of ThingsRainmaker Ho
 
92058 sensors transducers and actuators
92058 sensors transducers and actuators92058 sensors transducers and actuators
92058 sensors transducers and actuatorskumar19792
 
Mechanical sensor
Mechanical sensorMechanical sensor
Mechanical sensorB.k. Das
 
Introduction to Windows IoT via Raspberry Pi 3
Introduction to Windows IoT via Raspberry Pi 3Introduction to Windows IoT via Raspberry Pi 3
Introduction to Windows IoT via Raspberry Pi 3Lee Richardson
 
Internet of things using Raspberry Pi
Internet of things using Raspberry PiInternet of things using Raspberry Pi
Internet of things using Raspberry PiYash Gajera
 
The Future of Embedded and IoT Security: Kaspersky Operating System
The Future of Embedded and IoT Security: Kaspersky Operating SystemThe Future of Embedded and IoT Security: Kaspersky Operating System
The Future of Embedded and IoT Security: Kaspersky Operating SystemKaspersky Lab
 

Destaque (8)

Sensors and Actuators
Sensors and Actuators Sensors and Actuators
Sensors and Actuators
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
 
92058 sensors transducers and actuators
92058 sensors transducers and actuators92058 sensors transducers and actuators
92058 sensors transducers and actuators
 
Mechanical sensors 2
Mechanical sensors 2Mechanical sensors 2
Mechanical sensors 2
 
Mechanical sensor
Mechanical sensorMechanical sensor
Mechanical sensor
 
Introduction to Windows IoT via Raspberry Pi 3
Introduction to Windows IoT via Raspberry Pi 3Introduction to Windows IoT via Raspberry Pi 3
Introduction to Windows IoT via Raspberry Pi 3
 
Internet of things using Raspberry Pi
Internet of things using Raspberry PiInternet of things using Raspberry Pi
Internet of things using Raspberry Pi
 
The Future of Embedded and IoT Security: Kaspersky Operating System
The Future of Embedded and IoT Security: Kaspersky Operating SystemThe Future of Embedded and IoT Security: Kaspersky Operating System
The Future of Embedded and IoT Security: Kaspersky Operating System
 

Semelhante a Sensors, actuators and the Raspberry PI using Python

Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Dnyanesh Patil
 
Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development FastBit Embedded Brain Academy
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218CAVEDU Education
 
Ins and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingIns and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingICS
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Tom Paulus
 
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)savageautomate
 
Raspberry pi tutorial #1
Raspberry pi tutorial #1Raspberry pi tutorial #1
Raspberry pi tutorial #1동호 손
 
Project ACRN GPIO mediator introduction
Project ACRN GPIO mediator introductionProject ACRN GPIO mediator introduction
Project ACRN GPIO mediator introductionProject ACRN
 
F9 microkernel app development part 2 gpio meets led
F9 microkernel app development part 2 gpio meets ledF9 microkernel app development part 2 gpio meets led
F9 microkernel app development part 2 gpio meets ledBenux Wei
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRICELEEIO
 
Exploring Raspberry Pi
Exploring Raspberry PiExploring Raspberry Pi
Exploring Raspberry PiLentin Joseph
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiNeil Broers
 

Semelhante a Sensors, actuators and the Raspberry PI using Python (20)

Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3
 
Raspberry pi led blink
Raspberry pi led blinkRaspberry pi led blink
Raspberry pi led blink
 
PPT+.pdf
PPT+.pdfPPT+.pdf
PPT+.pdf
 
Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development
 
4. GPIO Access
4. GPIO Access4. GPIO Access
4. GPIO Access
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
 
Ins and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingIns and Outs of GPIO Programming
Ins and Outs of GPIO Programming
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013
 
Atomic pi Mini PC
Atomic pi Mini PCAtomic pi Mini PC
Atomic pi Mini PC
 
Atomic PI apug
Atomic PI apugAtomic PI apug
Atomic PI apug
 
Day4
Day4Day4
Day4
 
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
 
Raspberry pi tutorial #1
Raspberry pi tutorial #1Raspberry pi tutorial #1
Raspberry pi tutorial #1
 
Project ACRN GPIO mediator introduction
Project ACRN GPIO mediator introductionProject ACRN GPIO mediator introduction
Project ACRN GPIO mediator introduction
 
F9 microkernel app development part 2 gpio meets led
F9 microkernel app development part 2 gpio meets ledF9 microkernel app development part 2 gpio meets led
F9 microkernel app development part 2 gpio meets led
 
PPT+.pdf
PPT+.pdfPPT+.pdf
PPT+.pdf
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
 
Exploring Raspberry Pi
Exploring Raspberry PiExploring Raspberry Pi
Exploring Raspberry Pi
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry Pi
 
Raspberry pi and pi4j
Raspberry pi and pi4jRaspberry pi and pi4j
Raspberry pi and pi4j
 

Sensors, actuators and the Raspberry PI using Python

  • 1. Sensors, actuators and the Raspberry PI Programming GPIO using Python
  • 2. Raspberry PI vs Desktop PC • Smaller footprint • Slower processor  Less memory  Non-standard peripherals
  • 6. Using GPIO – output mode import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) # refer to GPIO pins GPIO.setwarnings(False) # ignore warnings GPIO.setup(pin, GPIO.OUT) # make GPIO pin for output GPIO.output(pin, GPIO.HIGH) # turn ON GPIO pin GPIO.output(pin, GPIO.LOW) # turn OFF GPIO pin
  • 7. Using GPIO – input mode import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) # refer to GPIO pins GPIO.setwarnings(False) # ignore warnings GPIO.setup(pin, GPIO.IN) # make GPIO pin for input val = GPIO.input(pin) # read GPIO pin
  • 11. Relay Connections Relay board Raspberry PI GND 6 IN1 15 (GPIO 22) IN2 16 (GPIO 23) IN3 18 (GPIO 24) IN4 22 (GPIO 25) VCC 2
  • 13. Relay controller sample code import RPi.GPIO as GPIO import time pins = [22,23,24,25] for p in pins: GPIO.setup(p, GPIO.OUT) while True: for q in pins: GPIO.output(q, GPIO.HIGH) time.sleep(5) for q in pins: GPIO.output(q, GPIO.LOW) time.sleep(5)
  • 17. Sensor Connections Sensor board Raspberry PI GND 6 OUT 11 (GPIO 17) VCC 2
  • 18. Sensor sample code pin = 17 GPIO.setup(pin, GPIO.IN) # make GPIO pin for input state = GPIO.input(pin) # read GPIO pin while True: time.sleep(1) r = GPIO.input(pin) if (r != state): state = r print "state changed"
  • 21. AD/DA board connections AD/DA board Raspberry PI SDA 3 SCL 5 VCC 2 GND 6
  • 22. Convertor sample code import smbus def read(a): bus.read_byte_data(0x48, a) return bus.read_data(0x48) bus = smbus.SMBus(1) control = read(0) light = read(1) temperature = read(2) custom = read(3) bus.write_byte(self.addr, 99)