issue113:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue113:python [2016/10/03 11:06] – créée auntiee | issue113:python [2016/10/10 19:11] (Version actuelle) – d52fr | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | This month, we will be using the RPi to control a simple DC Hobby motor. This can be obtained from most hobby stores, electronics suppliers, and even some big box hardware stores. Here is a “shopping list” of what we will be needing. | + | ===== 1 ===== |
+ | |||
+ | **This month, we will be using the RPi to control a simple DC Hobby motor. This can be obtained from most hobby stores, electronics suppliers, and even some big box hardware stores. Here is a “shopping list” of what we will be needing. | ||
• DC Hobby Motor | • DC Hobby Motor | ||
Ligne 12: | Ligne 14: | ||
First, NEVER EVER connect a motor of any kind directly to the RPi. You are asking for disaster. The current requirements can cause the RPi to “melt down”. The driver chip is less than $5.00 US and is a lot cheaper than a $39.00 RPi. | First, NEVER EVER connect a motor of any kind directly to the RPi. You are asking for disaster. The current requirements can cause the RPi to “melt down”. The driver chip is less than $5.00 US and is a lot cheaper than a $39.00 RPi. | ||
- | Second, we will discuss the L293D H-bridge motor driver for a few moments so you understand how this device works. | + | Second, we will discuss the L293D H-bridge motor driver for a few moments so you understand how this device works.** |
- | According to wikipedia, “An H bridge is an electronic circuit that enables a voltage to be applied across a load in either direction. These circuits are often used in robotics and other applications to allow DC motors to run forwards and backwards.” | + | Ce mois-ci, nous allons utiliser le RPi pour contrôler un simple moteur de loisirs à courant continu (DC). On peut se procurer celui-ci dans la plupart des boutiques de loisirs, des fournisseurs d' |
+ | |||
+ | • Moteur de loisirs DC. | ||
+ | • Puce de contrôle moteur à double pont en H L293D. | ||
+ | • 4 piles AA (ou AAA) et un support pour piles. | ||
+ | • Planche à essai. | ||
+ | • Des cavaliers mâle-mâle. | ||
+ | • Le RPi (bien entendu). | ||
+ | |||
+ | Avant de commencer le câblage et le codage, nous devons parler de deux ou trois choses. | ||
+ | |||
+ | Tout d' | ||
+ | |||
+ | Ensuite, nous discuterons du pilote de moteur L293D à pont en H pendant quelques instants pour que vous puissiez comprendre le fonctionnement de ce dispositif. | ||
+ | |||
+ | ===== 2 ===== | ||
+ | |||
+ | **According to wikipedia, “An H bridge is an electronic circuit that enables a voltage to be applied across a load in either direction. These circuits are often used in robotics and other applications to allow DC motors to run forwards and backwards.” | ||
Here is a pinout of the driver chip (“borrowed” from hardwarefun.com)... | Here is a pinout of the driver chip (“borrowed” from hardwarefun.com)... | ||
Ligne 24: | Ligne 43: | ||
• AND EITHER 1A OR 2A HIGH BUT NOT BOTH (chip pin 2 and pin 7 respectively) | • AND EITHER 1A OR 2A HIGH BUT NOT BOTH (chip pin 2 and pin 7 respectively) | ||
- | Now that we have decoded the logic of the magic chip, we can start to wire our breadboard and RPi. | + | Now that we have decoded the logic of the magic chip, we can start to wire our breadboard and RPi.** |
- | Wiring | + | Selon Wikipedia, « Un pont en H est un circuit électronique qui permet l' |
+ | |||
+ | Voici le brochage de la puce de pilotage (« emprunté » auprès de hardwarefun.com)... | ||
+ | |||
+ | Les broches 1 et 9 sont des broches enable (activation). Considérez-les comme des interrupteurs On/Off. Un état bas de la broche enable signifie que le moteur est éteint. Un état haut signifie que le moteur PEUT ÊTRE allumé. Regardons cela comme un tableau logique ou une table de vérité. Les broches 1A et 2A sont sur un côté de la puce et sont des lignes de contrôle comme les broches enable. La même logique s' | ||
+ | |||
+ | Le résultat du tableau dément ci-dessus est celui-ci : | ||
+ | Si vous voulez que le moteur s' | ||
+ | • l' | ||
+ | • ET L' | ||
+ | |||
+ | Ayant décodé la logique de la puce magique, nous pouvons commencer le câblage de la plaque d' | ||
+ | |||
+ | |||
+ | ===== 3 ===== | ||
+ | |||
+ | **Wiring | ||
The Fritzing drawing (next page, top right) shows our wiring diagram for this month. Notice that we are only using one half of the chip, so we could actually control two small DC motors instead of just one. That, however, will be up to you to experiment with. | The Fritzing drawing (next page, top right) shows our wiring diagram for this month. Notice that we are only using one half of the chip, so we could actually control two small DC motors instead of just one. That, however, will be up to you to experiment with. | ||
Ligne 36: | Ligne 71: | ||
The next Fritzing diagram (below) shows the battery and motor hook-ups. | The next Fritzing diagram (below) shows the battery and motor hook-ups. | ||
- | We are using the +5 VDC power from the RPi to power the motor driver chip (RPi pin 2 to L293D pin 16). While the above diagram shows AAA batteries, you can use a battery pack that uses AA batteries as well. We are also providing Ground from the RPi (pin 6) to the chip (pins 4,5,12,13). The motor is driven on chip pin 3 (1A) and pin 5 (2A). The battery connects to chip pin 8 to provide the voltage for the motor. | + | We are using the +5 VDC power from the RPi to power the motor driver chip (RPi pin 2 to L293D pin 16). While the above diagram shows AAA batteries, you can use a battery pack that uses AA batteries as well. We are also providing Ground from the RPi (pin 6) to the chip (pins 4,5,12,13). The motor is driven on chip pin 3 (1A) and pin 5 (2A). The battery connects to chip pin 8 to provide the voltage for the motor.** |
- | Code | + | Câblage |
+ | |||
+ | Le dessin Fritzing (en haut à droite de la page suivante) montre le diagramme de câblage pour ce mois-ci. Remarquez que nous n' | ||
+ | |||
+ | Comme toujours, connectez les câbles au RPi AVANT de l' | ||
+ | |||
+ | Cette première image Fritzing montre les connexions au RPi et à la plaque d' | ||
+ | |||
+ | Le diagramme Fritzing suivant (ci-dessous) montre les connexions entre la batterie et le moteur. | ||
+ | |||
+ | Nous utilisons l' | ||
+ | |||
+ | ===== 4 ===== | ||
+ | |||
+ | **Code | ||
We will deal with code in two programs. The first simply turns on the motor, runs for a few seconds then stops it. The second is a modified version of the first that shows how to reverse the motor. | We will deal with code in two programs. The first simply turns on the motor, runs for a few seconds then stops it. The second is a modified version of the first that shows how to reverse the motor. | ||
Ligne 58: | Ligne 107: | ||
Well, that’s it for this month. Next month, we will be working with servos. All you need is a small inexpensive one with three wires. We will not be using parts from this month’s project, but keep them for future projects. | Well, that’s it for this month. Next month, we will be working with servos. All you need is a small inexpensive one with three wires. We will not be using parts from this month’s project, but keep them for future projects. | ||
- | Until then, have fun. | + | Until then, have fun.** |
+ | |||
+ | Code | ||
+ | |||
+ | Nous allons traiter le code dans deux programmes. Le premier allume le moteur, le laisse tourner pendant quelques secondes, puis l' | ||
+ | |||
+ | Dcmotor1.py | ||
+ | |||
+ | Ce programme (ci-dessous) allumera tout simplement le moteur en marche avant (dans le sens des aiguilles d'une montre), le laissera tourner, puis l' | ||
+ | |||
+ | Dcmotor2.py | ||
+ | |||
+ | Dans ce programme (page suivante), nous réglons les broches GPIO comme nous l' | ||
+ | |||
+ | En marche avant, plus le rapport cyclique est long (plus près de 100), plus le moteur tournera vite. | ||
+ | |||
+ | En marche arrière, plus le rapport cyclique est COURT (plus près de 0), plus vite tournera le moteur. | ||
+ | |||
+ | Nous accélérons le moteur en réglant le rapport cyclique sur un FAIBLE pourcentage, | ||
+ | |||
+ | C'est tout pour ce mois-ci. Le mois prochain, nous allons travailler avec des servos. Tout ce dont vous aurez besoin est un petit servo peu cher avec trois fils. Nous n' | ||
+ | |||
+ | Jusque-là, amusez-vous bien. |
issue113/python.1475485598.txt.gz · Dernière modification : 2016/10/03 11:06 de auntiee