Xbee to Xbee - communication failure
hi , last school year , i'm working arduino , xbee project. ive got 2 arduino uno's , 2 xbee schields .
i'm making boat , have boat 2 motors in , , remote control . each has 1 uno , 1 xbee.
i'll made 2 programs 1 program reads 2 potentiometers , , calculates speed.. works pretty , when open serial monitor , move 1 of potentiometers sends serial information : (l249r249)
l & r left , right motor , wanted .
in mij other arduino have program must recieve information , use pwm control motors of boat
when open serial monitor , , type : (l0r249)
the left motor stand still , , right motor rotate @ max speed , can type every singal , works fine.
but when put jumpers on xbee , , try programs , nothing moves , recieve led on arduino motors isn't on or blinking ...
i configurated xbee's ctu , tested program , worked : http://arduino.cc/it/guide/arduinoxbeeshield
so dont .. got right information send , recieve program works perfect , xbee's configurated perfect , test program works al dont ..
i hope knows why ..
already & grtz belgium !
i'm making boat , have boat 2 motors in , , remote control . each has 1 uno , 1 xbee.
i'll made 2 programs 1 program reads 2 potentiometers , , calculates speed.. works pretty , when open serial monitor , move 1 of potentiometers sends serial information : (l249r249)
l & r left , right motor , wanted .
code: [select]
//declaratie
int analogpin1 = 4;
int analogpin2 = 5;
int dl = 0;
int dr = 0;
int linksemotor = 0;
int rechtsemotor= 0;
int analogl = 5;
int analogr = 6;
int snelheidbegin = 0;
int richtingbegin = 0;
void setup() // toekennen functie van de i/o
{
pinmode(analogpin1, input);
pinmode(analogpin2, input);
pinmode(analogl,output);
pinmode(analogr,output);
serial.begin(9600); // initializeer de seriele communicatie
} // einde van void setup
void loop()
{
int snelheid = map(analogread(analogpin1), 0, 1023, 0, 499);
int richting = analogread(analogpin2);
if (abs(snelheidbegin - snelheid)> 2 || abs(richtingbegin - richting)>2)
{
snelheidbegin = snelheid;
richtingbegin = richting;
if ((richting > 499) && (richting < 524)) {
dl = 0;
dr = 0;
}
else if (richting < 500) {
dl = 499 - richting;
}
else {
dr = richting - 524;
}
if (dl > snelheid){
dl = snelheid;
}
if (dr > snelheid){
dr = snelheid;
}
linksemotor = snelheid - dl;
rechtsemotor = snelheid - dr;
serial.print("(");
serial.print("l");
serial.print(linksemotor/2);
serial.print("r");
serial.print(rechtsemotor/2);
serial.print(")");
delay (50);
} // einde van if(snelheidbegin != snelheid || richtingbegin != richting)
} // einde van voidloop
in mij other arduino have program must recieve information , use pwm control motors of boat
when open serial monitor , , type : (l0r249)
the left motor stand still , , right motor rotate @ max speed , can type every singal , works fine.
code: [select]
//declaratie
#include <math.h>
int pwmout1 = 5;
int pwmout2 = 6;
string inputstring = ""; //
string strl = ""; //
string strr = "";
int charcount = 0; //
unsigned long vall = 0; //
unsigned long valr = 0;
int l = 0; //
int r = 0; //
int e = 0;
boolean stringcomplete = false; //
char stx = '(';
char etx = ')';
void setup()
{
// toekennen functie van de i/o
pinmode(pwmout1, output);
pinmode(pwmout2, output);
// initializeer de seriele communicatie
serial.begin(9600);
// reserveer 200 bytes voor de inkomende string
inputstring.reserve(200);
}
void loop()
{
if (stringcomplete)
{
serial.println(inputstring);
serial.println(charcount);
l = inputstring.indexof("l");
r = inputstring.indexof("r");
e = inputstring.indexof(")");
serial.print("posities lr: l");
serial.print(l);
serial.print("r");
serial.print(r);
strl = inputstring.substring(l+1,r);
strr = inputstring.substring(r+1,e);
vall = convertstring2int(strl);
valr = convertstring2int(strr);
serial.println(strl);
serial.println(strr);
serial.println(vall);
serial.println(valr);
serial.println("the end");
analogwrite(pwmout1,vall);
analogwrite(pwmout2,valr);
inputstring = "";
strl = "";
strr = "";
charcount = 0;
vall = 0;
valr = 0;
stringcomplete = false;
}
} // einde van void loop
void serialevent ()
{
while (serial.available())
{
// read new byte
char inchar = (char)serial.read();
// add byte inputstring
inputstring += inchar;
// increment charcount 1
charcount = charcount+1;
// if incoming character ')', set flag
// main "loop" can start parsing inputstring.
if (inchar == etx)
{stringcomplete = true;}
}
} // einde van void serialevent
unsigned long convertstring2int(string x)
{
serial.println();
serial.print ("start converting ");
serial.print (x);
serial.print (" int - length =");
unsigned long addval=0;
unsigned long sum=0;
unsigned long result=0;
unsigned long digit = 0;
unsigned long length = x.length();
unsigned long tenpow =1;
serial.println (length);
for (unsigned long i=0; i<length ; i++)
{
serial.print ("tenpow = ");
serial.println (tenpow);
serial.print ("loop: ");
serial.print(i);
serial.print (" - digitstr: ");
string digitstr = x.substring(length-(i+1),(length+1)-(i+1));
serial.print(digitstr);
if(digitstr == "0")digit=0;
if(digitstr == "1")digit=1;
if(digitstr == "2")digit=2;
if(digitstr == "3")digit=3;
if(digitstr == "4")digit=4;
if(digitstr == "5")digit=5;
if(digitstr == "6")digit=6;
if(digitstr == "7")digit=7;
if(digitstr == "8")digit=8;
if(digitstr == "9")digit=9;
serial.print (" - digit: ");
serial.print (digit);
addval = round (round (tenpow)*round(digit));
serial.print (" - addval: ");
serial.print (addval);
serial.print (" - former result ");
serial.print (sum);
sum = round (addval + round(sum)); //
serial.print (" - new result ");
serial.println (sum);
tenpow = round(tenpow * 10); //
result = sum;
}
return result;
}
but when put jumpers on xbee , , try programs , nothing moves , recieve led on arduino motors isn't on or blinking ...
i configurated xbee's ctu , tested program , worked : http://arduino.cc/it/guide/arduinoxbeeshield
so dont .. got right information send , recieve program works perfect , xbee's configurated perfect , test program works al dont ..
i hope knows why ..
already & grtz belgium !
quote
already & grtz belgium !
don't use capital letters start sentences in belgium? or, shift key broken?
quote
i hope knows why ..
i'm going karmac magnificent impression, , it's line 78 needs changed.
if, rather guesses, want real help, posting code might idea.
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Xbee to Xbee - communication failure
arduino
Comments
Post a Comment