Modifications

Sauter à la navigation Sauter à la recherche
1 175 octets ajoutés ,  21 février 2018 à 10:08
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{RASP-FT232H-NAV}}
 
{{RASP-FT232H-NAV}}
  −
{{traduction}}
      
Il est facile de contrôler les broches GPIO de la carte FT232H en utilisant la bibliothèque "Python GPIO d'Adafruit". Maintenant que cette bibliothèque est installée, nous allons en démontrer l'usage avec des exemples simples. Nous allons faire clignoter une LED et lire une entrée digitale.
 
Il est facile de contrôler les broches GPIO de la carte FT232H en utilisant la bibliothèque "Python GPIO d'Adafruit". Maintenant que cette bibliothèque est installée, nous allons en démontrer l'usage avec des exemples simples. Nous allons faire clignoter une LED et lire une entrée digitale.
Ligne 49 : Ligne 47 :     
# Bouche infinie qui change l'état de la LED (allumé/éteind) et lit l'état de l'entrée.
 
# Bouche infinie qui change l'état de la LED (allumé/éteind) et lit l'état de l'entrée.
 +
# Presser Ctrl-C pour quitter le programme
 
print 'Press Ctrl-C to quit.'
 
print 'Press Ctrl-C to quit.'
 
while True:
 
while True:
# Set pin C0 to a high level so the LED turns on.
+
# Mettre la broche C0 au niveau haut (HIGH) pour allumer la LED.
 
ft232h.output(8, GPIO.HIGH)
 
ft232h.output(8, GPIO.HIGH)
# Sleep for 1 second.
+
# Attendre 1 seconde.
 
time.sleep(1)
 
time.sleep(1)
# Set pin C0 to a low level so the LED turns off.
+
# Mettre la broche C0 au niveau base (LOW) pour eteindre la LED.
 
ft232h.output(8, GPIO.LOW)
 
ft232h.output(8, GPIO.LOW)
# Sleep for 1 second.
+
# Attendre 1 seconde.
 
time.sleep(1)
 
time.sleep(1)
# Read the input on pin D7 and print out if it's high or low.
+
# Lire l'etat de la broche D7 et afficher si le niveau est haut (HIGH) ou bas (LOW).
 
level = ft232h.input(7)
 
level = ft232h.input(7)
 
if level == GPIO.LOW:
 
if level == GPIO.LOW:
Ligne 67 : Ligne 66 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
Save the file and then open a command line terminal and navigate to the folder with gpio_test.py. Run the script by executing on Windows:
+
Sauvez le fichier puis ouvrez un terminal de commande.
 +
 
 +
Utilisez la commande {{fname|cd}} pour vous rendre dans le répertoire où le fichier '''gpio_test.py''' est stocké.  
 +
 
 +
Exécutez le script en exécutant la commande suivante sous Windows:
    
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Ligne 73 : Ligne 76 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
Or on Mac OSX or Linux run the script as root by executing:
+
Ou la commande suivante sous Mac OSX ou Linux (nous utilisons {{fname|sudo}} pour avoir les droits administrateurs):
    
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Ligne 79 : Ligne 82 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
You should see the LED start to blink once a second, and the state of the D7 input is also printed. For example if D7 is connected to ground you'll see:
+
Vous devriez voir la LED commencer à clignoter une fois par seconde et afficher régulièrement l'état de la broche D7.
 +
 
 +
Par exemple, si la broche D7 est connectés sur la masse, vous devriez voir:
    
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Ligne 88 : Ligne 93 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
Try moving the jumper wire for D7 from ground to 5 volts. You should see the input start to read a high value:
+
Essayez de déplacer le fil que vous avez branché sur D7 de la masse (GND) à 5 Volts. Vous devriez voir les lectures de la valeur d'entrée passer à 'HIGH' (niveau haut):
    
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Ligne 96 : Ligne 101 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
Swap the jumper wire between ground and 5 volts to see the input value change.
+
Basculez de nouveau le fil de +5Volts vers la masse (GND) et la valeur lue repassera de nouveau vers 'LOW' (niveau bas).
   −
Let's look a little more closely at the code to understand how reading and writing digital GPIO works.
+
Jetons un petit coup d'oeil sous le capot pour voir comment le programme fonctionne pour effectuer les lectures et écritures sur les GPIOs.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Import standard Python time library.
+
# Importer la bibliothèque standard "time".
 
import time
 
import time
   −
