advice for programming XBee at runtime...

I'm setting up two arduino's with XBee's and the Sparkfun xbee sheilds to transmit data between two systems.

With the boards programmed and the XBee's in their default setting, it works perfectly, except it is too slow.

I'm trying to write code that will set the xbees at the desired baud rate when the board boots, so that I can use the boards for other tests at the same time, without taking the xbee's off to reprogram them with a computer.

Attached is the code for the reception end. The changes I made should be pretty obvious, and as soon as I run this code the system stops working. Using the port monitor, I am still only able to see output at 9600 baud, and it is usually garbage.

Have I made any obvious mistakes or logical errors in my code?

Many thanks...

bd38400_PulseReceiver.pde (1.14 KB)

  delay(2000); //delay at startup just for safety sake

Useless, unless you just like to waste time.

  Serial.begin(9600);
  Serial.flush();

Initiate the serial port, and immediately dump all data in the receive buffer. In the 62 nanoseconds between these two function calls, how much data do you suppose has arrived?

With the boards programmed and the XBee's in their default setting, it works perfectly, except it is too slow.

What about with the boards programmed (differently), but the XBees configured to transmit at 115200?

delay(2000); //delay at startup just for safety sake
Useless, unless you just like to waste time.

Fair enough. I'd read, like the "trash character" some people have had luck with that getting their xbee into programming mode.

  Serial.begin(9600);

Serial.flush();



Initiate the serial port, and immediately dump all data in the receive buffer. In the 62 nanoseconds between these two function calls, how much data do you suppose has arrived?

None. For one, the xmitter will be going through the same boot process, for another, any data that arrives at this time will not be important, as we will be waiting a few seconds at boot for the systems to come ready and gain full communications.

With the boards programmed and the XBee's in their default setting, it works perfectly, except it is too slow.

What about with the boards programmed (differently), but the XBees configured to transmit at 115200?

I'm happy to try it. Can you give me any advice on how my code might correctly configure the xbee to 115200? That is what I'm trying to accomplish, and that is where I'm having the issue I'm asking for help with.

Can you give me any advice on how my code might correctly configure the xbee to 115200? That is what I'm trying to accomplish, and that is where I'm having the issue I'm asking for help with.

What I was asking was if the process works, but is too slow, if the XBee is configured using X-CTU, rather than programatically. If so, I see no reason not to write all sketches assuming that the XBees talk to each other at 115200. There is no need, necessarily, for the Arduino to talk to the XBee at the same speed that the XBee talks to the other XBee, as long as it is not talking to the XBee faster than the XBee talks to the other XBee.

The problem we're having is, we're trying to transmit one byte of data 4000 times per second. By my math, that requires the 38400 baud I'm trying to reach in the code.

I could use xctu, but since I've started on this path I'd like to see if I can't get the arduino to program the xbee. It should work, theoretically, I'm just not sure what I'm doing wrong.

By my math, that requires the 38400 baud I'm trying to reach in the code.

That would be the minimum. Any faster value would also work.

I could use xctu, but since I've started on this path I'd like to see if I can't get the arduino to program the xbee. It should work, theoretically, I'm just not sure what I'm doing wrong.

Can't help you there. I've always configured the XBee using X-CTU. I figure the Arduino's job is to send data to the serial port, not program XBees.

If you get it to work, though, let us know how.

Now that I think about it, when you reprogram an xbee in xctu, you don't lose connectivity as soon as you enter the command... so the power down must be integral to implementing the new speed.

if I'm right, my only option will be xctu for this.

There are two different baud rates being used. The one that the Arduino or X-CTU uses to talk to the XBee and the one that the XBee uses to talk to other XBees. It is important to be clear which one you are trying to configure. I'm sure that there are different commands for setting each speed.

X-CTU does not have a problem with still being able to communicate with the XBee when the speed being set it is the XBee to XBee speed, and I presume it doesn't have a problem with the PC to XBee change either, since it switches speeds itself after telling the XBee to change speeds.