🗊Презентация Описание возможностей GPIO

Категория: Технология
Нажмите для полного просмотра!
Описание возможностей GPIO, слайд №1Описание возможностей GPIO, слайд №2Описание возможностей GPIO, слайд №3Описание возможностей GPIO, слайд №4Описание возможностей GPIO, слайд №5Описание возможностей GPIO, слайд №6Описание возможностей GPIO, слайд №7Описание возможностей GPIO, слайд №8Описание возможностей GPIO, слайд №9Описание возможностей GPIO, слайд №10Описание возможностей GPIO, слайд №11Описание возможностей GPIO, слайд №12Описание возможностей GPIO, слайд №13Описание возможностей GPIO, слайд №14Описание возможностей GPIO, слайд №15Описание возможностей GPIO, слайд №16Описание возможностей GPIO, слайд №17Описание возможностей GPIO, слайд №18Описание возможностей GPIO, слайд №19Описание возможностей GPIO, слайд №20Описание возможностей GPIO, слайд №21Описание возможностей GPIO, слайд №22Описание возможностей GPIO, слайд №23

Вы можете ознакомиться и скачать презентацию на тему Описание возможностей GPIO. Доклад-сообщение содержит 23 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1






Raspberry PI. Описание возможностей GPIO
лекция 1
Описание слайда:
Raspberry PI. Описание возможностей GPIO лекция 1

Слайд 2





Raspberry PI 3
Описание слайда:
Raspberry PI 3

Слайд 3





CSI камера
Описание слайда:
CSI камера

Слайд 4





GPIO
Описание слайда:
GPIO

Слайд 5





I2C
Описание слайда:
I2C

Слайд 6





I2C. Датчика давления, температуры и влажности BME280 производства Bosch Sensortec
Описание слайда:
I2C. Датчика давления, температуры и влажности BME280 производства Bosch Sensortec

Слайд 7





UART
Описание слайда:
UART

Слайд 8





SPI
Описание слайда:
SPI

Слайд 9





Аналоги Raspberry
Описание слайда:
Аналоги Raspberry

Слайд 10





Raspbian
Описание слайда:
Raspbian

Слайд 11





raspberry-gpio-python
Importing the module
try:
    import RPi.GPIO as GPIO
except RuntimeError:
    print("Error importing RPi.GPIO!  This is probably because you need superuser privileges.  You can 
               achieve this by using 'sudo' to run your script")
Pin numbering
GPIO.setmode(GPIO.BOARD)					mode = GPIO.getmode()
  # or
GPIO.setmode(GPIO.BCM)
Описание слайда:
raspberry-gpio-python Importing the module try: import RPi.GPIO as GPIO except RuntimeError: print("Error importing RPi.GPIO! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script") Pin numbering GPIO.setmode(GPIO.BOARD) mode = GPIO.getmode() # or GPIO.setmode(GPIO.BCM)

Слайд 12





Channels
Warnings
GPIO.setwarnings(False)
Setup up a channel
GPIO.setup(channel, GPIO.IN)
GPIO.setup(channel, GPIO.OUT)
GPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH)
chan_list = [11,12]    # add as many channels as you want!
                       # you can tuples instead i.e.:
                       #   chan_list = (11,12)
GPIO.setup(chan_list, GPIO.OUT)
Input
To read the value of a GPIO pin:
GPIO.input(channel)
This will return either 0 / GPIO.LOW / False or 
1 / GPIO.HIGH / True.
Описание слайда:
Channels Warnings GPIO.setwarnings(False) Setup up a channel GPIO.setup(channel, GPIO.IN) GPIO.setup(channel, GPIO.OUT) GPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH) chan_list = [11,12] # add as many channels as you want! # you can tuples instead i.e.: # chan_list = (11,12) GPIO.setup(chan_list, GPIO.OUT) Input To read the value of a GPIO pin: GPIO.input(channel) This will return either 0 / GPIO.LOW / False or 1 / GPIO.HIGH / True.

Слайд 13





Cleanup
GPIO.cleanup(channel)
GPIO.cleanup( (channel1, channel2) )
GPIO.cleanup( [channel1, channel2] )

import atexit

def cleanup():
    GPIO.cleanup()
    print("Cleaning up!!")
    
atexit.register(cleanup)
Описание слайда:
Cleanup GPIO.cleanup(channel) GPIO.cleanup( (channel1, channel2) ) GPIO.cleanup( [channel1, channel2] ) import atexit def cleanup(): GPIO.cleanup() print("Cleaning up!!") atexit.register(cleanup)

Слайд 14





Inputs
Pull up / Pull down resistors
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  # or
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
Снимок в определенный момент
if GPIO.input(channel):
    print('Input was HIGH')
else:
    print('Input was LOW')
Или цикл:
(this assumes that pressing the button changes the input from LOW to HIGH)
while GPIO.input(channel) == GPIO.LOW:
    time.sleep(0.01)  # wait 10 ms to give CPU chance to do other things
Описание слайда:
Inputs Pull up / Pull down resistors GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP) # or GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) Снимок в определенный момент if GPIO.input(channel): print('Input was HIGH') else: print('Input was LOW') Или цикл: (this assumes that pressing the button changes the input from LOW to HIGH) while GPIO.input(channel) == GPIO.LOW: time.sleep(0.01) # wait 10 ms to give CPU chance to do other things

Слайд 15





Inputs.  Как опрашивать правильно?
Interrupts and Edge detection!
LOW -> HIGH = rising edge
HIGH -> LOW  = falling edge
wait_for_edge() function
GPIO.wait_for_edge(channel, GPIO.RISING) Блокировка программы!!!

# wait for up to 5 seconds for a rising edge (timeout is in milliseconds)
channel = GPIO.wait_for_edge(channel, GPIO_RISING, timeout=5000)
if channel is None:
    print('Timeout occurred')
else:
    print('Edge detected on channel', channel)
event_detected() function
GPIO.add_event_detect(channel, GPIO.RISING)  # add rising edge detection on a channel
do_something()
if GPIO.event_detected(channel):
    print('Button pressed')
Описание слайда:
Inputs. Как опрашивать правильно? Interrupts and Edge detection! LOW -> HIGH = rising edge HIGH -> LOW = falling edge wait_for_edge() function GPIO.wait_for_edge(channel, GPIO.RISING) Блокировка программы!!! # wait for up to 5 seconds for a rising edge (timeout is in milliseconds) channel = GPIO.wait_for_edge(channel, GPIO_RISING, timeout=5000) if channel is None: print('Timeout occurred') else: print('Edge detected on channel', channel) event_detected() function GPIO.add_event_detect(channel, GPIO.RISING) # add rising edge detection on a channel do_something() if GPIO.event_detected(channel): print('Button pressed')

Слайд 16





Threaded callbacks
def my_callback(channel):
    print('This is a edge event callback function!')
    print('Edge detected on channel %s'%channel)
    print('This is run in a different thread to your main program')
GPIO.add_event_detect(channel, GPIO.RISING, callback=my_callback)  # add rising edge detection on a channel
...the rest of your program...
def my_callback_one(channel):
    print('Callback one')

def my_callback_two(channel):
    print('Callback two')

GPIO.add_event_detect(channel, GPIO.RISING)
GPIO.add_event_callback(channel, my_callback_one)
GPIO.add_event_callback(channel, my_callback_two)
Описание слайда:
Threaded callbacks def my_callback(channel): print('This is a edge event callback function!') print('Edge detected on channel %s'%channel) print('This is run in a different thread to your main program') GPIO.add_event_detect(channel, GPIO.RISING, callback=my_callback) # add rising edge detection on a channel ...the rest of your program... def my_callback_one(channel): print('Callback one') def my_callback_two(channel): print('Callback two') GPIO.add_event_detect(channel, GPIO.RISING) GPIO.add_event_callback(channel, my_callback_one) GPIO.add_event_callback(channel, my_callback_two)

Слайд 17





Switch debounce (шумоподавитель)
You may notice that the callbacks are called more than once for each button press. This is as a result of what is known as 'switch bounce'. There are two ways of dealing with switch bounce:
add a 0.1uF capacitor across your switch.
software debouncing
a combination of both
To debounce using software, add the bouncetime= parameter to a function where you specify a callback function. Bouncetime should be specified in milliseconds. For example:

# add rising edge detection on a channel, ignoring further edges for 200ms for switch bounce handling
GPIO.add_event_detect(channel, GPIO.RISING, callback=my_callback, bouncetime=200)

or
GPIO.add_event_callback(channel, my_callback, bouncetime=200)
Описание слайда:
Switch debounce (шумоподавитель) You may notice that the callbacks are called more than once for each button press. This is as a result of what is known as 'switch bounce'. There are two ways of dealing with switch bounce: add a 0.1uF capacitor across your switch. software debouncing a combination of both To debounce using software, add the bouncetime= parameter to a function where you specify a callback function. Bouncetime should be specified in milliseconds. For example: # add rising edge detection on a channel, ignoring further edges for 200ms for switch bounce handling GPIO.add_event_detect(channel, GPIO.RISING, callback=my_callback, bouncetime=200) or GPIO.add_event_callback(channel, my_callback, bouncetime=200)

Слайд 18





Пример, на  input
# coding: utf-8

import RPi.GPIO as GPIO
import time, datetime 
import atexit
import lab_work_3_telegram 

