issue115:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue115:python [2016/11/29 09:10] – créée d52fr | issue115:python [2016/12/10 15:35] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ===== 1 ===== | ||
+ | ** | ||
Welcome back for another entry into what I lovingly call ‘Greg’s Python Folly’. As promised, we will be working on interfacing a stepper motor to the Raspberry Pi. You will need your Raspberry Pi, a hobby stepper motor, a 4 x AA size battery pack, the L293D driver chip we used previously, a breadboard, and some jumpers. | Welcome back for another entry into what I lovingly call ‘Greg’s Python Folly’. As promised, we will be working on interfacing a stepper motor to the Raspberry Pi. You will need your Raspberry Pi, a hobby stepper motor, a 4 x AA size battery pack, the L293D driver chip we used previously, a breadboard, and some jumpers. | ||
Ligne 6: | Ligne 8: | ||
Now, let’s examine stepper motors in general, then we’ll expand that information to the 28BJY specifically and work on interfacing it to the Pi through our L293D driver chip. | Now, let’s examine stepper motors in general, then we’ll expand that information to the 28BJY specifically and work on interfacing it to the Pi through our L293D driver chip. | ||
+ | ** | ||
+ | |||
+ | Bienvenue de nouveau dans ce que j' | ||
+ | |||
+ | Alors que je faisais des recherches pour ce projet-ci, je suis tombé sur un guide sur tutorials-raspberrypi.de. J'ai été tellement impressionné par les informations de ce site web que j' | ||
+ | |||
+ | Le moteur choisi est un mini-moteur pas-à-pas Radio Shack. En fait, c'est un moteur basse tension 28BJY-48. Avant d' | ||
+ | |||
+ | Bon, regardons d' | ||
+ | |||
+ | ** | ||
Stepper Motors | Stepper Motors | ||
Ligne 18: | Ligne 31: | ||
Turning on each coil one at a time will cause the magnet in the rotor to turn toward the proper coil. Using a clock face as a guide, turning on the coils in the sequence of 12 o’clock, 3 o’clock, 6 o’clock, 9 o’clock and then again at 12 o’clock will cause the rotor to turn clockwise one full rotation. This requires 4 “steps” to make one rotation. This is called the Unipolar wave. If we go a bit further, we could make a more granular movement by alternating the coils from a single coil turned on and then turning on the next coil as well, which makes the rotor turn in an eighth turn when both coils are turned on. The sequence would then be: 12, 12 and 3, 3, 3 and 6, 6, 6 and 9, 9, 9 and 12, and then finally 12 alone again. This then is 8 steps per rotation which is called half stepping. To make the motor reverse (counter-clockwise), | Turning on each coil one at a time will cause the magnet in the rotor to turn toward the proper coil. Using a clock face as a guide, turning on the coils in the sequence of 12 o’clock, 3 o’clock, 6 o’clock, 9 o’clock and then again at 12 o’clock will cause the rotor to turn clockwise one full rotation. This requires 4 “steps” to make one rotation. This is called the Unipolar wave. If we go a bit further, we could make a more granular movement by alternating the coils from a single coil turned on and then turning on the next coil as well, which makes the rotor turn in an eighth turn when both coils are turned on. The sequence would then be: 12, 12 and 3, 3, 3 and 6, 6, 6 and 9, 9, 9 and 12, and then finally 12 alone again. This then is 8 steps per rotation which is called half stepping. To make the motor reverse (counter-clockwise), | ||
+ | ** | ||
+ | |||
+ | Les moteurs pas-à-pas | ||
+ | |||
+ | Les moteurs pas-à-pas sont utilisés en robotique et dans les machines à commande numérique lorsque vous voulez pouvoir facilement bouger un objet vers un endroit précis. Il y a deux types de base de moteurs pas-à-pas, un appelé unipolaire et l' | ||
+ | |||
+ | Dans les deux cas, il y a un certain nombre de bobines électromagnétiques qui sont allumées et coupées successivement pour faire tourner le moteur. Chaque fois que nous alimentons l'une des bobines, le moteur tourne un petit peu (si alimenté dans la séquence correcte pour le moteur). On appelle cela un pas, d'où le nom de moteur pas-à-pas. | ||
+ | |||
+ | Moteurs Unipolaires | ||
+ | |||
+ | Les moteurs unipolaires possèdent des bobines alimentées dans une seule direction : le UNI de unipolaire. Le rotor du moteur est contrôlé en alimentant, puis coupant, les différentes bobines dans une séquence spécifique pendant un certain temps. Voici un diagramme simplifié de ce modèle : | ||
+ | |||
+ | Alimenter chaque bobine, une à la fois, va faire que l' | ||
+ | |||
+ | ===== 2 ===== | ||
+ | ** | ||
Bipolar Motors | Bipolar Motors | ||
Ligne 37: | Ligne 66: | ||
Since the central component in this project is the L293D driver chip, here is a quick breakdown to try to make things easier for you... | Since the central component in this project is the L293D driver chip, here is a quick breakdown to try to make things easier for you... | ||
+ | ** | ||
+ | Moteurs bipolaires | ||
+ | |||
+ | Le 28BJY, comme dit précédemment, | ||
+ | |||
+ | Les numéros montrés avec les couleurs des fils sont pour le 28BJY et les vôtres peuvent être différents. Le connecteur des fils (s'il y en a un) peut être différent d'une unité à l' | ||
+ | |||
+ | Le câblage | ||
+ | |||
+ | Un léger avertissement avant de commencer. | ||
+ | |||
+ | Tout d' | ||
+ | |||
+ | Deuxièmement, | ||
+ | |||
+ | Quand vous regardez le plan, ça semble plutôt simple (et ça l' | ||
+ | |||
+ | Puisque le composant principal dans ce projet est la puce de commande L293D, voici un petit plan pour essayer de vous faciliter la tâche : | ||
+ | |||
+ | ** | ||
L293D | L293D | ||
Pin 1 -> Pin 9 | Pin 1 -> Pin 9 | ||
Ligne 71: | Ligne 120: | ||
coil_B_1_pin = 23 # blue | coil_B_1_pin = 23 # blue | ||
coil_B_2_pin = 24 # yellow | coil_B_2_pin = 24 # yellow | ||
+ | ** | ||
+ | L293D | ||
+ | Pin 1 -> Pin 9 | ||
+ | Pin 2 -> Pi GPIO 6 | ||
+ | Pin 3 -> Moteur rose | ||
+ | Pin 4 -> Rail négatif de la plaque | ||
+ | Pin 5 -> Non connecté | ||
+ | Pin 6 -> Moteur orange | ||
+ | Pin 7 -> Pi GPIO 5 | ||
+ | Pin 8 -> Rail positif de la plaque | ||
+ | Pin 9 -> Pin 1 | ||
+ | Pin 10 -> PI GPIO 23 | ||
+ | Pin 11 -> Moteur jaune | ||
+ | Pin 12 -> Non connecté | ||
+ | Pin 13 -> Non connecté | ||
+ | Pin 14 -> Moteur bleu | ||
+ | Pin 15 -> Pi GPio 24 | ||
+ | Pin 16 -> Pi +5VDC | ||
+ | |||
+ | Si vous respectez cela, vous ne devrez pas avoir de problème avec les fils. | ||
+ | |||
+ | Le code | ||
+ | |||
+ | Comme toujours, je vais parler du code par blocs. Allons-y. | ||
+ | |||
+ | import RPi.GPIO as GPIO | ||
+ | import time | ||
+ | |||
+ | GPIO.setmode(GPIO.BCM) | ||
+ | GPIO.setwarnings(False) | ||
+ | coil_A_1_pin = 6 # rose | ||
+ | coil_A_2_pin = 5 # orange | ||
+ | coil_B_1_pin = 23 # bleu | ||
+ | coil_B_2_pin = 24 # jaune | ||
+ | |||
+ | |||
+ | ===== 3 ===== | ||
+ | ** | ||
Here we are simply defining the imports, setting the GPIO mode, and setting the warnings to False so we don’t get any nagging notices about already initialized pins. We also define which GPIO pins control the motor coils through the driver chip. | Here we are simply defining the imports, setting the GPIO mode, and setting the warnings to False so we don’t get any nagging notices about already initialized pins. We also define which GPIO pins control the motor coils through the driver chip. | ||
Ligne 100: | Ligne 187: | ||
GPIO.output(coil_B_1_pin, | GPIO.output(coil_B_1_pin, | ||
GPIO.output(coil_B_2_pin, | GPIO.output(coil_B_2_pin, | ||
+ | ** | ||
+ | Ici, nous ne définissons que les imports, nous paramétrons le mode GPIO (entrée/ | ||
+ | |||
+ | # adaptez si c'est différent | ||
+ | StepCount = 8 | ||
+ | Seq = range(0, StepCount) | ||
+ | Seq[0] = [0,1,0,0] | ||
+ | Seq[1] = [0,1,0,1] | ||
+ | Seq[2] = [0,0,0,1] | ||
+ | Seq[3] = [1,0,0,1] | ||
+ | Seq[4] = [1,0,0,0] | ||
+ | Seq[5] = [1,0,1,0] | ||
+ | Seq[6] = [0,0,1,0] | ||
+ | Seq[7] = [0,1,1,0] | ||
+ | |||
+ | Et voici la clé permettant de faire fonctionner notre projet. Ce moteur veut 8 pas (internes) par tour de moteur (selon la doc.). Nous définissons également la séquence des bobines qui seront alimentées à chaque pas, sous la forme d'une série de listes. Chaque liste indique quelle bobine est alimentée à un moment donné. | ||
+ | |||
+ | GPIO.setup(coil_A_1_pin, | ||
+ | GPIO.setup(coil_A_2_pin, | ||
+ | GPIO.setup(coil_B_1_pin, | ||
+ | GPIO.setup(coil_B_2_pin, | ||
+ | |||
+ | Ici nous faisons le paramétrage, | ||
+ | |||
+ | def setStep(w1, w2, w3, w4): | ||
+ | GPIO.output(coil_A_1_pin, | ||
+ | GPIO.output(coil_A_2_pin, | ||
+ | GPIO.output(coil_B_1_pin, | ||
+ | GPIO.output(coil_B_2_pin, | ||
+ | |||
+ | ** | ||
This subroutine is called each time we want to step the motor and we pass a 0 or 1 to each coil wire port on the driver chip to energize or deenergize the various coils to turn the rotor. | This subroutine is called each time we want to step the motor and we pass a 0 or 1 to each coil wire port on the driver chip to energize or deenergize the various coils to turn the rotor. | ||
Ligne 114: | Ligne 232: | ||
Until then, keep learning and above all, HAVE FUN! | Until then, keep learning and above all, HAVE FUN! | ||
+ | ** | ||
+ | |||
+ | Cette sous-routine est appelée chaque fois que nous voulons faire avancer le moteur d'un pas, et nous transmettons un 0 ou un 1 à chaque broche de fil de bobine sur la puce de commande pour alimenter ou pas les différentes bobines pour faire tourner le rotor. | ||
+ | |||
+ | Et enfin notre fonction « main » (principale) qui boucle sans cesse en demandant la quantité de temps et le nombre de pas dans cette direction donnée. Pour mon moteur, il faut 512 pas pour faire presque une rotation complète. | ||
+ | |||
+ | Sur mon système, avec mon moteur, un délai de 1 ms fonctionne bien. Mais vous devrez peut-être ajouter quelques millisecondes au vôtre pour qu'il fonctionne. | ||
+ | |||
+ | Notez que j'ai dit qu'il fallait 512 pas pour faire PRESQUE une rotation complète. Ce moteur a un rapport d' | ||
+ | |||
+ | Si vous voulez en apprendre plus sur les moteurs pas-à-pas, adafruit.com propose un chouette petit article sur le sujet. | ||
+ | |||
+ | J' | ||
+ | |||
+ | En attendant, continuez d' | ||
+ | |||
+ | ** | ||
+ | Encadré de la page 19, texte en noir : | ||
+ | |||
+ | These two routines allow for easily commanding the motor forwards or backwards a specific number of steps in the proper direction. | ||
+ | ** | ||
+ | |||
+ | Encadré de la page 19, texte en noir : | ||
+ | |||
+ | Ces deux fonctions permettent, pour commander facilement le moteur en avant ou en arrière, un nombre spécifique de pas dans la direction appropriée. | ||
+ | |||
+ |
issue115/python.1480407041.txt.gz · Dernière modification : 2016/11/29 09:10 de d52fr