I can't control motors with AF_DCMotor and Arduino Mega 2560


i can not work same codes used arduino uno engines control robot.
when connecting motor controller board (af_dcmotor) arduino mega 2560 has left me run same codes used arduino uno board.

the upload mega board smoothly, not respond, nothing, neither simple code direct commands move directly motors nor sending commands serial port code little bit more complex.

there 2 things have changed when moving 1 plate other , 'board' board touches ie arduino mega 2560 , had change port com3 (i used arduino uno) com6 com3 because com3 not load program.

you can me?

here's code:

#include <afmotor.h>

int input;
void setup(){
serial.begin(9600);

}

void loop() {
af_dcmotor motor4(4, motor34_64khz);  // define el motor en el puerto 4 64khz
af_dcmotor motor3(3, motor34_64khz);  // define el motor en el puerto 3 64khz
af_dcmotor motor2(2, motor12_64khz);  // define el motor en el puerto 2 64khz
af_dcmotor motor1(1, motor12_64khz);  // define el motor en el puerto 1 64khz

input=serial.read();

int pindigital = 2;     
pinmode(pindigital, output);

if (input=='1'){
digitalwrite(pindigital, low);   // activaremos el relé en posición motor 1
delay(500);
motor1.setspeed(255);  // define la velocidad del motor (max.255)
motor1.run(forward);
delay(500);  // hace un forward durante medio segundo
  }

if (input=='2'){
motor2.setspeed(255);  // define la velocidad del motor (max.255)
motor2.run(forward);
delay(500);  // hace un forward durante medio segundo
  }

if (input=='3'){
motor3.setspeed(255);  // define la velocidad del motor (max.255)
motor3.run(forward);
delay(500);  // hace un forward durante medio segundo
  }

if (input=='4'){
motor4.setspeed(255);  // define la velocidad del motor (max.255)
motor4.run(forward);
delay(500);  // hace un forward durante medio segundo
  }

if (input=='5'){
digitalwrite(pindigital, high);    // activaremos el relé en posición motor 5
delay(500);
motor1.setspeed(255);  // define la velocidad del motor (max.255)
motor1.run(forward);
delay(500);  // hace un forward durante medio segundo
  }

if (input=='6'){
digitalwrite(pindigital, low);   // activaremos el relé en posición motor 1
delay(500);
motor1.setspeed(255);  // define la velocidad del motor (max.255)
motor1.run(backward);
delay(500);  // hace un backward durante medio segundo
  }

if (input=='7'){
motor2.setspeed(255);  // define la velocidad del motor (max.255)
motor2.run(backward);
delay(500);  // hace un backward durante medio segundo
  }

if (input=='8'){
motor3.setspeed(255);  // define la velocidad del motor (max.255)
motor3.run(backward);
delay(500);  // hace un backward durante medio segundo
  }

if (input=='9'){
motor4.setspeed(255);  // define la velocidad del motor (max.255)
motor4.run(backward);
delay(500);  // hace un backward durante medio segundo
  }

if (input=='0'){
digitalwrite(pindigital, high);    // activaremos el relé en posición motor 5
delay(500);
motor1.setspeed(255);  // define la velocidad del motor (max.255)
motor1.run(backward);
delay(500);  // hace un forward durante medio segundo
  }   
}

quote
click modify button in upper right of post window.
highlight code.
click "#" code tags button on toolbar above left of quote button.
click save (at bottom).
when post code on forum, please make habit of using code tags "#" button.    


quote
i can not work same codes used arduino uno engines (motors) control robot.  

quote
when connecting motor controller board (af_dcmotor) arduino mega 2560 has left me run same codes used arduino uno board.

quote
the upload mega board smoothly, not respond, nothing, neither simple code direct commands move directly motors nor sending commands serial port code little bit more complex.  


quote
there 2 things have changed when moving 1 plate other , 'board' board touches ie arduino mega 2560  


quote
and had change port com3 (i used arduino uno) com6 com3 because com3 not load program.  


i have bad feeling this.

code: [select]
#include <afmotor.h>

int input;
void setup(){
serial.begin(9600);

}

void loop() {
af_dcmotor motor4(4, motor34_64khz);  // define el motor en el puerto 4 64khz
af_dcmotor motor3(3, motor34_64khz);  // define el motor en el puerto 3 64khz
af_dcmotor motor2(2, motor12_64khz);  // define el motor en el puerto 2 64khz
af_dcmotor motor1(1, motor12_64khz);  // define el motor en el puerto 1 64khz

input=serial.read();

int pindigital = 2;    
pinmode(pindigital, output);

if (input=='1'){
digitalwrite(pindigital, low);   // activaremos el relé en posición motor 1
delay(500);
motor1.setspeed(255);  // define la velocidad del motor (max.255)
motor1.run(forward);
delay(500);  // hace un forward durante medio segundo
 }

if (input=='2'){
motor2.setspeed(255);  // define la velocidad del motor (max.255)
motor2.run(forward);
delay(500);  // hace un forward durante medio segundo
 }

if (input=='3'){
motor3.setspeed(255);  // define la velocidad del motor (max.255)
motor3.run(forward);
delay(500);  // hace un forward durante medio segundo
 }

if (input=='4'){
motor4.setspeed(255);  // define la velocidad del motor (max.255)
motor4.run(forward);
delay(500);  // hace un forward durante medio segundo
 }

if (input=='5'){
digitalwrite(pindigital, high);    // activaremos el relé en posición motor 5
delay(500);
motor1.setspeed(255);  // define la velocidad del motor (max.255)
motor1.run(forward);
delay(500);  // hace un forward durante medio segundo
 }

if (input=='6'){
digitalwrite(pindigital, low);   // activaremos el relé en posición motor 1
delay(500);
motor1.setspeed(255);  // define la velocidad del motor (max.255)
motor1.run(backward);
delay(500);  // hace un backward durante medio segundo
 }

if (input=='7'){
motor2.setspeed(255);  // define la velocidad del motor (max.255)
motor2.run(backward);
delay(500);  // hace un backward durante medio segundo
 }

if (input=='8'){
motor3.setspeed(255);  // define la velocidad del motor (max.255)
motor3.run(backward);
delay(500);  // hace un backward durante medio segundo
 }

if (input=='9'){
motor4.setspeed(255);  // define la velocidad del motor (max.255)
motor4.run(backward);
delay(500);  // hace un backward durante medio segundo
 }

if (input=='0'){
digitalwrite(pindigital, high);    // activaremos el relé en posición motor 5
delay(500);
motor1.setspeed(255);  // define la velocidad del motor (max.255)
motor1.run(backward);
delay(500);  // hace un forward durante medio segundo
 }  
}



where did code ?


Arduino Forum > Topics > Robotics (Moderator: fabioc84) > I can't control motors with AF_DCMotor and Arduino Mega 2560


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support