def cleanup():
    GPIO.cleanup()
    print("Cleaning up!!")
    
atexit.register(cleanup)

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(19,GPIO.IN)
GPIO.setup(20,GPIO.IN)

def mic_fc_04(channel): #power 3.3v
    if GPIO.event_detected(channel):
        print(str(datetime.datetime.now()),' Шум в помещении!')
Описание слайда:
Пример, на input # coding: utf-8 import RPi.GPIO as GPIO import time, datetime import atexit import lab_work_3_telegram def cleanup(): GPIO.cleanup() print("Cleaning up!!") atexit.register(cleanup) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(19,GPIO.IN) GPIO.setup(20,GPIO.IN) def mic_fc_04(channel): #power 3.3v if GPIO.event_detected(channel): print(str(datetime.datetime.now()),' Шум в помещении!')

Слайд 19





GPIO Outputs
1. First set up RPi.GPIO 
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)

2. To set an output high:
GPIO.output(12, GPIO.HIGH)
 # or
GPIO.output(12, 1)
 # or
GPIO.output(12, True)

3. To set an output low:
GPIO.output(12, GPIO.LOW)
 # or
GPIO.output(12, 0)
 # or
GPIO.output(12, False)
Описание слайда:
GPIO Outputs 1. First set up RPi.GPIO import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) 2. To set an output high: GPIO.output(12, GPIO.HIGH) # or GPIO.output(12, 1) # or GPIO.output(12, True) 3. To set an output low: GPIO.output(12, GPIO.LOW) # or GPIO.output(12, 0) # or GPIO.output(12, False)

Слайд 20





PWM
Широтно-импульсная модуляция (ШИМ, англ. pulse-width modulation (PWM)) — процесс управления мощностью, подводимой к нагрузке, путём изменения скважности импульсов, при постоянной частоте.
Описание слайда:
PWM Широтно-импульсная модуляция (ШИМ, англ. pulse-width modulation (PWM)) — процесс управления мощностью, подводимой к нагрузке, путём изменения скважности импульсов, при постоянной частоте.

Слайд 21





Using PWM in RPi.GPIO
To create a PWM instance:
p = GPIO.PWM(channel, frequency)

To start PWM:
p.start(dc)   # where dc is the duty cycle (0.0 <= dc <= 100.0)

To change the frequency:
p.ChangeFrequency(freq)   # where freq is the new frequency in Hz

To change the duty cycle:
p.ChangeDutyCycle(dc)  # where 0.0 <= dc <= 100.0

To stop PWM:
p.stop()
Описание слайда:
Using PWM in RPi.GPIO To create a PWM instance: p = GPIO.PWM(channel, frequency) To start PWM: p.start(dc) # where dc is the duty cycle (0.0 <= dc <= 100.0) To change the frequency: p.ChangeFrequency(freq) # where freq is the new frequency in Hz To change the duty cycle: p.ChangeDutyCycle(dc) # where 0.0 <= dc <= 100.0 To stop PWM: p.stop()

Слайд 22





Using PWM in RPi.GPIO
An example to brighten/dim an LED:
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)

p = GPIO.PWM(12, 50)  # channel=12 frequency=50Hz
p.start(0)
try:
    while 1:
        for dc in range(0, 101, 5):
            p.ChangeDutyCycle(dc)
            time.sleep(0.1)
        for dc in range(100, -1, -5):
            p.ChangeDutyCycle(dc)
            time.sleep(0.1)
except KeyboardInterrupt: 
    pass
p.stop()
GPIO.cleanup()
Описание слайда:
Using PWM in RPi.GPIO An example to brighten/dim an LED: import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) p = GPIO.PWM(12, 50) # channel=12 frequency=50Hz p.start(0) try: while 1: for dc in range(0, 101, 5): p.ChangeDutyCycle(dc) time.sleep(0.1) for dc in range(100, -1, -5): p.ChangeDutyCycle(dc) time.sleep(0.1) except KeyboardInterrupt: pass p.stop() GPIO.cleanup()

Слайд 23





Checking function of GPIO channels
gpio_function(channel)
Shows the function of a GPIO channel.
For example:
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
func = GPIO.gpio_function(pin)

will return a value from:
GPIO.IN, GPIO.OUT, GPIO.SPI, GPIO.I2C, GPIO.HARD_PWM, GPIO.SERIAL, GPIO.UNKNOWN
Описание слайда:
Checking function of GPIO channels gpio_function(channel) Shows the function of a GPIO channel. For example: import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) func = GPIO.gpio_function(pin) will return a value from: GPIO.IN, GPIO.OUT, GPIO.SPI, GPIO.I2C, GPIO.HARD_PWM, GPIO.SERIAL, GPIO.UNKNOWN



Похожие презентации
Mypresentation.ru
Загрузить презентацию