| Ligne 18 : |
Ligne 18 : |
| | # -*- coding: latin-1 -*- | | # -*- coding: latin-1 -*- |
| | | | |
| − | # Voir: Contrôle de moteur pas-à-pas sur wiki.mchobby.be | + | # Traduction |
| − | # | + | # Contrôle de moteur pas-à-pas sur |
| | + | # http://mchobby.be/wiki/index.php?title=Rasp-Hack-Stepper |
| | + | # traduction CC-BY-SA par Meurisse D. pour www.mchobby.be |
| | + | # avec autorisation d'AdaFruit Industries USA. |
| | + | # |
| | + | # Source: |
| | + | # AdaFruit Industries USA, Réalisé par Simon Monk. |
| | + | # |
| | import RPi.GPIO as GPIO | | import RPi.GPIO as GPIO |
| | import time | | import time |
| Ligne 31 : |
Ligne 38 : |
| | coil_B_2_pin = 24 | | coil_B_2_pin = 24 |
| | | | |
| | + | # Configuration des broches de sorties |
| | + | # pour contrôle des bobines du moteur pas-à-pas |
| | GPIO.setup(enable_pin, GPIO.OUT) | | GPIO.setup(enable_pin, GPIO.OUT) |
| | GPIO.setup(coil_A_1_pin, GPIO.OUT) | | GPIO.setup(coil_A_1_pin, GPIO.OUT) |
| Ligne 37 : |
Ligne 46 : |
| | GPIO.setup(coil_B_2_pin, GPIO.OUT) | | GPIO.setup(coil_B_2_pin, GPIO.OUT) |
| | | | |
| | + | # Broche d'Activation (enabled) activée |
| | GPIO.output(enable_pin, 1) | | GPIO.output(enable_pin, 1) |
| | | | |
| | + | # |
| | + | # Définir Marche AVANT |
| | + | # |
| | + | # Paramètres: |
| | + | # delay - Délai d'attente entre deux activation de bobine. |
| | + | # Influence la vitesse. |
| | + | # steps - Nombre de pas à réaliser. |
| | + | # |
| | def forward(delay, steps): | | def forward(delay, steps): |
| | for i in range(0, steps): | | for i in range(0, steps): |
| − | setStep(1, 0, 1, 0) time.sleep(delay) | + | setStep(1, 0, 1, 0) |
| − | setStep(0, 1, 1, 0) time.sleep(delay) | + | time.sleep(delay) |
| − | setStep(0, 1, 0, 1) time.sleep(delay) | + | setStep(0, 1, 1, 0) |
| − | setStep(1, 0, 0, 1) time.sleep(delay) | + | time.sleep(delay) |
| | + | setStep(0, 1, 0, 1) |
| | + | time.sleep(delay) |
| | + | setStep(1, 0, 0, 1) |
| | + | time.sleep(delay) |
| | | | |
| | # | | # |
| − | # Marche Arrière | + | # Définir Marche ARRIERE |
| | # | | # |
| | def backwards(delay, steps): | | def backwards(delay, steps): |
| | for i in range(0, steps): | | for i in range(0, steps): |
| − | setStep(1, 0, 0, 1) time.sleep(delay) | + | setStep(1, 0, 0, 1) |
| − | setStep(0, 1, 0, 1) time.sleep(delay) | + | time.sleep(delay) |
| − | setStep(0, 1, 1, 0) time.sleep(delay) | + | setStep(0, 1, 0, 1) |
| − | setStep(1, 0, 1, 0) time.sleep(delay) | + | time.sleep(delay) |
| | + | setStep(0, 1, 1, 0) |
| | + | time.sleep(delay) |
| | + | setStep(1, 0, 1, 0) |
| | + | time.sleep(delay) |
| | | | |
| | + | # |
| | + | # Définir l'activation des différentes |
| | + | # bobines du moteur pas-à-pas en une seule |
| | + | # instruction |
| | + | # |
| | def setStep(w1, w2, w3, w4): | | def setStep(w1, w2, w3, w4): |
| − | GPIO.output(coil_A_1_pin, w1)
| + | GPIO.output(coil_A_1_pin, w1) |
| − | GPIO.output(coil_A_2_pin, w2)
| + | GPIO.output(coil_A_2_pin, w2) |
| − | GPIO.output(coil_B_1_pin, w3)
| + | GPIO.output(coil_B_1_pin, w3) |
| − | GPIO.output(coil_B_2_pin, w4)
| + | GPIO.output(coil_B_2_pin, w4) |
| | | | |
| | + | # |
| | + | # Boucle principale du programme |
| | + | # |
| | while True: | | while True: |
| − | delay = raw_input("Delay between steps (milliseconds)?") | + | delay = raw_input("Delais entre les pas (millisecondes)?") |
| − | steps = raw_input("How many steps forward? ") | + | steps = raw_input("Combien de pas en marche avant? ") |
| | forward(int(delay) / 1000.0, int(steps)) | | forward(int(delay) / 1000.0, int(steps)) |
| − | steps = raw_input("How many steps backwards? ") | + | steps = raw_input("Combien de pas en marche arrière? ") |
| | backwards(int(delay) / 1000.0, int(steps)) | | backwards(int(delay) / 1000.0, int(steps)) |
| − |
| |
| | </nowiki> | | </nowiki> |
| | | | |
| | | | |
| | {{Rasp-Hack-Stepper-TRAILER}} | | {{Rasp-Hack-Stepper-TRAILER}} |