ArduShop.ro

ArduShop.ro
cod Z4A413ZN reducere 5%, pentru vizitatorii paginilor mele !

luni, 8 aprilie 2013

Comanda unui motor pas cu pas unipolar folosind Arduino (II)


   Dupa am facut o prezentare in prima parte, acum am zis ca trebuie sa fac si partea practica...
   Am incercat identificarea ordinii firelor prin masurarea rezistentelor dintre ele si am observat ca nu pot deoarece au un fir comun (negru), am facut o identificare a modului de rotatie prin legarea firului comun al infasurarilor (negru) la masa si atingerea celor 4 fire la +12V proveniti de la sursa mea reglabila cu LM317, rezultandu-mi ordinea (galben, rosu, albastru si maro).
   Am realizat si un filmulet numit testing a unipolar stepper motor in care am prezentat modul de testare:

   Am realizat montajul de comanda (driver) cu ULN2003AN:





   Schema de conectare este:

   Am incercat sketch-ul din articolul Identifying and using a stepper motor on Arduino, modificand partea cu conectarea firelor:


/* Stepper Copal
 * -------------
 *
 * Program to drive a stepper motor coming from a 5'25 disk drive
 * according to the documentation I found, this stepper: "[...] motor 
 * made by Copal Electronics, with 1.8 degrees per step and 96 ohms 
 * per winding, with center taps brought out to separate leads [...]"
 * [http://www.cs.uiowa.edu/~jones/step/example.html]
 *
 * It is a unipolar stepper motor with 5 wires:
 * 
 * - red: power connector, I have it at 5V and works fine
 * - orange and black: coil 1
 * - brown and yellow: coil 2
 *
 * (cleft) 2005 DojoDave for K3
 * http://www.0j0.org | http://arduino.berlios.de
 *
 * @author: David Cuartielles
 * @date: 20 Oct. 2005
 */

int motorPin1 = 9;
int motorPin2 = 11;
int motorPin3 = 10;
int motorPin4 = 12;
int delayTime = 500;

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop() {
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delay(delayTime);
}



   Filmuletul care prezinta modul de functionare se numeste first test with a unipolar stepper motor and Arduino:

   Apoi am testat sketch-ul din programul Arduino IDE numit "Steper_oneRevolution", modificand ordinea a 2 fire in program, apoi schimbandu-le fizic, deoarece in loc de rotire avea o miscare sacadata (fata-spate), filmuletul cu modul de functionare se numeste oneRevolution for a unipolar stepper motor and Arduino:

   La motorul testat am conectat culorile astfel:
- la D9 firul maro
- la D10 firul rosu
- la D11 firul galben
- la D12 firul albastru
- la +12V firul negru

/* 
 Stepper Motor Control - one revolution

 This program drives a unipolar or bipolar stepper motor. 
 The motor is attached to digital pins 9 - 12 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 <Stepper.h>

const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution
                                     // for your motor (se 

// initialize the stepper library on pins 9 through 12:
Stepper myStepper(stepsPerRevolution, 9,10,11,12);            

void setup() {
  // set the speed at xxx rpm:
  myStepper.setSpeed(100);
  // 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); 
}

   Pentru a scadea sau creste viteza de rotatie, se modifica:
 // set the speed at xxx rpm:
  myStepper.setSpeed(100);

   Am modificat acest sketch pentru a comanda rotirea mtorului intr-un sens sau altul prin apasarea a 2 butoane fara retinere (taste):

/* 
 use base of "Stepper Motor Control - one revolution" sketch made by Tom Igoe
 This program drives a unipolar stepper motor  with 2 button (clockwise or counterclockwise)
 The motor is attached to digital pins 9 - 12 of the Arduino.
 adapted sketch made by Nicu Florica (niq_ro) from http://tehnic.go.ro
 version 1.0 (07.04.2013 - Craiova, Romania)
 */

#include <Stepper.h>