# Import GPIO and FT232H modules.
+
# Importer les modules GPIO et FT232H
 
import Adafruit_GPIO as GPIO
 
import Adafruit_GPIO as GPIO
 
import Adafruit_GPIO.FT232H as FT232H
 
import Adafruit_GPIO.FT232H as FT232H
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
First the required modules are loaded for this script. The time module will be used to delay for a short period of time.   
+
Pour commencer, le programme charge les modules nécessaire pour le fonctionnement du script. Le module {{fname|time}} est utilisé pour insérer des délais de pause dans le programme.   
   −
The '''Adafruit_GPIO''' and '''Adafruit_GPIO.FT232H''' modules will be imported with shorter names using the 'as' keyword. These modules have all the logic for reading and writing GPIO on the FT232H.
+
Les modules '''Adafruit_GPIO''' et '''Adafruit_GPIO.FT232H''' sont importés et un alias (nom raccourcis) est associé aux modules à l'aide du mot clée {{fname|as}}. Ces modules dispose de toute la logique nécessaire pour lire les écrire des valeurs sur les GPIO du FT232H.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Temporarily disable the built-in FTDI serial driver on Mac & Linux platforms.
+
# Désactiver temporairement le pilote FTDI série sur les plateformes Mac et Linux.
 
FT232H.use_FT232H()
 
