Ligne 15 : |
Ligne 15 : |
| Running a stepper is a little more intricate than running a DC motor but its still very easy | | Running a stepper is a little more intricate than running a DC motor but its still very easy |
| | | |
− | == xx == | + | == Programmation == |
| + | |
| + | === Inclure la bibliothèque == |
| + | Assurez-vous d'avoir inclus les bibliothèques nécessaire à l'aide de l'instruction #include |
| + | |
| + | <nowiki>#include <Wire.h> |
| + | #include <Adafruit_MotorShield.h> |
| + | #include "utility/Adafruit_PWMServoDriver.h"</nowiki> |
| + | |
| + | === Créer un objet Adafruit_MotorShield === |
| + | |
| + | <nowiki>Adafruit_MotorShield AFMS = Adafruit_MotorShield();</nowiki> |
| + | |
| + | === Créer un objet "moteur pas-à-pas" === |
| + | Demander la création d'un objet Stepper (littéralement pas-à-pas) à Adafruit_MotorShield: |
| + | |
| + | <nowiki>Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);</nowiki> |
| + | |
| + | with '''getStepper(steps, stepper#)'''. '''Steps''' indicates how many steps per revolution the motor has. A 7.5degree/step motor has 360/7.5 = 48 steps. '''Stepper#''' is which port it is connected to. If you're using M1 and M2, its port '''1'''. If you're using M3 and M4 indicate port '''2''' |
| + | |
| + | === Initialiser la vitesse par défaut === |
| + | Set the speed of the motor using '''setSpeed(rpm)''' where rpm is how many revolutions per minute you want the stepper to turn. |
| + | |
| + | === Faire fonctionner le moteur === |
| + | Then every time you want the motor to move, call the '''step(#steps, direction, steptype)''' procedure. #steps is how many steps you'd like it to take. direction is either '''FORWARD''' or '''BACKWARD''' and the step type is '''SINGLE''', '''DOUBLE''', '''INTERLEAVE''' or '''MICROSTEP'''. |
| + | |
| + | * "Single" means single-coil activation |
| + | * "Double" means 2 coils are activated at once (for higher torque) |
| + | * "Interleave" means that it alternates between single and double to get twice the resolution (but of course its half the speed). |
| + | * "Microstepping" is a method where the coils are PWM'd to create smooth motion between steps. |
| + | |
| + | Theres tons of information about the pros and cons of these different stepping methods in the resources page. |
| + | |
| + | You can use whichever stepping method you want, changing it "on the fly" to as you may want minimum power, more torque, or more precision. |
| + | |
| + | By default, the motor will 'hold' the position after its done stepping. If you want to release all the coils, so that it can spin freely, call '''release()''' |
| + | |
| + | The stepping commands are 'blocking' and will return once the steps have finished. |
| + | |
| + | Because the stepping commands 'block' - you have to instruct the Stepper motors each time you want them to move. If you want to have more of a 'background task' stepper control, check out [https://github.com/adafruit/AccelStepper bibliothèque AccelStepper] sur le GitHub d'AdaFruit (install similarly to how you did with Adafruit_MotorShield) which has some examples for controlling three steppers simultaneously with varying acceleration |
| | | |
| {{Adafruit Motor Shield V2-TRAILER}} | | {{Adafruit Motor Shield V2-TRAILER}} |