From: Andrea Manni Date: Mon, 25 May 2015 17:21:53 +0000 (+0200) Subject: step motors X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;h=daadffcffaf4c0618a6008c7582ceb92aaae64ed;p=sketchbook_andrea step motors --- diff --git a/README b/README index 5f7f14d..e340305 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ Sketchbook di Andrea ===================== -Esempi per i corsi su Arduino. +Codice esempi per i corsi su Arduino. Le ultime versioni sono disponibili su: git.andreamanni.com - http://git.andreamanni.com/ - Interfaccia web: http://git.andreamanni.com/web diff --git a/motors/reverse_L293D_5/reverse_L293D_5.ino b/motors/reverse_L293D_5/reverse_L293D_5.ino new file mode 100644 index 0000000..a13a368 --- /dev/null +++ b/motors/reverse_L293D_5/reverse_L293D_5.ino @@ -0,0 +1,39 @@ + /* + Adafruit Arduino - Lesson 15. Bi-directional Motor + + Pilotare un motore DC brushed con un H-bridge mediante + un integrato L293D + + + Schemi e istruzioni: + - https://learn.adafruit.com/adafruit-arduino-lesson-15-dc-motor-reversing/overview + + */ + + int enablePin = 11; + int in1Pin = 10; + int in2Pin = 9; + int switchPin = 7; + int potPin = 0; + + void setup() + { + pinMode(in1Pin, OUTPUT); + pinMode(in2Pin, OUTPUT); + pinMode(enablePin, OUTPUT); + pinMode(switchPin, INPUT_PULLUP); + } + + void loop() + { + int speed = analogRead(potPin) / 4; + boolean reverse = digitalRead(switchPin); + setMotor(speed, reverse); + } + + void setMotor(int speed, boolean reverse) + { + analogWrite(enablePin, speed); + digitalWrite(in1Pin, ! reverse); + digitalWrite(in2Pin, reverse); + } diff --git a/motors/simple_motor_PWM_potenziometer__minimum_transistor_diode_3/simple_motor_PWM_potenziometer__minimum_transistor_diode_3.ino b/motors/simple_motor_PWM_potenziometer__minimum_transistor_diode_3/simple_motor_PWM_potenziometer__minimum_transistor_diode_3.ino index 4e68000..d73ec6f 100644 --- a/motors/simple_motor_PWM_potenziometer__minimum_transistor_diode_3/simple_motor_PWM_potenziometer__minimum_transistor_diode_3.ino +++ b/motors/simple_motor_PWM_potenziometer__minimum_transistor_diode_3/simple_motor_PWM_potenziometer__minimum_transistor_diode_3.ino @@ -1,8 +1,10 @@ /* Simple Motor : Potenziometro con minimo - + Motore DC con variazione della velocita' impostata - tramite un potenziometro 10k ohms + tramite un potenziometro 10k ohms, + settato un valore minimo sotto il quale il motore + non viene attivato. Schema: http://lab.piffa.net/schemi/motor_pot_bb.png diff --git a/motors/simple_motor_PWM_potenziometer_transistor_diode_2/simple_motor_PWM_potenziometer_transistor_diode_2.ino b/motors/simple_motor_PWM_potenziometer_transistor_diode_2/simple_motor_PWM_potenziometer_transistor_diode_2.ino index 9e60b45..9a43bcd 100644 --- a/motors/simple_motor_PWM_potenziometer_transistor_diode_2/simple_motor_PWM_potenziometer_transistor_diode_2.ino +++ b/motors/simple_motor_PWM_potenziometer_transistor_diode_2/simple_motor_PWM_potenziometer_transistor_diode_2.ino @@ -34,7 +34,7 @@ void loop() { /* Domande -1. Cosa succede quando il motore ha riceve un carico molto basso? +1. Cosa succede quando il motore riceve poca corrente? 2. Impostare un valore minimo per la partenza del motore, sotto al quale il motore non parte. */ diff --git a/motors/simple_motor_PWM_potenziometer_transistor_diode_2_soluzione/simple_motor_PWM_potenziometer_transistor_diode_2_soluzione.ino b/motors/simple_motor_PWM_potenziometer_transistor_diode_2_soluzione/simple_motor_PWM_potenziometer_transistor_diode_2_soluzione.ino index 872d474..1094bb8 100644 --- a/motors/simple_motor_PWM_potenziometer_transistor_diode_2_soluzione/simple_motor_PWM_potenziometer_transistor_diode_2_soluzione.ino +++ b/motors/simple_motor_PWM_potenziometer_transistor_diode_2_soluzione/simple_motor_PWM_potenziometer_transistor_diode_2_soluzione.ino @@ -33,7 +33,7 @@ void loop() { if (motValue > 60) { // Valore minimo per far partire il motore analogWrite(motorPin,motValue); // } - else analogWrite(motorPin,0); // Se non super il valore minimo + else analogWrite(motorPin,0); // Se non supera il valore minimo // deve restare fermo delay(3); // Pause, stabilizza la lettura del Pot diff --git a/motors/stepper/cdrom_stepper/cdrom_stepper.ino b/motors/stepper/cdrom_stepper/cdrom_stepper.ino new file mode 100644 index 0000000..dfbc399 --- /dev/null +++ b/motors/stepper/cdrom_stepper/cdrom_stepper.ino @@ -0,0 +1,41 @@ + +/* + CDROM stepper + + Pilotare lo step di un lettore CDROM mediante + il motor shield. + + - http://wiki.piffa.net/index.php/CNC_ROM + +Pin on top, plastica sotto + + 1 2 2 5 1 3 1 e' il piu' vicino al capacitor + 3 4 + +*/ + +#include + +// Connect a stepper motor with 48 steps per revolution (7.5 degree) +// to motor port #2 (M3 and M4) +AF_Stepper motor(200, 2); //Motor with 200 steps per rev (1.8 degree) + +void setup() { + Serial.begin(9600); // set up Serial library at 9600 bps + Serial.println("Stepper test!"); + + motor.setSpeed(20); // max 400 +} + +void loop() { + + //motor.step(340, FORWARD, MICROSTEP); + //motor.step(340, BACKWARD, MICROSTEP); + + for (int lenght = 340; lenght > 40; lenght -= 40) + { + motor.step(lenght, FORWARD, MICROSTEP); + motor.step(lenght - 20, BACKWARD, MICROSTEP); + } + motor.step(150, BACKWARD, MICROSTEP); +} diff --git a/motors/stepper/step_1_single_step_raw/step_1_single_step_raw.ino b/motors/stepper/step_1_single_step_raw/step_1_single_step_raw.ino new file mode 100644 index 0000000..bea37e3 --- /dev/null +++ b/motors/stepper/step_1_single_step_raw/step_1_single_step_raw.ino @@ -0,0 +1,132 @@ + + +/* + BYJ48 Stepper motor code + Connect : + IN1 >> D8 + IN2 >> D9 + IN3 >> D10 + IN4 >> D11 + VCC ... 5V Prefer to use external 5V Source + Gnd + written By :Mohannad Rawashdeh + http://www.instructables.com/member/Mohannad+Rawashdeh/ + 28/9/2013 + */ + +#define IN1 8 +#define IN2 9 +#define IN3 10 +#define IN4 11 +int Steps = 0; +boolean Direction = true;// gre +unsigned long last_time; +unsigned long currentMillis ; +int steps_left=4095; +long time; +void setup() +{ + Serial.begin(115200); + pinMode(IN1, OUTPUT); + pinMode(IN2, OUTPUT); + pinMode(IN3, OUTPUT); + pinMode(IN4, OUTPUT); + // delay(1000); + +} +void loop() +{ + while(steps_left>0){ + currentMillis = micros(); + if(currentMillis-last_time>=1000){ + stepper(1); + time=time+micros()-last_time; + last_time=micros(); + steps_left--; + } + } + Serial.println(time); + Serial.println("Wait...!"); + delay(2000); + Direction=!Direction; + steps_left=4095; +} + +void stepper(int xw){ + // Impostato ad Half Steps + for (int x=0;x7){ + Steps=0; + } + if(Steps<0){ + Steps=7; + } +} + + diff --git a/motors/stepper/step_2_full_step_raw/step_2_full_step_raw.ino b/motors/stepper/step_2_full_step_raw/step_2_full_step_raw.ino new file mode 100644 index 0000000..27fe70b --- /dev/null +++ b/motors/stepper/step_2_full_step_raw/step_2_full_step_raw.ino @@ -0,0 +1,132 @@ + + +/* + BYJ48 Stepper motor code + Connect : + IN1 >> D8 + IN2 >> D9 + IN3 >> D10 + IN4 >> D11 + VCC ... 5V Prefer to use external 5V Source + Gnd + written By :Mohannad Rawashdeh + http://www.instructables.com/member/Mohannad+Rawashdeh/ + 28/9/2013 + */ + +#define IN1 8 +#define IN2 9 +#define IN3 10 +#define IN4 11 +int Steps = 0; +boolean Direction = true;// gre +unsigned long last_time; +unsigned long currentMillis ; +int steps_left=4095; +long time; +void setup() +{ + Serial.begin(115200); + pinMode(IN1, OUTPUT); + pinMode(IN2, OUTPUT); + pinMode(IN3, OUTPUT); + pinMode(IN4, OUTPUT); + // delay(1000); + +} +void loop() +{ + while(steps_left>0){ + currentMillis = micros(); + if(currentMillis-last_time>=1000){ + stepper(1); + time=time+micros()-last_time; + last_time=micros(); + steps_left--; + } + } + Serial.println(time); + Serial.println("Wait...!"); + delay(2000); + Direction=!Direction; + steps_left=4095; +} + +void stepper(int xw){ + // Impostato ad Half Steps + for (int x=0;x7){ + Steps=0; + } + if(Steps<0){ + Steps=7; + } +} + + diff --git a/motors/stepper/step_3_half_step/step_3_half_step.ino b/motors/stepper/step_3_half_step/step_3_half_step.ino new file mode 100644 index 0000000..3f1c85c --- /dev/null +++ b/motors/stepper/step_3_half_step/step_3_half_step.ino @@ -0,0 +1,131 @@ + + +/* + BYJ48 Stepper motor code + Connect : + IN1 >> D8 + IN2 >> D9 + IN3 >> D10 + IN4 >> D11 + VCC ... 5V Prefer to use external 5V Source + Gnd + written By :Mohannad Rawashdeh + http://www.instructables.com/member/Mohannad+Rawashdeh/ + 28/9/2013 + */ + +#define IN1 8 +#define IN2 9 +#define IN3 10 +#define IN4 11 +int Steps = 0; +boolean Direction = true;// gre +unsigned long last_time; +unsigned long currentMillis ; +int steps_left=4095; +long time; +void setup() +{ + Serial.begin(115200); + pinMode(IN1, OUTPUT); + pinMode(IN2, OUTPUT); + pinMode(IN3, OUTPUT); + pinMode(IN4, OUTPUT); + // delay(1000); + +} +void loop() +{ + while(steps_left>0){ + currentMillis = micros(); + if(currentMillis-last_time>=1000){ + stepper(1); + time=time+micros()-last_time; + last_time=micros(); + steps_left--; + } + } + Serial.println(time); + Serial.println("Wait...!"); + delay(2000); + Direction=!Direction; + steps_left=4095; +} + +void stepper(int xw){ + for (int x=0;x7){ + Steps=0; + } + if(Steps<0){ + Steps=7; + } +} + + diff --git a/motors/stepper/step_4_fasi/step_4_fasi.ino b/motors/stepper/step_4_fasi/step_4_fasi.ino new file mode 100644 index 0000000..b2f0af9 --- /dev/null +++ b/motors/stepper/step_4_fasi/step_4_fasi.ino @@ -0,0 +1,31 @@ +/* + Step + + Utilizzo della libreria Step + +*/ +#include + int passi = 32 ; // Passi del motore + int rapporto = 64 ; // Rapporto di riduzione +// numeri di steps * rapporto di riduzione + // (usiamo 4 step in full step drive) + +//Stepper motore(2048, 8, 10, 9, 11); +Stepper motore(passi, 8, 10, 9, 11); + + +void setup() { +} + +void loop() +{ +// Rotazione completa CW + motore.setSpeed(1); // Impostiamo la velocita' + motore.step(4); + delay(500); + + delay(1000); + motore.setSpeed(1); // Impostiamo la velocita' + motore.step(-3); + delay(500); +} diff --git a/motors/stepper/step_4_phase_ardino_library/step_4_phase_ardino_library.ino b/motors/stepper/step_4_phase_ardino_library/step_4_phase_ardino_library.ino deleted file mode 100644 index a2ab28e..0000000 --- a/motors/stepper/step_4_phase_ardino_library/step_4_phase_ardino_library.ino +++ /dev/null @@ -1,56 +0,0 @@ -/* YourDuino.com Example Software Sketch - Small Stepper Motor and Driver V1.3 11/30/2013 - http://arduino-direct.com/sunshop/index.php?l=product_detail&p=126 - Shows 4-step sequence, Then 1/2 turn and back different speeds - terry@yourduino.com */ - -/*-----( Import needed libraries )-----*/ -#include - -/*-----( Declare Constants, Pin Numbers )-----*/ -//---( Number of steps per revolution of INTERNAL motor in 4-step mode )--- -#define STEPS_PER_MOTOR_REVOLUTION 32 - -//---( Steps per OUTPUT SHAFT of gear reduction )--- -#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048 - -/*-----( Declare objects )-----*/ -// create an instance of the stepper class, specifying -// the number of steps of the motor and the pins it's -// attached to - -//The pin connections need to be 4 pins connected -// to Motor Driver In1, In2, In3, In4 and then the pins entered -// here in the sequence 1-3-2-4 for proper sequencing -Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11); - - -/*-----( Declare Variables )-----*/ -int Steps2Take; - -void setup() /*----( SETUP: RUNS ONCE )----*/ -{ -// Nothing (Stepper Library sets pins as outputs) -}/*--(end setup )---*/ - -void loop() /*----( LOOP: RUNS CONSTANTLY )----*/ -{ - small_stepper.setSpeed(1); // SLOWLY Show the 4 step sequence - Steps2Take = 4; // Rotate CW - small_stepper.step(Steps2Take); - delay(2000); - - Steps2Take = STEPS_PER_OUTPUT_REVOLUTION / 2; // Rotate CW 1/2 turn - small_stepper.setSpeed(100); - small_stepper.step(Steps2Take); - delay(1000); - - Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION / 2; // Rotate CCW 1/2 turn - small_stepper.setSpeed(700); // 700 a good max speed?? - small_stepper.step(Steps2Take); - delay(2000); - -}/* --(end main loop )-- */ - -/* ( THE END ) */ - diff --git a/motors/stepper/step_5_rotazioni/step_5_rotazioni.ino b/motors/stepper/step_5_rotazioni/step_5_rotazioni.ino new file mode 100644 index 0000000..b9f285e --- /dev/null +++ b/motors/stepper/step_5_rotazioni/step_5_rotazioni.ino @@ -0,0 +1,33 @@ +/* + Step + + Utilizzo della libreria Step + +*/ +#include + int passi = 32 ; // Passi del motore + int rapporto = 64 ; // Rapporto di riduzione +// numeri di steps * rapporto di riduzione + // (usiamo 4 step in full step drive) + +//Stepper motore(2048, 8, 10, 9, 11); +Stepper motore(passi, 8, 10, 9, 11); + + +void setup() { + + +} + +void loop() +{ +// Rotazione completa CW + motore.setSpeed(300); // Impostiamo la velocita' + motore.step(passi * rapporto); + delay(1000); + +// Rotazione completa Anti-CW + motore.setSpeed(700); // Re impostiamo la velocita' + motore.step(-passi * rapporto); + delay(2000); +} diff --git a/motors/stepper/step_8_phase_raw/step_8_phase_raw.ino b/motors/stepper/step_8_phase_raw/step_8_phase_raw.ino deleted file mode 100644 index 3f1c85c..0000000 --- a/motors/stepper/step_8_phase_raw/step_8_phase_raw.ino +++ /dev/null @@ -1,131 +0,0 @@ - - -/* - BYJ48 Stepper motor code - Connect : - IN1 >> D8 - IN2 >> D9 - IN3 >> D10 - IN4 >> D11 - VCC ... 5V Prefer to use external 5V Source - Gnd - written By :Mohannad Rawashdeh - http://www.instructables.com/member/Mohannad+Rawashdeh/ - 28/9/2013 - */ - -#define IN1 8 -#define IN2 9 -#define IN3 10 -#define IN4 11 -int Steps = 0; -boolean Direction = true;// gre -unsigned long last_time; -unsigned long currentMillis ; -int steps_left=4095; -long time; -void setup() -{ - Serial.begin(115200); - pinMode(IN1, OUTPUT); - pinMode(IN2, OUTPUT); - pinMode(IN3, OUTPUT); - pinMode(IN4, OUTPUT); - // delay(1000); - -} -void loop() -{ - while(steps_left>0){ - currentMillis = micros(); - if(currentMillis-last_time>=1000){ - stepper(1); - time=time+micros()-last_time; - last_time=micros(); - steps_left--; - } - } - Serial.println(time); - Serial.println("Wait...!"); - delay(2000); - Direction=!Direction; - steps_left=4095; -} - -void stepper(int xw){ - for (int x=0;x7){ - Steps=0; - } - if(Steps<0){ - Steps=7; - } -} - - diff --git a/motors/stepper/stepper_6_acceleration/stepper_6_acceleration.ino b/motors/stepper/stepper_6_acceleration/stepper_6_acceleration.ino new file mode 100644 index 0000000..dd22bdd --- /dev/null +++ b/motors/stepper/stepper_6_acceleration/stepper_6_acceleration.ino @@ -0,0 +1,58 @@ +/* YourDuinoStarter Example: 2 Stepper Motors + - WHAT IT DOES: Runs 2 28BYJ-48 stepper motors with AccelStepper Library + - Motors accelerate and decelerate simultaneously in opposite rotations + - SEE the comments after "//" on each line below + - Derived from example code by Mike McCauley + - modified by Celem for single stepper + - modified by lowres for two steppers + NOTE: This may not run 2 motors from USB. + May need separate +5 Supply for motors + - CONNECTIONS: See Pin definitions below + + - V1.01 11/30/2013 + Questions: terry@yourduino.com */ + +/*-----( Import needed libraries )-----*/ +#include +/*-----( Declare Constants and Pin Numbers )-----*/ +#define FULLSTEP 4 +#define HALFSTEP 8 +// motor pins + + +#define motorPin5 8 // Blue - 28BYJ48 pin 1 +#define motorPin6 9 // Pink - 28BYJ48 pin 2 +#define motorPin7 10 // Yellow - 28BYJ48 pin 3 +#define motorPin8 11 // Orange - 28BYJ48 pin 4 + // Red - 28BYJ48 pin 5 (VCC) +/*-----( Declare objects )-----*/ +// NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48 + +AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8); + +/*-----( Declare Variables )-----*/ +//none + +void setup() /****** SETUP: RUNS ONCE ******/ +{ + stepper2.setMaxSpeed(1000.0); + stepper2.setAcceleration(50.0); + stepper2.setSpeed(200); + stepper2.moveTo(-2048); // 1 revolution + +}//--(end setup )--- + + +void loop() /****** LOOP: RUNS CONSTANTLY ******/ +{ + //Change direction at the limits + if (stepper2.distanceToGo() == 0) + stepper2.moveTo(-stepper2.currentPosition()); + + stepper2.run(); + +}//--(end main loop )--- + +/*-----( Declare User-written Functions )-----*/ +//none +//*********( THE END )*********** diff --git a/motors/stepper/stepper_7_constant_speed/stepper_7_constant_speed.ino b/motors/stepper/stepper_7_constant_speed/stepper_7_constant_speed.ino new file mode 100644 index 0000000..c0cbed5 --- /dev/null +++ b/motors/stepper/stepper_7_constant_speed/stepper_7_constant_speed.ino @@ -0,0 +1,29 @@ +// ConstantSpeed.pde +// -*- mode: C++ -*- +// +// Shows how to run AccelStepper in the simplest, +// fixed speed mode with no accelerations +/// \author Mike McCauley (mikem@airspayce.com) +// Copyright (C) 2009 Mike McCauley +// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $ +#define FULLSTEP 4 +#define HALFSTEP 8 + +#define motorPin5 8 // Blue - 28BYJ48 pin 1 +#define motorPin6 9 // Pink - 28BYJ48 pin 2 +#define motorPin7 10 // Yellow - 28BYJ48 pin 3 +#define motorPin8 11 // Orange - 28BYJ48 pin 4 + +#include + +AccelStepper stepper(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5 +void setup() +{ + stepper.setMaxSpeed(1000); + stepper.setSpeed(50); +} +void loop() +{ + stepper.runSpeed(); +} + diff --git a/motors/stepper/stepper_acceleration/stepper_acceleration.ino b/motors/stepper/stepper_acceleration/stepper_acceleration.ino deleted file mode 100644 index 9b22155..0000000 --- a/motors/stepper/stepper_acceleration/stepper_acceleration.ino +++ /dev/null @@ -1,70 +0,0 @@ -/* YourDuinoStarter Example: 2 Stepper Motors - - WHAT IT DOES: Runs 2 28BYJ-48 stepper motors with AccelStepper Library - - Motors accelerate and decelerate simultaneously in opposite rotations - - SEE the comments after "//" on each line below - - Derived from example code by Mike McCauley - - modified by Celem for single stepper - - modified by lowres for two steppers - NOTE: This may not run 2 motors from USB. - May need separate +5 Supply for motors - - CONNECTIONS: See Pin definitions below - - - V1.01 11/30/2013 - Questions: terry@yourduino.com */ - -/*-----( Import needed libraries )-----*/ -#include -/*-----( Declare Constants and Pin Numbers )-----*/ -#define FULLSTEP 4 -#define HALFSTEP 8 -// motor pins -#define motorPin1 4 // Blue - 28BYJ48 pin 1 -#define motorPin2 5 // Pink - 28BYJ48 pin 2 -#define motorPin3 6 // Yellow - 28BYJ48 pin 3 -#define motorPin4 7 // Orange - 28BYJ48 pin 4 - // Red - 28BYJ48 pin 5 (VCC) - -#define motorPin5 8 // Blue - 28BYJ48 pin 1 -#define motorPin6 9 // Pink - 28BYJ48 pin 2 -#define motorPin7 10 // Yellow - 28BYJ48 pin 3 -#define motorPin8 11 // Orange - 28BYJ48 pin 4 - // Red - 28BYJ48 pin 5 (VCC) -/*-----( Declare objects )-----*/ -// NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48 -AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); -AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8); - -/*-----( Declare Variables )-----*/ -//none - -void setup() /****** SETUP: RUNS ONCE ******/ -{ - stepper1.setMaxSpeed(1000.0); - stepper1.setAcceleration(50.0); - stepper1.setSpeed(200); - stepper1.moveTo(2048); // 1 revolution - - stepper2.setMaxSpeed(1000.0); - stepper2.setAcceleration(50.0); - stepper2.setSpeed(200); - stepper2.moveTo(-2048); // 1 revolution - -}//--(end setup )--- - - -void loop() /****** LOOP: RUNS CONSTANTLY ******/ -{ - //Change direction at the limits - if (stepper1.distanceToGo() == 0) - stepper1.moveTo(-stepper1.currentPosition()); - if (stepper2.distanceToGo() == 0) - stepper2.moveTo(-stepper2.currentPosition()); - - stepper1.run(); - stepper2.run(); - -}//--(end main loop )--- - -/*-----( Declare User-written Functions )-----*/ -//none -//*********( THE END )*********** diff --git a/motors/stepper/stepper_oneRevolution_adapted/stepper_oneRevolution_adapted.ino b/motors/stepper/stepper_oneRevolution_adapted/stepper_oneRevolution_adapted.ino deleted file mode 100644 index 7c40ceb..0000000 --- a/motors/stepper/stepper_oneRevolution_adapted/stepper_oneRevolution_adapted.ino +++ /dev/null @@ -1,59 +0,0 @@ - -/* - Stepper Motor Control - one revolution - - Revisionato per i motori 5v 28YBJ-48 con controller board - - http://arduino-info.wikispaces.com/SmallSteppers - - This program drives a unipolar or bipolar stepper motor. - The motor is attached to digital pins 8 - 11 of the Arduino. - - The motor should revolve one revolution in one direction, then - one revolution in the other direction. - - - Created 11 Mar. 2007 - Modified 30 Nov. 2009 - by Tom Igoe - - */ - -#include - -const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution -// for your motor -// 2048 = 360deg = 32*64 in 4-step sequence as in Step Library -// 1025 = 180deg -// 512.5 = 90deg -// 5.6944 = 1deg - -// initialize the stepper library on pins 8 through 11: -Stepper myStepper(stepsPerRevolution,8,10,9,11); -// Sequence is 1-3-2-4 -// Valid values: (8,10,11,9), (9,11,8,10), (10,8,9,11), and (11,9,10,8) -// 1N1 on pin 8 -// 1N2 on pin 9 -// 1N3 on pin 10 -// 1N4 on pin 11 -// powered via 5v -// Max speed is 14RPM @ 5v - -void setup() { - // set the speed at 60 rpm: - myStepper.setSpeed(14); // Max speed is 14RPM @5v - // initialize the serial port: - Serial.begin(9600); -} - -void loop() { - // step one revolution in one direction: - Serial.println("clockwise"); - myStepper.step(stepsPerRevolution); - delay(500); - - // step one revolution in the other direction: - Serial.println("counterclockwise"); - myStepper.step(-stepsPerRevolution); - delay(500); -} -