Pages: [1]   Go Down
Author Topic: advice for programming XBee at runtime...  (Read 854 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 - downloaded 5 times.)
Logged

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

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

Code:
  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?

Quote
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?
Logged

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


Quote
 
Code:
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.

Quote
Code:
  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.

Quote
Quote
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.

Logged

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

Quote
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.
Logged

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

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.
Logged

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

Quote
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.

Quote
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.
Logged

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

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.
Logged

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

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.
Logged

Pages: [1]   Go Up
Jump to: