Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


Panneau latéral

materiel:rpi:gpio:accueil

Ceci est une ancienne révision du document !


RPI - GPIO

Utilisations : entrées, sorties, …

Avec la biblio RPI.gpio et la biblio gpiozero : Here’s a list of devices which currently supported:

  • LED (also PWM LED allowing change of brightness)
  • RGB LED
  • Buzzer
  • Motor
  • Button
  • Motion Sensor
  • Light Sensor
  • Analogue-to-Digital converters MCP3004 and MCP3008
  • Robot

Vidéo d'introduction

Ressources

Pins

RPI 3

RPI B+

Sorties

from gpiozero import LED
from time import sleep
 
led = LED(17)
 
while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)

Entreés

from gpiozero import Button
mybutton = Button(2)
mybutton.wait_for_press()
print('You pushed me')

Lancer une fonction

from gpiozero import Button
from signal import pause
 
def say_hello():
	print("Hello!")
 
button = Button(2)
button.when_pressed = say_hello
 
pause()

Lancer un programme

from gpiozero import Button from signal import pause import subprocess button = Button(2) button.wait_for_press() subprocess.call(, shell=True)
 

Entrée / Sortie

from gpiozero import LED, Button
from signal import pause
led = LED(17)
button = Button(2)
button.when_pressed = led.on
button.when_released = led.off
pause()
<code>
</WRAP>
</WRAP>
 
 
 
-----
 
 
FIXME
 
 
 
 
 
 
 
 
==== Installation ====
 
  sudo apt-get install python-setuptools
  sudo easy_install -U RPIO
 
Comme on a accès aux couches physiques avec ce type de module, il faut lancer python ou idle (l'interpréteur python) en mode administrateur :
 
  sudo idle &
 
==== Exemples ===
**Exemple de code en python (http://explainingcomputers.com/rasp_pi_robotics.html) :**
<code python>
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
for x in range(0,3):
    GPIO.output(7,True)
    time.sleep(1)
    GPIO.output(7,False)
    time.sleep(1)
GPIO.cleanup()

Autre exemple en contrôlant des moteurs à courant continu via un L298 :

/home/resonancg/www/wiki/data/attic/materiel/rpi/gpio/accueil.1480961973.txt.gz · Dernière modification: 2016/12/05 19:19 de resonance