Pages: [1] 2   Go Down
Author Topic: Change Power Level Xbee (series1)  (Read 1908 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys I want to change the power level of my xbees through source code to my college project.
I have 2 XBee 1mW Chip Antenna - Series 1 (802.15.4), one XBee Explorer USB and one arduino duemilanove connected to a XBee Shield.

I already now how to set the power level using the X-CTU software, but I want to change that through source code because my project is about power consumption of a wirelles network. So I want to now if there is a library or a function in one of the standard libraries that do the power level change.
I had found some old libraries that don't have the function that I'm looking for.

Thanks. 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can send AT commands to the XBee, just like X-CTU does, to change settings.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But there's a way to send this AT command through source code?
Because I'm trying to do something autonomous, that don't need my interaction with serial communication.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But there's a way to send this AT command through source code?
Yes.

Quote
Because I'm trying to do something autonomous, that don't need my interaction with serial communication.
How is the XBee communicating with the Arduino? Semaphore flags waving around?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One of the Xbees is connected to the USB Xplorer that's connected to the computer. The second Xbee is connected to one Xbee Shield that's connected to one arduino duemilanove,being powered trough a external power supply (VIN/GND).
I want that the xbee that's connected to arduino/xbee shield could change your power level on an autonomous way to save power, decreasing the power level when signal is strong and increasing when signal is weak.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How is the XBee communicating with the Arduino?
You didn't answer this question. I'll tell you - the communication is via Serial.print(), Serial.write(), Serial.println(), Serial.read(), and Serial.available().

So, yes, you can send +++ to the XBee, to put it into command mode, and then send it AT commands, using Serial.print().
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How is the XBee communicating with the Arduino?
You didn't answer this question. I'll tell you - the communication is via Serial.print(), Serial.write(), Serial.println(), Serial.read(), and Serial.available().

So, yes, you can send +++ to the XBee, to put it into command mode, and then send it AT commands, using Serial.print().

Thanks PaulS
I will try this:
Serial.print(+++);
Serial.print(ATPL);
Serial.print(x); //4,3,2,1

I will tell you if it works.

If that's
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I will try this:
Serial.print(+++);
Serial.print(ATPL);
Serial.print(x); //4,3,2,1
It may be necessary to play with delay() times, to give the XBee time to enter command mode.

It definitely will be necessary to read what the XBee is responding with, to assure, for instance, that it entered command mode, before sending it an AT command.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll do a test within the code using the Serial.read(), to see if the command was received correctly, and I will put the delay too.
And I'll do it on Wednesday because tomorrow I have a lot of classes.

But thanks PaulS, you were very helpful, helped me a lot.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

   I'm using the following code just to do some tests:

Code:
void setup ()
{
  Serial.begin(9600);
}

void loop ()
{
  Serial.print("+++");
  delay(4000);
  Serial.println("ATPL");
  delay(1000);
  Serial.println("ATPL 2");
  delay(1000);
  Serial.println("ATPL");
  exit(1);
}


   But that isn't working, because after I did the upload to arduino board and connected the xbee shield with the xbee and I open the X-CTU serial terminal to see if that's working.
   The terminal shows me the code but don't return me the "OK" after the "+++", the ATPL command is typed autonomous by arduino but doesn't work.
   Do you guys nows what's wrong with the code?
   Thanks

"Sorry for me english, is not my native language"
« Last Edit: March 28, 2012, 10:05:18 am by acintra » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do you guys nows what's wrong with the code?
That code should be in setup(), or a function that gets called only as needed, not in loop().

The code talks to the XBee, but doesn't listen to the XBee. Why not?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do you guys nows what's wrong with the code?
That code should be in setup(), or a function that gets called only as needed, not in loop().

The code talks to the XBee, but doesn't listen to the XBee. Why not?

The code isn't listening to xbee because this is only a prototype code, I'm using that just to learn how to use the AT commands in the source code. After I will do a complete code to my project
But thanks PaulS like always you helped me a lot.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The code isn't listening to xbee because this is only a prototype code, I'm using that just to learn how to use the AT commands in the source code.
In the production version, you might be able to get away with not reading the reply. In the prototype/development phase it is crucial to read the reply, to make sure that it is what you think are getting.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok that's still not working...
This is the code that I'm using now:

Code:
void setup ()
{
  Serial.begin(9600);
 
  Serial.print("+++");
  delay(3000);
  if(Serial.read()=='OK'){
  Serial.println("ATPL");
  delay(1000);
  if(Serial.read()>=3){
  Serial.println("ATPL 2");
  delay(1000);
  Serial.println("ATPL");
  }
  }
}

void loop ()
{
 
}

But I'm still note receiving the "OK" from the command "+++", and not receiving too the return of ATPL.
I listened to the returns too like you said. I really don't now what to do to this works.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Serial.read() returns one byte. That one byte is almost certainly not equal to the multibyte constant 'OK'.
Logged

Pages: [1] 2   Go Up
Jump to: