sensors, actuators and the raspberry pi using python
TRANSCRIPT
![Page 1: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/1.jpg)
Sensors, actuators and the Raspberry PI
Programming GPIO using Python
![Page 2: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/2.jpg)
Raspberry PI vs Desktop PC
Smaller footprint Slower processor Less memory Non-standard peripherals
![Page 3: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/3.jpg)
![Page 4: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/4.jpg)
![Page 5: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/5.jpg)
![Page 6: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/6.jpg)
Using GPIO – output mode
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) # refer to GPIO pinsGPIO.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
![Page 7: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/7.jpg)
Using GPIO – input mode
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) # refer to GPIO pinsGPIO.setwarnings(False) # ignore warnings
GPIO.setup(pin, GPIO.IN) # make GPIO pin for input
val = GPIO.input(pin) # read GPIO pin
![Page 8: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/8.jpg)
![Page 9: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/9.jpg)
![Page 10: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/10.jpg)
![Page 11: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/11.jpg)
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
![Page 12: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/12.jpg)
![Page 13: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/13.jpg)
Relay controller sample code
import RPi.GPIO as GPIOimport 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)
![Page 14: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/14.jpg)
![Page 15: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/15.jpg)
![Page 16: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/16.jpg)
![Page 17: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/17.jpg)
Sensor Connections
Sensor board Raspberry PI
GND 6
OUT 11 (GPIO 17)
VCC 2
![Page 18: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/18.jpg)
Sensor sample code
pin = 17GPIO.setup(pin, GPIO.IN) # make GPIO pin for input
state = GPIO.input(pin) # read GPIO pinwhile True: time.sleep(1) r = GPIO.input(pin) if (r != state): state = r print "state changed"
![Page 19: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/19.jpg)
![Page 20: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/20.jpg)
![Page 21: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/21.jpg)
AD/DA board connections
AD/DA board Raspberry PI
SDA 3
SCL 5
VCC 2
GND 6
![Page 22: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/22.jpg)
Convertor sample codeimport 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)
![Page 23: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/23.jpg)
![Page 24: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/24.jpg)
![Page 25: Sensors, actuators and the Raspberry PI using Python](https://reader035.vdocuments.site/reader035/viewer/2022070521/58ef57bf1a28abf72b8b463f/html5/thumbnails/25.jpg)