Go Down

Topic: xbee problem (Read 58 times) previous topic - next topic

mikehj24

I am new and love robots but since i am a beginner i am running into confusion. I bought a 2 wheel chasis car with 2 dc motors, an xbee motor shield found here

 http://www.ebay.com/itm/Motor-Stepper-Servo-Shield-XBee-Wireless-Proto-motor-Shield-for-arduino-/311719802701?hash=item4893f2b74d:g:DZcAAOSwAoRXFg4k 

i have 2 wires for each dc motor, for the left wheel the 2 wires go into B- and B+, and for the 2 wires coming from the right wheel i plugged them into A+, and A- . I connected the xbee pro modules in XCTU. 

The problem is when I use serial moniter from the arduino software and have my rc car plugged in through a usb to the computer it works fine when i send commands, but when i unplug it from my computer, and use an xbee transmitter only hooked up to my computer and other xbee on the motor shield and use xctu and send for example an w command which moves it forward nothing happens, the light flashes on the motor shield so i know they are communicating but the dc motors dont turn please help.

Here is the code


int lmt1=11,lmt2=12,rmt1=8,rmt2=9;     //set your motor output pins left motor terminals and right motor terminals
int value;           // declaring variable used in serial communication
void setup()         // main function executes only once
{
 pinMode(lmt1,OUTPUT);
 pinMode(lmt2,OUTPUT);
 pinMode(rmt1,OUTPUT);
 pinMode(rmt2,OUTPUT);
 Serial.begin(9600); // serial communication begins baud rate is 9600
}
void loop()
{
  value=Serial.read(); //it will read the data recieved by xbee
  switch(value)   // will activate the case according to the value
 
  {
    case 'w':     // pressing w from keyboard activates this case and robot moves forward
    Serial.println("Robot moves forward");
    fwd();
    break;        // restart the loop function
    case 'd':     // pressing d from keyboard activates this case and robot turns right
    Serial.println("Robot turns right");
    right();
    break;
    case 'a':     // pressing a from keyboard activates this case and robot turns left
    Serial.println("Robot turns left");
    left();
    break;
    case 's':     // pressing s from keyboard activates this case and robot stops
    Serial.println("Robot stops");
    Stop();
    break;
    case 'z':     // pressing z from keyboard activates this case and robot moves back
    Serial.println("Robot moves back");
    back();
    break;
  }
   
}
void Stop() // function details
{
  digitalWrite(lmt1,LOW);   // logic to stop all motor signal 0 volt
  digitalWrite(lmt2,LOW);
  digitalWrite(rmt1,LOW);
  digitalWrite(rmt2,LOW);
}
void left()
{
  digitalWrite(lmt1,LOW);   // logic to move left. Right motor moves forward and left motor backwards
  digitalWrite(lmt2,HIGH);
  digitalWrite(rmt1,HIGH);
  digitalWrite(rmt2,LOW);
}
void right()                // logic to move right. Left motor moves forward and right motor backwards
{
  digitalWrite(lmt1,HIGH);
  digitalWrite(lmt2,LOW);
  digitalWrite(rmt1,LOW);
  digitalWrite(rmt2,HIGH);
}
void fwd()                   // logic to move forward. both motor moves forward
{
  digitalWrite(lmt1,HIGH);
  digitalWrite(lmt2,LOW);
  digitalWrite(rmt1,HIGH);
  digitalWrite(rmt2,LOW);
}
void back()                 // logic to move Backwards. both motor moves backwards
{
  digitalWrite(lmt1,LOW);
  digitalWrite(lmt2,HIGH);
  digitalWrite(rmt1,LOW);
  digitalWrite(rmt2,HIGH);
}

Power_Broker

Try this fix:

Code: [Select]

void loop()
{
  if(Serial.available())
  {
    value=Serial.read(); //it will read the data recieved by xbee
  }
.
.    //rest of code
.
}
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

PaulS

http://www.ebay.com/itm/Motor-Stepper-Servo-Shield-XBee-Wireless-Proto-motor-Shield-for-arduino-/311719802701?hash=item4893f2b74d:g:DZcAAOSwAoRXFg4k 
I've never seen one of those. I just might have to get one. Well, except for the fact that you are forced to connect the XBee to the hardware serial pins, preventing debugging. Rats.

Which position do you have the switch in? USB or Micro?

What kind of XBees do you have? How are they configured?
The art of getting good answers lies in asking good questions.

Coding Badly


@mikehj24, please do not cross-post.  Other thread removed.


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy