Pages: 1 2 [3] 4 5   Go Down
Author Topic: Data over XBee works for a few seconds then stops...  (Read 7163 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
PaulS, his baud rate is 115400, is 9600 a valid comparison?
I'll try again at higher baud rates this afternoon (left the stuff home) and post my results.

I was just pointing out a test that I though OP could perform. If it works, then the problem is not with the hardware. If it doesn't, then the problem is not with the software or XBees themselves.
« Last Edit: October 17, 2011, 05:14:14 am by PaulS » Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It also occurred to me that whenever I test the sending arduino directly to the computer (via USB) the code and serial reading in Max/MSP works fine, and as far as I've tested, runs indefinitely, so it's only when I've introduced the XBees and Explorer into the equation.

Also is your test sending data from the explorer to the wireless Arduino?
Would it make any difference that the data is going the other way? (arduino to explorer)
Like does the Explorer have a smaller serial buffer than an arduino (or however that works)
« Last Edit: October 17, 2011, 05:57:06 am by kriista » Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 935
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No, there's a lot more there that you don't see.  The XBee (this is provably true for series 2, I don't know about series 1) takes what you give it, wraps it up in a packet with the originating address, checksums, lengths, other addresses, etc and then sends it.  The receiving end sucks that stuff off, and in the case of transparent mode, gives you back the data you put in.  So, for a small packet of data, you could be sending twice that in overhead over the air.  For larger packets, this is marginal, but still there.  The devices have to do this to be able to form a mesh and do forwarding.

And, I don't think you can outrun the serial port with the arduino.  If you send "hello", it all goes out.  You can prove that by just running it serial.  What you put into the serial port to show up on a laptop over the USB port, shows up, it doesn't get lost; regardless of baud rate.  This is because the transmit buffer on the arduino is monitored by the serial code to be sure you can stuff everything into it.  This means that changing baud rate will change the speed you send.  So, you'll pass less characters at a lower rate than you pass at a higher rate.  Sort of makes sense when you think about it.  However, the radio transmit rate on the XBee doesn't depend on how fast you send it character to send, it depends on how fast it can send and how many times it retries, forwards, redirects etc.  So, at 9600 baud input, it has a lot of time to do the overhead compared to your rate where there isn't much time left over.

Another thing, the two XBees don't have to be the same baud rate.  The various tutorials out there hint that you do, but you don't have to do this.  One can be 9600 and the other can be 57K.  When you set the baud rate, your setting the rate the arduino or USB can talk to it, not the over-the-air speed.  The radio transmit speed is handled solely by the XBee network.  Basically, it runs as fast as it can all the time.  That's why the 900MHz devices run so much slower than the 2.4GHz ones.  Higher frequency, higher data rate.  So, you can lower the baud rate, which will lower the data rate and tell you if you are exceeding the max datarate of your little network.

This is difficult to explain, I hope it made sense.
Logged

Trying to keep my house under control http://www.desert-home.com/

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Series 1 doesn't do mesh stuff, so I think it's much less overhead than series 2. Granted, there's still probably a fair amount of overhead.

I'm going to try setting up a handshake type thing between Max/MSP and the Xbee/arduino as it would solve this problem, as well as the inevitable cross chatter between two arduinos that I was going to have to deal with in the future. Hopefully that doesn't add much latency.
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 935
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I give up.  Have fun.
Logged

Trying to keep my house under control http://www.desert-home.com/

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm going to mess around with the straight (non handshake) variables too, it's just mid workweek really crushes my 'mess around with the arduino' time...
Logged

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

I tried my test again at different speeds. The only speed that worked was 9600 baud.
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That's not very promising for just straight piping data across then.
Logged

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

Quote
That's not very promising for just straight piping data across then.
Remind us again of your goals. Sending at 9600 baud allows you to send 960 bytes per second. For an accelerometer, with 3 axes, there are 6 data bytes (plus start and end markers for security), for an 8 byte packet. You can send 120 of those per second.
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There's 9 sensors total (3axis accel, 3axis gyro, 3axis compass) so three times that, also there's two of these sensor boards in total as well, so 18 sensors worth of data coming in all together.

The application is for a music/art performance situation where the sensors would be attached to the wrist of a painter, and that data (after kalman/marg filtering to determine absolute angles) would be used to capture and process the audio coming from the canvas itself (via contact mics). All the audio capturing/processing would happening in Max/MSP.

It's this:


Except there it's two people (I'm to the right of the canvas) doing the audio processing. So the sensor system would be to make it autonomous from musicians processing the sound.


Getting the information into the computer wouldn't be so bad, it's just the performance-based, real-time nature of it that would suffer if the latency is too great. As a performer, latency about 10-20ms starts to 'feel' really shitty, and couple that with the fact that there's often very fast movements in the painting process, the faster that data can get to the computer, the better.

Hence trying to crank it up to 11500, and sending data across constantly.
Logged

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

I was able to send data from the PC to the Arduino, via the XBees at 115200, and the data appeared correctly in the serial monitor. It did not get echoed back completely correctly, though. I'll run another test, when I can, where the Arduino generates the data, to see of it can be streamed to the PC (without echo) at 115200, reliably, and for how long.
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah coming to the computer (via the USB explorer) is the only way it will be used.

I was looking at some handshake based serial stuff between the two and the code has a delay built in after each ADC read, which one of the authors of the code (the example included in the IDE under communication/callresponseserial) said the delay after each ADC read is for the ADC to 'settle'. That would certainly add extra latency/overhead if I add 2ms for each of the 18 total sensors.
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, finally had some free time to try to trouble shoot some more.

I got some handshake code working. Using the example in /communication/serialcallresponse as a starting point I tweaked the code to get all the analog inputs I have.

It works quite well, when connected over USB, however, when I go over Xbee, I don't get any data at all (other than the 'void establishContact()' loop).

I tested this in Max/MSP and using Serial Monitor. I keep getting '65' as my data coming in even if I send the Xbee the byte it's looking for.

The example also uses Serial.print (instead of Serial.write) even though it's supposed to be sending digital bytes. I'm trying to fix one thing at a time though, so ......


(edit: it looks like I never configured my Xbee's to have two way communication. they are now setup to talk two ways).

Even with this handshaking it stops working after a couple of seconds..... So unless there's some other kind of bottleneck I'm hitting, I don't really know what's happening.

Here's the code:

Code:
#define aX A0
#define aY A1
#define aZ A2
#define gX A6
#define gY A7
#define gZ A3

int AccX;
int AccY;
int AccZ;
int GyroX;
int GyroY;
int GyroZ;

int inByte = 0;         // incoming serial byte

void setup()
{
  Serial.begin(115200);
}

void loop()
{
    // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    inByte = Serial.read();
   
    AccX = analogRead(aX);
    AccY = analogRead(aY);
    AccZ = analogRead(aZ);
    GyroX = analogRead(gX);
    GyroY = analogRead(gY);
    GyroZ = analogRead(gZ);
   
    Serial.print(AccX, BYTE);
    Serial.print(AccY, BYTE);
    Serial.print(AccZ, BYTE);
    Serial.print(GyroX, BYTE);
    Serial.print(GyroY, BYTE);
    Serial.print(GyroZ, BYTE);
  }
}

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('A', BYTE);   // send a capital A
    delay(300);
  }
}
Logged

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

