Stepper motors working strangely


hi , sorry poor english. working on camera scanning system. camera move row row in fixed pattern , capture photos @ positions repeatedly, attached simplified moving pattern of camera.

basically flow arduino controls motor, , tells computer(python) capture photos once reached position.

hardware:
arduino mega
m542 step motor driver

and here code use
code: [select]
//motor , dir pin setting
const int mo_x = 2;  
const int dir_x = 3;  
const int mo_y = 4;  
const int dir_y = 5;

//end switch pin
const int endpin_x = 9;
const int endpin_y = 10;

//fixed step
const int xy_step = 2504;

//end switch val checking
int end_x = 0;
int end_y = 0;

int stage = 0;

boolean initial_done = false; //check initialized
void setup()
{
 serial.begin(115200);
 pinmode(mo_x, output);
 pinmode(dir_x, output);      
 pinmode(mo_y, output);
 pinmode(dir_y, output);  
 pinmode(endpin_x, input);
 pinmode(endpin_y, input);
 delay(3000); //wait serial connection
}

void loop()
{
 switch (stage){
   case 0 :  // initialise position
     while (initial_done == false){
        check_end();
     while(end_y != high) { // check y end first
        back();
        move_mo(mo_y);
        check_end();  }
     while(end_x != high) { // check x end
        left();
        move_mo(mo_x);  
        check_end();  }  
     if (end_x == high && end_y == high ){
        initial_done = true;
        stage = 1;   }
     }
     break;
 
  case 1 :  //start scanning
    if (initial_done == true){
       //move first row
       delay(1000);
       front();
       for (int = 0; < xy_step; i++){
         move_mo(mo_y);  }
       for(int row = 1; row <= 5 ;){ // 5 row
         //check row or odd
         if ((row %2) != 0){
           right();}  
         else if ((row %2) == 0){
           left(); }
           
         // capture
         cap();
             
         // move column 5 times
         for(int col = 1; col <= 5; col++){
           for (int = 0; < xy_step; i++){
             move_mo(mo_x);  }        
           //capture
           cap();  
           }          
         //move next row
         if (row != 5 && row <6 ){
           for (int = 0; < xy_step; i++){
             move_mo(mo_y);  }        
         }
         if (row == 5){  // go start position
           check_end();
           stage = 0;
           initial_done = false;  }
         row++;
        }
    }
   break;
   

// func set  dir
void left(){digitalwrite(dir_x, high);}
void right(){digitalwrite(dir_x, low);}
void front(){digitalwrite(dir_y, high);}
void back(){digitalwrite(dir_y, low);}

// func move motor
void move_mo(int motor){  
 digitalwrite(motor, high);
 delay(2);
 digitalwrite(motor, low);
 delay(2);  }

//func check cap
void cap(){
 delay(2000);
 serial.print("c");
 delay(1000);
 serial.flush();
 while(!serial.available()) {}
 //check serial
 int incoming;
 while (incoming != '1'){
     if (serial.available() >0){
       incoming = serial.read();   }
   }
 delay(2000);
}

void check_end(){   //func read end switch state
 end_x = digitalread(endpin_x);
 end_y = digitalread(endpin_y);}


the camera moves in pattern expected, , captures photos properly.

but there problem, photos seems shifted after every round of scanning, , found out motor move larger step every time moves instead of value set, reached end of track.
anyone knows problem is?

many thanks.

am right in thinking motor should move 2504 steps on each occasion?

have verified simple sketch that?
have verified that correct number?

...r


Arduino Forum > Using Arduino > Project Guidance > Stepper motors working strangely


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support