const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution for your motor
Stepper myStepper(stepsPerRevolution, 9,10,11,12);     // initialize the stepper library on pins 9 through 12:
int speed = 50; // set the speed at 50 rpm:
int buton1 = 4;                 // first button at pin 4
int buton2 = 5;                 // second button at pin 5

void setup() {

  myStepper.setSpeed(speed); // set the speed
  Serial.begin(9600);   // initialize the serial port:
pinMode(buton1, INPUT);  // set buton1 pin as input
pinMode(buton2, INPUT);  // set buton2 pin as input
}

void loop() 
{
 digitalWrite(buton1, HIGH);  // if not pushed, set voltage for buton1 as HIGH 
 digitalWrite(buton2, HIGH);  // if not pushed, set voltage for buton1 as HIGH 

  if (digitalRead(buton1) == LOW) 
{
   Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
 }          

if (digitalRead(buton2) == LOW) 
{
   Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
 }          

  delay(10); // waiting little bit...  

 // delay(10); // waiting little bit...  
}


   Am definit inca 2 taste, una pentru crestere viteza si una pentru reducere viteza, sketch-ul devenind versiunea 1m1:


/* 
 use base of "Stepper Motor Control - one revolution" sketch made by Tom Igoe
 This program drives a unipolar stepper motor  with 2 button (clockwise or counterclockwise) and 2 for speed
 The motor is attached to digital pins 9 - 12 of the Arduino.
 adapted sketch made by Nicu Florica (niq_ro) from http://tehnic.go.ro
http://nicuflorica.blogspot.com & http://www.niqro.3x.ro
 version 1m1 (07.04.2013 - Craiova, Romania)
 */

#include <Stepper.h>

const int stepsPerRevolution = 100;  // change this to fit the number of steps per revolution for your motor
Stepper myStepper(stepsPerRevolution, 9,10,11,12);     // initialize the stepper library on pins 9 through 12:
int viteza = 50; // set the speed at 50 rpm:
int buton1 = 4;                 // first button at pin 4
int buton2 = 5;                 // second button at pin 5
int buton3 = 6;                 // third button at pin 6
int buton4 = 7;                 // fourth button at pin 7


void setup() {

  myStepper.setSpeed(viteza); // set the speed
  Serial.begin(9600);   // initialize the serial port:
pinMode(buton1, INPUT);  // set buton1 pin as input
pinMode(buton2, INPUT);  // set buton2 pin as input
pinMode(buton3, INPUT);  // set buton3 pin as input
pinMode(buton4, INPUT);  // set buton4 pin as input

}

void loop() 
{
 digitalWrite(buton1, HIGH);  // if not pushed, set voltage for buton1 as HIGH 
 digitalWrite(buton2, HIGH);  // if not pushed, set voltage for buton1 as HIGH 
 digitalWrite(buton3, HIGH);  // if not pushed, set voltage for buton1 as HIGH 
 digitalWrite(buton4, HIGH);  // if not pushed, set voltage for buton1 as HIGH 

if (digitalRead(buton1) == LOW) 
{
   Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
 }          

if (digitalRead(buton2) == LOW) 
{
   Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
 }          

  if (digitalRead(buton3) == LOW) 
{
   Serial.println("speed +");
   viteza = viteza*1.2;
   delay(250); // waiting little bit...  
 }          

  if (digitalRead(buton4) == LOW) 
{
   Serial.println("speed -");
   viteza = viteza*0.8;
   delay(250); // waiting little bit...  
 }          

  myStepper.setSpeed(viteza); // set the speed
  delay(10); // waiting little bit...  
 }


   Filmuletul care prezinta modul de comanda al motorului pas cu pas unipolar cu 4 taste (una pentru rotire in stanga, una pentru rotire in drepata, una pentru creste viteza si una pentru scadere viteza) se numeste control a unipolar stepper motor with 4 button and Arduino:


Niciun comentariu:

Trimiteți un comentariu