Pages: [1]   Go Down
Author Topic: XBee transmission via Processing  (Read 723 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 75
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello forum, I am running into some strange behaviour trying to set up comms via XBee. My setup is as follows:

- laptop connected to XBee Explorer (USB).
- XBee Explorer mounted with XBee series 2, running as Coordinator (AT), with ATRO (packetization timeout) set to 0, with its destination address (DL and DH) set to the address (SL and SH) of the Arduino based XBee.

- Arduino (Mega) with XBee shield.
- XBee on shield set up as Router/end device AT, ATRO set to 1 (was getting errors with 0 but can't remember what they were at the moment), and its DL and DH set to the the respective SL and SH values of the coordinator.

I have set up a simple protocol in the Arduino, a linefeed in the input buffer signals a full command sentence. A command sentence consists of a command byte followed by a string coding for a numeric value. So, for example, to send a steering command for numeric value -10 (command byte 'b') we send "b-10" followed by a newline.

Now, all this works absolutely fine when done manually from a terminal (I use GtkTerm). Processing, on the other hand, runs into a hell of a lot of trouble. Look at the following code snippet:

Quote
  String s;

  s = new String("b" + steering + "\n");
  print("Sending:" + s);
  myPort.write(s);

  delay(100);

  s = new String("c" + throttle + "\n");
  print("Sending:" + s);
  myPort.write(s);


where "steering" and "throttle" are int variables to be transmitted.

This code works only by sticking the delay in there. Trying to squeeze the two command sentences closer (either by ommiting the delay or by dumping them into the same string) results in garbage read by the Arduino (which helpfully echoes what it receives).

To make matters more weird, this works when in the Processing code's "mousePressed()" method (initially tried it so that the coordinates of mouse presses in the window would correspond to throttle and steering values). However, when I renamed the method so that it gets called at set intervals (large ones, half a second to five seconds) to update the remote values, all hell breaks loose. The arduino reads garbage, sentences are omitted or truncated or parsed improperly. Sometimes, the Arduino resets  :o, which I can tell because I have included a "Hello world" in its setup() which it spits out occasionally.

I really can't figure out what the problem might be but it must have something to do with the Processing/XBee interface. Any ideas?
Logged

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

Quote
- XBee Explorer mounted with XBee series 2, running as Coordinator (AT), with ATRO (packetization timeout) set to 0

This is the only thing that I can see that you are doing that is a bit strange. You are allowing 0 time for the data to be packeted for transmission. Why?
Logged

Pages: [1]   Go Up
Jump to: