Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
documentation:electronique:modules_kits:em483_stepper:index [2021/05/12 15:03] – f1sls | documentation:electronique:modules_kits:em483_stepper:index [2021/05/19 02:33] (Version actuelle) – f1sls | ||
---|---|---|---|
Ligne 6: | Ligne 6: | ||
===== WIRING ===== | ===== WIRING ===== | ||
{{: | {{: | ||
+ | |||
+ | {{: | ||
+ | {{: | ||
+ | ===== ARDUINO ===== | ||
+ | ==== LIBS ==== | ||
+ | * https:// | ||
+ | |||
+ | ==== SAMPLES ==== | ||
+ | {{: | ||
+ | <code cpp> | ||
+ | #define ButonControl 4 | ||
+ | #include < | ||
+ | |||
+ | |||
+ | NonBlockingMotor motor(4, 7, 5, 6); | ||
+ | |||
+ | int degreRotate = 900; | ||
+ | int degreRotateBack = 330; | ||
+ | |||
+ | |||
+ | long f1(long x){ | ||
+ | | ||
+ | } | ||
+ | |||
+ | unsigned long currentTime = 0; | ||
+ | unsigned long newTime = 0; | ||
+ | |||
+ | void on_reached(long steps){ } // to get number of steps use println | ||
+ | |||
+ | boolean dataBtn ; | ||
+ | |||
+ | void setup() { | ||
+ | // put your setup code here, to run once: | ||
+ | // initialise step motor | ||
+ | motor.init(); | ||
+ | motor.set_time_between_pulses(2000); | ||
+ | motor.set_conversion_function(f1); | ||
+ | motor.set_on_destination_reached(on_reached); | ||
+ | pinMode(ButonControl, | ||
+ | | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | | ||
+ | |||
+ | | ||
+ | motor.set_destination(degreRotate); | ||
+ | motor.status = CW; // OR CCV to rotate back | ||
+ | } | ||
+ | |||
+ | |||
+ | if( dataBtn== 1) | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | | ||
+ | | ||
+ | |||
+ | if(millis() % 4000 == 0){ // this need because L293D Get realy hot so to prevent bourning the skheme : | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | // motor get hot and for this we will need to make all the pins to LOW to avoid HOT | ||
+ | void waitModeMotor(){ | ||
+ | digitalWrite(4, | ||
+ | digitalWrite(5, | ||
+ | digitalWrite(6, | ||
+ | digitalWrite(7, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <code cpp> | ||
+ | ////////////////////////////////////////////////////////////////// | ||
+ | //©2011 bildr | ||
+ | //Released under the MIT License - Please reuse change and share | ||
+ | //Using the easy stepper with your arduino | ||
+ | //use rotate and/or rotateDeg to controll stepper motor | ||
+ | //speed is any number from .01 -> 1 with 1 being fastest - | ||
+ | //Slower Speed == Stronger movement | ||
+ | ///////////////////////////////////////////////////////////////// | ||
+ | |||
+ | |||
+ | #define DIR_PIN 2 | ||
+ | #define STEP_PIN 3 | ||
+ | |||
+ | void setup() { | ||
+ | pinMode(DIR_PIN, | ||
+ | pinMode(STEP_PIN, | ||
+ | } | ||
+ | |||
+ | void loop(){ | ||
+ | |||
+ | rotateDeg(360, | ||
+ | delay(1000); | ||
+ | rotateDeg(-360, | ||
+ | delay(1000); | ||
+ | |||
+ | |||
+ | |||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | void rotate(int steps, float speed){ | ||
+ | //rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement) | ||
+ | //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger | ||
+ | int dir = (steps > 0)? HIGH:LOW; | ||
+ | steps = abs(steps); | ||
+ | |||
+ | digitalWrite(DIR_PIN, | ||
+ | |||
+ | float usDelay = (1/speed) * 70; | ||
+ | |||
+ | for(int i=0; i < steps; i++){ | ||
+ | digitalWrite(STEP_PIN, | ||
+ | delayMicroseconds(usDelay); | ||
+ | |||
+ | digitalWrite(STEP_PIN, | ||
+ | delayMicroseconds(usDelay); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void rotateDeg(float deg, float speed){ | ||
+ | //rotate a specific number of degrees (negitive for reverse movement) | ||
+ | //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger | ||
+ | int dir = (deg > 0)? HIGH:LOW; | ||
+ | digitalWrite(DIR_PIN, | ||
+ | |||
+ | int steps = abs(deg)*(1/ | ||
+ | float usDelay = (1/speed) * 70; | ||
+ | |||
+ | for(int i=0; i < steps; i++){ | ||
+ | digitalWrite(STEP_PIN, | ||
+ | delayMicroseconds(usDelay); | ||
+ | |||
+ | digitalWrite(STEP_PIN, | ||
+ | delayMicroseconds(usDelay); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== BIPOLAR STEPPER WITH H BRIDGE ===== | ||
+ | <code cpp> | ||
+ | /* | ||
+ | Stepper Motor Demonstration 3 | ||
+ | Stepper-Demo3.ino | ||
+ | Demonstrates NEMA 17 Bipolar Stepper with L298N Driver | ||
+ | Uses Potentiometer on Analog Input A0 | ||
+ | Uses Arduino Stepper Library | ||
+ | |||
+ | DroneBot Workshop 2018 | ||
+ | https:// | ||
+ | */ | ||
+ | |||
+ | // Include the Arduino Stepper Library | ||
+ | #include < | ||
+ | |||
+ | // Define Constants | ||
+ | |||
+ | // Number of steps per output rotation | ||
+ | const int STEPS_PER_REV = 200; | ||
+ | const int SPEED_CONTROL = A0; | ||
+ | |||
+ | // Create Instance of Stepper Class | ||
+ | // Specify Pins used for motor coils | ||
+ | // The pins used are 8, | ||
+ | // Connected to L298N Motor Driver In1, In2, In3, In4 | ||
+ | // Pins entered in sequence 1-2-3-4 for proper step sequencing | ||
+ | |||
+ | Stepper stepper_NEMA17(STEPS_PER_REV, | ||
+ | |||
+ | void setup() { | ||
+ | // nothing to do inside the setup | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // read the sensor value: | ||
+ | int sensorReading = analogRead(SPEED_CONTROL); | ||
+ | // map it to a range from 0 to 100: | ||
+ | int motorSpeed = map(sensorReading, | ||
+ | // set the motor speed: | ||
+ | if (motorSpeed > 0) { | ||
+ | stepper_NEMA17.setSpeed(motorSpeed); | ||
+ | // step 1/100 of a revolution: | ||
+ | stepper_NEMA17.step(STEPS_PER_REV / 100); | ||
+ | } | ||
+ | } | ||
+ | </ |