Bonjour tous le monde !
Dans mon projet j’ai 3 moteurs XYZ pas à pas.
Je souhaiterai pouvoir en désactivé 1-2-ou 3 celon mes besoins.
J’utilise la librairie AccelStepper (Doc anglais ICI) (Doc trad Google ICI)
Je suis assez débutant. J’avoue ne pas comprendre…
Il semblerait que j’aurai besoin de 3 ou 4 fonctions :
◆ disableOutputs()
◆ enableOutputs()
◆ setEnablePin()
◆ setPinsInverted()
Les explications sont :
◆ disableOutputs()
void AccelStepper::disableOutputs()
Disable motor pin outputs by setting them all LOW Depending on the design of your electronics this may turn off the power to the motor coils, saving power. This is useful to support Arduino low power modes: disable the outputs during sleep and then reenable with enableOutputs() before stepping again. If the enable Pin is defined, sets it to OUTPUT mode and clears the pin to disabled.
References setOutputPins().
◆ enableOutputs()
void AccelStepper::enableOutputs()
Enable motor pin outputs by setting the motor pins to OUTPUT mode. Called automatically by the constructor. If the enable Pin is defined, sets it to OUTPUT mode and sets the pin to enabled.
References FULL3WIRE, FULL4WIRE, HALF3WIRE, and HALF4WIRE.
Referenced by AccelStepper().
◆ setEnablePin()
void AccelStepper::setEnablePin (uint8_t enablePin = 0xff)
Sets the enable pin number for stepper drivers. 0xFF indicates unused (default). Otherwise, if a pin is set, the pin will be turned on when enableOutputs() is called and switched off when disableOutputs() is called.
Parameters : [in] enablePin Arduino digital pin number for motor enable
See also
setPinsInverted
◆ setPinsInverted() [1/2]
void AccelStepper::setPinsInverted ( bool directionInvert = false,
bool stepInvert = false,
bool enableInvert = false
)
Sets the inversion for stepper driver pins
Parameters
[in] directionInvert True for inverted direction pin, false for non-inverted
[in] stepInvert True for inverted step pin, false for non-inverted
[in] enableInvert True for inverted enable pin, false (default) for non-inverted
◆ setPinsInverted() [2/2]
void AccelStepper::setPinsInverted ( bool pin1Invert,
bool pin2Invert,
bool pin3Invert,
bool pin4Invert,
bool enableInvert
)
Sets the inversion for 2, 3 and 4 wire stepper pins
Parameters
[in] pin1Invert True for inverted pin1, false for non-inverted
[in] pin2Invert True for inverted pin2, false for non-inverted
[in] pin3Invert True for inverted pin3, false for non-inverted
[in] pin4Invert True for inverted pin4, false for non-inverted
[in] enableInvert True for inverted enable pin, false (default) for non-inverted
J’ai trouvé un bout de code simple que j’ai modifié (tests sur 1 seul moteur) :
#include <AccelStepper.h>
#define ZdirPin 7 // Moteur Z -> Direction pin 7
#define ZstepPin 4 // Moteur Z -> Stepper pin 4
#define motorInterfaceType 1 // Interface 1 pour le Driver A4988
AccelStepper moteurZ = AccelStepper(motorInterfaceType, ZstepPin, ZdirPin); //Creé instance avec nom du moteurZ
void setup() {
moteurZ.setMaxSpeed(1000);
moteurZ.setAcceleration(100);
moteurZ.setEnablePin(8); // Pin 8 relié pin "EN" A4988
moteurZ.setPinsInverted(false, false, true);
moteurZ.move(10000);
}
void loop() {
moteurZ.runToPosition();
moteurZ.disableOutputs();
}
Le moteur tourne bien, s’arrête et ne repart plus.
Mais il reste toujours bloqué, alimenté.
Mon matériel :
Carte Mega
Shield CNC V3
Driver A4988
Librairie AccelStepper
Quand pensez-vous ?







