Author Topic: Having trouble with motors?!  (Read 516 times)

0 Members and 1 Guest are viewing this topic.

Offline heinz357Topic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 1
Having trouble with motors?!
« on: July 13, 2011, 03:56:17 PM »
Right, not sure if this is in the right section, but I'm not sure where the problem lies yet?!

Heres the issue, I'm a total beginner, but I'm not afraid to spend a long while researching things before I try them out....Google really IS my friend!!  ;)

I have an Arduino Romeo, and try as I might, I cant find a sample script to test the onboard motor driver that actually works!  I have run many test scripts on the board for LED and servos, so I know the board is ok, and I've tested both motors on the battery that I'm running the board with.  All the components are within specs for the board, and all the jumper settings on the board are in the correct positions, but still no life from the motors?!

I'm trying to learn to code, but until I can find a working code to experiment with, I'm going to find it really difficult!!

LED's I've got the hang of, servos too, but I need to learn motor control before I can get any furter with the Bot project I'm working towards!

Can someone point me towards a small script, that simply spins both motors, nothing too complicated, no sensors or servos involved, it just needs to turn both motors, because I cant find one that works anywhere?!

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Having trouble with motors?!
« Reply #1 on: July 13, 2011, 05:09:46 PM »
From what you are saying, it seems like there is a "set-up" on how to use motors, but it's simply not working?

Can you post the code that you used that isn't working?

It's a lot easier for us to fix something rather than to fabricate something for a board we (most likely) don't have.

(And we're more likely to help with the more information you provide.)


Offline heinz357Topic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 1
Re: Having trouble with motors?!
« Reply #2 on: July 13, 2011, 07:40:25 PM »
This was the first code that I tried, and is the one that comes from the boards manufacturer...

Code: [Select]
//Standard PWM DC control

int E1 = 5;     //M1 Speed Control
int E2 = 6;     //M2 Speed Control
int M1 = 4;    //M1 Direction Control
int M2 = 7;    //M1 Direction Control

///For previous Romeo, please use these pins.
//int E1 = 6;     //M1 Speed Control
//int E2 = 9;     //M2 Speed Control
//int M1 = 7;    //M1 Direction Control
//int M2 = 8;    //M1 Direction Control


void stop(void)                    //Stop
        {
          digitalWrite(E1,LOW);   
          digitalWrite(E2,LOW);     
        }   
void advance(char a,char b)          //Move forward
        {
          analogWrite (E1,a);      //PWM Speed Control
          digitalWrite(M1,HIGH);   
          analogWrite (E2,b);   
          digitalWrite(M2,HIGH);
        } 
void back_off (char a,char b)          //Move backward
        {
          analogWrite (E1,a);
          digitalWrite(M1,LOW);   
          analogWrite (E2,b);   
          digitalWrite(M2,LOW);
}
void turn_L (char a,char b)             //Turn Left
        {
          analogWrite (E1,a);
          digitalWrite(M1,LOW);   
          analogWrite (E2,b);   
          digitalWrite(M2,HIGH);
        }
void turn_R (char a,char b)             //Turn Right
        {
          analogWrite (E1,a);
          digitalWrite(M1,HIGH);   
          analogWrite (E2,b);   
          digitalWrite(M2,LOW);
        }
void setup(void)
{
    int i;
    for(i=6;i<=9;i++)
    pinMode(i, OUTPUT); 
    Serial.begin(19200);      //Set Baud Rate
}
void loop(void)
{
     char val = Serial.read();
     if(val!=-1)
       {
          switch(val)
           {
             case 'w'://Move Forward
                     advance (100,100);   //PWM Speed Control
                     break;
             case 's'://Move Backward
                     back_off (100,100);
                     break;
             case 'a'://Turn Left
                     turn_L (100,100);
                     break;       
             case 'd'://Turn Right
                     turn_R (100,100);
                     break;         
            }     
          delay(40);
       }
      else stop(); 
}

...have also found one or two others, on Arduino forum, and the most I've managed to achieve is turning one motor, but not the other, I did manage to alter the code to make the other one turn, but not both, despite the code having sections defining left and right motors?!

Would a schematic of the board be any help, because it has an H-bridge that seems to be a little different to the norm, a 298P surface mount. Would this require different script from other H-bridges??

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Having trouble with motors?!
« Reply #3 on: July 13, 2011, 07:55:05 PM »
It looks like what that program does it takes an input from the computer, w a s or d and makes the robot move/turn that way.  

It looks like if you wired everything correctly and you changed your void loop(void) to something like this...
Code: [Select]
void loop(void)
{
     advance (100,100);   //PWM Speed Control
     delay(40);
}
 

Both of the motors should turn.  At least that's what I'm guessing.

I'm basically just taking the whole computer thing out of the equation, and just moving the motors forward, then pausing, forward, then pausing.  Etc.  I wouldn't run that program too long (motors might get hot... I dunno), but it still could be useful.


How you have everything hooked up would be nice to know too.  (Although since I've found the manual it looks pretty straightforward on how to hook them up lol)

EDIT:  I think I've found the manual for this thing, for those who want to help.
http://www.yerobot.com/products/manual/RoMeo%20Manual.pdf
« Last Edit: July 13, 2011, 08:02:27 PM by corrado33 »

 


Get Your Ad Here