FT232H.use_FT232H()
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
Next the '''use_FT232H()''' function is called to temporarily disable any FTDI serial drivers. This command is necessary on Mac or Linux platforms because the libftdi library will interfere with the built-in FTDI serial drivers.   
+
Ensuite, l'utilisation de la fonction '''use_FT232H()''' est pour temporairement désactiver le le pilote série FTDI. Cette commande est nécessaire sur les plateformes Mac ou Linux parce que la bibliothèque libftdi interfère avec la pilote FTDI série.   
   −
You don't really need to run this command on Windows because the FTDI serial driver was disabled using the Zadig tool, however it can't hurt to call the function as it will do nothing on Windows.
+
Vous n'avez pas vraiment besoin d'exécuter cette commande sur Windows parce que le pilote FTDI série a été désactivé avec l'outil Zadig. Cet appel ne perturbera pas le fonctionnement de du script sous Windows.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Create an FT232H object that grabs the first available FT232H device found.
+
# Créer un objet FT232H qui récupère le premier périphérique FT232H disponible.
 
ft232h = FT232H.FT232H()
 
ft232h = FT232H.FT232H()
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
Now an FT232H object is created and assigned to the ft232h variable. This will detect the first available FT232H device connected to the computer and initialize its MPSSE for use with GPIO.
+
Maintenant que l'objet FT232H est créé et assigné à la variable ft232h. Cette opération détecte le premier périphérique FT232H disponible sur l'ordinateur et l'initialise en mode MPSSE pour utiliser son GPIO.
   −
Make sure the '''use_FT232H()''' function was previously called or else this function will fail!
+
Assurez vous d'avoir appelé la fonction '''use_FT232H()''' avant la création de l'objet sinon la création échouera!
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Configure digital inputs and outputs using the setup function.
+
# Configure les entrées et sorties digitales en utilisant la fonction setup.
# Note that pin numbers 0 to 15 map to pins D0 to D7 then C0 to C7 on the board.
+
# Note: les broches 0 à 15 correspondent aux broches D0 à D7 puis à C0 à C7 de la carte.
ft232h.setup(7, GPIO.IN)  # Make pin D7 a digital input.
+
ft232h.setup(7, GPIO.IN)  # Déclare la broche D7 comme un entrée digitale.
ft232h.setup(8, GPIO.OUT)  # Make pin C0 a digital output.
+
ft232h.setup(8, GPIO.OUT)  # Déclare la broche C0 comme une sortie digitale.
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
Next the '''setup()''' function is called on the FT232H object. This function takes two parameters, the first is the pin number and the second is either '''GPIO.IN''' or '''GPIO.OUT''' to set the pin as a digital input or output.   
+
Ensuite, la fonction '''setup()''' de l'objet FT232H est appelé. Cette fonction prend deux paramètres: le premier est le numéro de broche et le second soit '''GPIO.IN''' ou '''GPIO.OUT''' pour déclarer la broche en entrée ou en sortie.   
   −
Remember the pin numbers are <font color="orange">'''0 to 7'''</font> for <font color="orange">'''D0 to D7'''</font>, and <font color="teal">'''8 to 15'''</font> for <font color="teal">'''C0 to C7'''</font>.
+
Rappelez vous que les numeros de broche sont <font color="orange">'''de 0 à 7'''</font> pour les <font color="orange">'''broches D0 à D7'''</font>, et <font color="teal">'''de 8 à 15'''</font> pour les <font color="teal">'''broches C0 à C7'''</font>.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Loop turning the LED on and off and reading the input state.
+
# Boucle allumant et éteignant la LED -- et -- lisant l'état de l'entrée .
 +
# Presser contrôle C pour quitter le programme.
 
print 'Press Ctrl-C to quit.'
 
print 'Press Ctrl-C to quit.'
 
while True:
 
while True:
# Set pin C0 to a high level so the LED turns on.
+
# Mettre la broche C0 au niveau haut (HIGH) pour allumer la LED.
 
ft232h.output(8, GPIO.HIGH)
 
ft232h.output(8, GPIO.HIGH)
# Sleep for 1 second.
+
# Attendre une seconde.
 
time.sleep(1)
 
time.sleep(1)
# Set pin C0 to a low level so the LED turns off.
+
# Mettre la broche C0 au niveau bas (LOW) pour eteindre la LED.
 
ft232h.output(8, GPIO.LOW)
 
ft232h.output(8, GPIO.LOW)
# Sleep for 1 second.
+
# Attendre une seconde.
 
time.sleep(1)
 
time.sleep(1)
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
Now an infinite loop is entered and the LED is turned on and off using the '''output()''' function on the FT232H object. This function takes two parameters, the first is the pin number and the second is '''GPIO.HIGH/True''' to set the pin to a high level (3.3 volts), or '''GPIO.LOW/False''' to set the pin to a low level (ground).
+
Maintenant que nous démarré une boucle infinie et la LED s'allume et s'éteind en utilisant la fonction '''output()''' de l'objet FT232H.  
 +
 
 +
La fonction '''output()''' accepte deux paramètres:
 +
* Le premier est le numéro de broche
 +
* Le second est soit '''GPIO.HIGH/True''' pour un niveau logique haut (3.3 volts) --OU-- '''GPIO.LOW/False''' pour un niveau logique bas (la masse).
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Read the input on pin D7 and print out if it's high or low.
+
# Lire l'entrée de sur la broche D7 et affiche l'état de la broche HIGH ou LOW (haut ou bas).
 
level = ft232h.input(7)
 
level = ft232h.input(7)
 
if level == GPIO.LOW:
 
if level == GPIO.LOW:
Ligne 167 : Ligne 177 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
Finally the digital input is read using the '''input()''' function on the FT232H object. This function takes one parameter, the pin number to read. The function will return '''GPIO.LOW/False''' if the input is at a low level (below about 0.8 volts), and '''GPIO.HIGH/True''' if the input is at a high level (above about 0.8 volts, up to 5V max).
+
Pour finir l'entrée digitale du FT232H est lue avec la fonction '''input()'''. Cette fonction prend un paramètre, le numéro de broche à lire.
 +
 
 +
La fonction retournera '''GPIO.LOW/False''' si l'entrée est au niveau bas (en dessous de 0.8 volts), et '''GPIO.HIGH/True''' si l'entrée est au niveau haut (au dessus de 0.8 volts, jusqu'à 5V max).
 +
 
 +
Voilà, c'est tout ce que nous avons besoin de savoir pour utiliser le GPIO du breakout FT232H!
   −
That's all there is to use GPIO on the FT232H board!  You can use these GPIO pins to turn on and off devices or LEDs, or read switches or pins from other chips.
+
Vous pouvez maintenant utilise les broches du GPIO pour activer/désactiver des périphériques, des LEDs, etc. Vous pouvez également lire des entrées boutons ou l'état des broches d'autres composants.
   −
Be aware that the output pins on the FT232H are only designed to source a few milliamps of current (up to about 16mA per pin). If you need to drive devices that take a lot of current, look into using transistors to switch higher amounts of current.
+
{{ambox|text=Gardez à l'esprit que les broches du FT232H sont conçues pour fournir que quelques milliampères (jusqu'à 16mA par broche). Si vous avez besoin de contrôler des périphériques plus puissants vous pourrez utiliser des transistors pour contrôler des courants plus puissant}}
    
{{RASP-FT232H-TRAILER}}
 
{{RASP-FT232H-TRAILER}}
29 918

modifications

Menu de navigation