I might be blind, but I don't see where you call establishContact().
Logged

Manchester, UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, good call. It was in the void setup() but I guess I copied it out when trimming the code up to post. Going to double check that it's actually on the Arduino with the call in there.

Off the top of my head it was working when connected directly, it was just the wireless part that failed.

Here's the "full" code (with the Wire/i2c and comments in there):

Code:
#include <Wire.h> //I2C Arduino Library
#define address 0x1E //0011110b, I2C 7bit address of HMC5883

#define aX A0
#define aY A1
#define aZ A2
#define gX A6
#define gY A7
#define gZ A3

// define sensor variables
int AccX;
int AccY;
int AccZ;
int GyroX;
int GyroY;
int GyroZ;

int inByte = 0;         // incoming serial byte

void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(115200);
  Wire.begin();
  //Put the HMC5883 IC into the correct operating mode
  Wire.beginTransmission(address); //open communication with HMC5883
  Wire.send(0x02); //select mode register
  Wire.send(0x00); //continuous measurement mode
  Wire.endTransmission();
  establishContact();  // send a byte to establish contact until receiver responds
}

void loop()
{
 
    int x,y,z; //triple axis data for magnetometer

  //Tell the HMC5883 where to begin reading data
  Wire.beginTransmission(address);
  Wire.send(0x03); //select register 3, X MSB register
  Wire.endTransmission();
 
    //Read data from each axis of magnetometer, 2 registers per axis
  Wire.requestFrom(address, 6);
  if(6<=Wire.available()){
    x = Wire.receive()<<8; //X msb
    x |= Wire.receive(); //X lsb
    z = Wire.receive()<<8; //Z msb
    z |= Wire.receive(); //Z lsb
    y = Wire.receive()<<8; //Y msb
    y |= Wire.receive(); //Y lsb
  }
 
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    inByte = Serial.read();
   
    AccX = analogRead(aX);
    AccY = analogRead(aY);
    AccZ = analogRead(aZ);
    GyroX = analogRead(gX);
    GyroY = analogRead(gY);
    GyroZ = analogRead(gZ);
   
    Serial.print(AccX, BYTE);
    Serial.print(AccY, BYTE);
    Serial.print(AccZ, BYTE);
    Serial.print(GyroX, BYTE);
    Serial.print(GyroY, BYTE);
    Serial.print(GyroZ, BYTE);
    Serial.print(x, BYTE);
    Serial.print(y, BYTE);
    Serial.print(z, BYTE);
  }
}

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('A', BYTE);   // send a capital A
    delay(300);
  }
}
Logged

Pages: 1 2 [3] 4 5   Go Up
Jump to: