Arduino won't react to data sent using serial from Matlab


hello everyone, i'm trying make aplication wich moves 2 stepper motors according serial data sent matlab. arduino seems receive data matlab doesn't anything. can please me see wrong in code?
 this code matlab:
code: [select]
delete(instrfindall);
arduino=serial('com4','baudrate',9600); % create serial communication object on port com4
fopen(arduino); % initiate arduino communication

        answer=3;
        fprintf(arduino,'%s',char(answer)); % send answer variable content arduino



and  code on arduino
code: [select]
/*-----( import needed libraries )-----*/
#include <stepper.h>


/*-----( 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 pozitia3 32 * 45   
#define pozitia2 32 * 29 
#define impinge 32 * 32
// pins entered here in sequence 1-3-2-4 proper sequencing
stepper brat(steps_per_motor_revolution, 8, 10, 9, 11);
stepper container(steps_per_motor_revolution, 4, 6, 5, 7);

/*-----( declare variables )-----*/
int  steps2take;
int matlabdata;
   int ledpin=13;

void setup() {
  // put setup code here, run once:

}

void loop() {
  // put main code here, run repeatedly:
 if(serial.available()>0) // daca exista date de citit
   {
    matlabdata=serial.read(); // citeste date

    if(matlabdata==3){
        digitalwrite(ledpin,low);
      steps2take=pozitia3 ;
      container.setspeed(800);   
      container.step(steps2take);
      delay(1000);

       steps2take=impinge ;
       brat.setspeed(800);   
       brat.step(steps2take);
       delay(1000);

       steps2take=-impinge ;
       brat.setspeed(800);   
       brat.step(steps2take);
       delay(1000);

       steps2take=-pozitia3 ;
       container.setspeed(800);   
       container.step(steps2take);
       delay(1000);
       
    }

      else if(matlabdata==2){
      steps2take=pozitia2 ;
      container.setspeed(800);   
      container.step(steps2take);
      delay(1000);

       steps2take=impinge ;
       brat.setspeed(800);   
       brat.step(steps2take);
       delay(1000);

       steps2take=-impinge ;
       brat.setspeed(800);   
       brat.step(steps2take);
       delay(1000);

       steps2take=-pozitia2 ;
       container.setspeed(800);   
       container.step(steps2take);
       delay(1000);
      }

     // else if(matlabdata==1)
     

       //steps2take=impinge ;
       //brat.setspeed(800);   
       //brat.step(steps2take);
       //delay(1000);

       //steps2take=-impinge ;
      // brat.setspeed(800);   
      // brat.step(steps2take);
       //delay(2000);

     
     
}
}


the problem motors wonțt move. tried them separatey , work fine. when try use serial data won't anything.

also tried more simple code using matlab , serial set led on off , working fine. using arduino mega2560

so formatting answer string , trying compare integer? seems problem there.

take matlab out of moment. can send 3 serial monitor? no, can send '3', matlab trying do. can change code detect '3'?


Arduino Forum > Using Arduino > Programming Questions > Arduino won't react to data sent using serial from Matlab


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts