interfacing problems with xbee

25 Apr 2012

Hi every body ... i'm working on a project in which i want to control a couple of dc motors using mbed and xbee wireless modules.

My problem is that when i send a control signal to the mbed to accelerate the motors, the motors keep accelerating due to my command till the motors reach a certain speed limit (and this speed is not appropriate for my application by the way), but once this limit is reached, the xbee goes mad and it never obeys my orders, so when i send an order to stop, it doesn't stop, when i send an order to decelerate, it never does and so on.

what do you think is the problem??

this is the main code in which i deal with the mbed and the other orders and classes in this code are not standard but i made them to control the motion of a small car

 #include "mbed.h"
#include "rover_1.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
//Serial pc(USBTX,USBRX);
Serial xbee (p9,p10);
DigitalOut rst(p21);

int main() 
{
    rst = 0;
    rst = 1;
    xbee.baud(9600);
    xbee.printf("z");
    rover_1 R(p22,p23,p24,p29,p30,p25);
    char a = 0;
    while(1)
    {
        if(xbee.readable())
        {
           a = xbee.getc();
           switch (a)
           {
                case 'w'/*(char)24*/:  // 24 stands for the right arrow in ascii code .. it used to be 'w'
                R.go_forward();
                led1 = 1;
                led2 = 1;
                led3 = 0;
                printf("%going forward\r\n");
                break;                                                
                
                case 's'/*(char)25*/:   // 24 stands for the right arrow in ascii code .. it used to be 's'
                R.go_backward();
                led3 = 1;
                led1 = led2 = 0;
                break;
                
                case 'd'/*(char)26*/:   // 26 stands for the right arrow in ascii code .. it used to be 'a'
                R.turn_right();
                led1 = 0;
                led2 = 1;
                led3 = 0;
                break;
                
                case 'a'/*(char)27*/:  // 27 stands for the right arrow in ascii code .. it used to be 'd'
                R.turn_left();
                led1 = 1;
                led2 = 0;
                led3 = 0;
                break;                                
                
                case 'e':
                R.accelerate();
                break;
                
                case 'q':   
                R.decalerate();
                break;
                
                case (char)32: // 32 is the ascii code for space bar .. it used to be 't'
                R.stop();
                led1 = led2 = led3 = 0;
                break; 
                
                case (char)26:
                R.lean_right();
                break;
                
                case (char)27:
                R.lean_left();
                break;                               
           }
         }
     }
}
03 May 2012

Motors generate lots of noise. Are they properly isolated? try the same but with the motors detached and some other mechanism to see the output. Oscope, led, counter circuit...

04 May 2012

before using the code, above, have you run a loop-back program - where your microprocessor simply does a getc() then a putc(), and the PC (you don't say what is on the other XBee), shows reliable echoed chars.

Then a program to toggle LEDs on command.

Also, not knowing what the rover class is/does makes it hard to help.