Go Down

Topic: Arduino and Motor shield power problems (Read 1 time) previous topic - next topic

chaneyac

Hi everyone,

I need some assistant with the Arduino Mega and motor shield. I am having a problem with the GM9 motor, I used the basic code to test the motors. It seems that they will not work.  Here is the code I used:
int motor_reset = 2; //digital pin 2 assigned to motor reset
void setup()
{
pinMode(motor_reset, OUTPUT);
Serial.begin(9600);
digitalWrite(motor_reset, LOW);
delay(50);
digitalWrite(motor_reset, HIGH);
delay(50);
}
//select the function you want to use but ensure two are not running simultaneously.
void loop()
{
//motorforward();
//motorreverse();
//rotateccw();
//motorstop();
}
//subroutine motor forward
void motorforward()
{
 
//left motor
unsigned char buff1[6];
buff1[0]=0x80; //start byte - do not change
buff1[1]=0x00; //Device type byte - do not change
buff1[2]=0x01; //Motor number and direction byte; motor one =00,01
buff1[3]=0x45; //Motor speed "0 to 128" in hex (ex 100 is 64 in hex)
for(int i=0; i<4; i++) {Serial.print(buff1, BYTE);}

//right motor
unsigned char buff2[6];
buff2[0]=0x80;
buff2[1]=0x00;
buff2[2]=0x03; //Motor number and direction byte; motor two=02,03
buff2[3]=0x45;
for(int i=0; i<4; i++) {Serial.print(buff2, BYTE);}
}
//subroutine reverse at half speed
void motorreverse()
{
//left motor
unsigned char buff3[6];
buff3[0]=0x80;
buff3[1]=0x00;
buff3[2]=0x00;
buff3[3]=0x35;
for(int i=0; i<4; i++) {Serial.print(buff3, BYTE);}
//right motor
unsigned char buff4[6];
buff4[0]=0x80;
buff4[1]=0x00;
buff4[2]=0x02;
buff4[3]=0x35;
for(int i=0; i<4; i++) {Serial.print(buff4, BYTE);}
}
//Motor all stop
void motorstop()
{
//left motor
unsigned char buff3[6];
buff3[0]=0x80;
buff3[1]=0x00;
buff3[2]=0x00;
buff3[3]=0x00;
for(int i=0; i<4; i++) {Serial.print(buff3, BYTE);}

//right motor
unsigned char buff4[6];
buff4[0]=0x80;
buff4[1]=0x00;
buff4[2]=0x02;
buff4[3]=0x00;
for(int i=0; i<4; i++) {Serial.print(buff4, BYTE);}
}
void rotateccw()
{
//left motor
unsigned char buff1[6];
buff1[0]=0x80;
buff1[1]=0x00;
buff1[2]=0x01;
buff1[3]=0x40;
for(int i=0; i<4; i++) {Serial.print(buff1, BYTE);}

//right motor
unsigned char buff2[6];
buff2[0]=0x80;
buff2[1]=0x00;
buff2[2]=0x02;
buff2[3]=0x40;
for(int i=0; i<4; i++) {Serial.print(buff2, BYTE);}
}

I am wonder if there is not enough power to turn on the motor. Please help.

Go Up