Ligne 1 : |
Ligne 1 : |
| == Introduction == | | == Introduction == |
− | Ce tutoriel vous explique comment exploiter comment commander des LEDs (DELs) en utilisant un [http://mchobby.be/PrestaShop/product.php?id_product=160 PI-Cobbler] et Python. | + | Ce tutoriel vous explique comment exploiter comment commander des LEDs (DELs) en utilisant un {{link-product-picobblerplus}} ou {{link-product-picobbler}} et Python.<br /> |
− | Assurez-vous d'avoir [http://mchobby.be/wiki/index.php?title=RaspberryPi-Accueil#Pr.C3.A9paration_pour_Python mis votre environnement Python à jour]. | + | Assurez-vous d'avoir [[RaspberryPi-Accueil#Pr.C3.A9paration_pour_Python|mis votre environnement Python à jour]]. |
| + | |
| + | === Pi-Cobbler ou Pi-Cobbler-Plus? === |
| + | |
| + | {{picobbler-compatibility}} |
| | | |
| == PI Cobbler & resistances == | | == PI Cobbler & resistances == |
Ligne 36 : |
Ligne 40 : |
| | | |
| == Le script Python == | | == Le script Python == |
− | xx
| + | Pour créer facilement ce script sur votre python, nous vous proposons une méthode à base de copier/coller à l'aide des étapes suivantes à réaliser dans un terminal (ou une connexion SSH). |
| + | |
| + | === Copier/coller le code === |
| + | Voici une méthode Copier/Coller super simple<br /> |
| + | |
| + | On commence par demander la création du fichier |
| + | <nowiki>cat <<! > raspi-blink.py</nowiki> |
| + | |
| + | On fait ensuite le copier/coller du code |
| + | <nowiki>#!/usr/bin/env python |
| + | # -*- coding: latin-1 -*- |
| + | |
| + | import RPi.GPIO as GPIO, time |
| + | |
| + | DEBUG = 1 |
| + | |
| + | LED_PAUSE = 2 # temps de pause en seconde |
| + | STATE = 0 # conteint RED_LED ou GREEN_ en fonction de la LED Actuellement allumée |
| + | |
| + | GPIO.setmode(GPIO.BCM) |
| + | GREEN_LED = 18 |
| + | RED_LED = 23 |
| + | GPIO.setup(GREEN_LED, GPIO.OUT) |
| + | GPIO.setup(RED_LED, GPIO.OUT) |
| + | |
| + | while True: |
| + | |
| + | if DEBUG: |
| + | print "." |
| + | |
| + | if STATE == RED_LED: |
| + | # Si LED Rouge Allumée... l'éteindre et allumer la verte |
| + | GPIO.output(GREEN_LED, True) |
| + | GPIO.output(RED_LED, False) |
| + | STATE = GREEN_LED |
| + | else: |
| + | # Si LED Verte Allumée... l'éteindre et allumer la rouge |
| + | GPIO.output(GREEN_LED, False) |
| + | GPIO.output(RED_LED, True) |
| + | STATE = RED_LED |
| + | |
| + | time.sleep(LED_PAUSE)</nowiki> |
| + | |
| + | On termine l'opération de saisie simplement avec: |
| + | <nowiki>!</nowiki> |
| + | |
| + | === Editer le fichier === |
| + | Si vous aviez besoin de modifier le fichier raspi-blink.py, vous pouvez utiliser nano... rudimentaire mais efficace. |
| + | <nowiki>nano raspi-blink.py</nowiki> |
| + | |
| + | Sachez juste que les options affichée comme '''^X''' signifie '''Ctrl+X''' |
| + | |
| + | === Rendre le fichier exécutable === |
| + | Par défaut, les fichier sont considéré comme des fichiers texte non exécutable... même s'il contiennent des scripts. |
| + | |
| + | Il faut donc indiquer au système d'exploitation qu'il peut autoriser l'exécution de notre raspi-blink.py |
| + | <nowiki>chmod +x raspi-blink.py</nowiki> |
| + | |
| + | == Exécuter notre programme == |
| + | <nowiki>sudo ./raspi-blink.py</nowiki> |
| + | |
| + | == Arrêter votre programme == |
| + | Un simple Ctrl + C fera l'affaire |
| + | |
| + | == Exemple en image == |
| + | {{#Widget:Iframe |
| + | |url=https://www.youtube.com/embed/o6QtrS1o0QY |
| + | |width=420 |
| + | |height=315 |
| + | |border=0 |
| + | }} |
| | | |
| == Ou Acheter == | | == Ou Acheter == |
− | Le [http://mchobby.be/PrestaShop/category.php?id_category=30 Pi-Cobbler est disponible de stock chez MCHobby].
| + | Les produits suivants sont disponibles chez MCHobby: |
| + | * {{link-product-picobblerplus}} |
| + | * {{link-product-pi3}} |
| + | * {{link-product-pi2}} |
| + | * {{link-product-piplus}} |
| + | * {{link-product-picobbler}} |
| + | * {{link-product-pi}} |
| | | |
| {{MCH-Accord}} | | {{MCH-Accord}} |
| | | |
| {{ADF-Accord}} | | {{ADF-Accord}} |