slow reading of serial port data

Hi all, I'm using ten XBee's 1mW Trace Antenna - Series 1 (802.15.4). They send an 11 bytes string 10 times per second at a baudrate of 9600. My problem is that when reading the data from the serial port in Processing that the buffer gets full and the data that I read out is "old". So I don't get real time data and this is crucial as I'm working with physiological data that I visualise real time. It works fine up to 5 devices.

My question is mainly where the bottle neck is? - Is it the rate at which I'm sending the data? I've checked and the amount of bytes I send every second is 1.29 Kbps. My type of XBee support up to 250 kbps.

  • Is it the baudrate at which the data is send, this is of course low now at 9600. If this is what is slowing it down, what rates do you advice?

  • Maybe it is the way I'm reading the data from the serial port? This is (part of) my Processing code:

myPort = new Serial(this, Serial.list()[2], 9600);
  myPort.bufferUntil('\n');
inString = myPort.readStringUntil('\n');
   if (inString != null) {
// do stuff with the incoming string
}

So the data is buffered and it stays in the buffer for a very long time when I have more then 5 devices sending data. So is there a better way to deal with the incoming data?

Sorry if I sound a bit thick, I'm quite new to this stuff. I'd really appreciate your advice on this. Thanks very much in advance, best, danielle.

Hi,

Can non of you Guru's give me a hint where to start looking? Any suggestions are greatly appreciated. TIA, danielle.

So the data is buffered and it stays in the buffer for a very long time when I have more then 5 devices sending data.

The data is buffered in Processing. It stays there until you read it - NOT a very long time.

This is (part of) my Processing code:

This is (part of) the answer:


Thanks Paul,

PaulS:
The data is buffered in Processing. It stays there until you read it - NOT a very long time.

This is my Arduino code:

Serial.print(analogRead(wind));
Serial.print(",");
Serial.print(analogRead(temp));
Serial.println(",5");
delay(100);

As you can see I produce a new line every 100 milliseconds for each of the 10 devices. So I don’t see why the buffer isn’t emptied every time a newline is in the buffer? Or maybe I misunderstand something?
It also puzzles me that it works fine with a couple of devices and then the buffer gets more and more full somehow? The readBuffer function is in the draw() part of the processing code so it should be reading out the buffer 60 times per second.

This is (part of) my Processing code:

This is (part of) the answer:


This code block is empty, could you please write your reaction again.

Thanks for your help, best, danielle.

As you can see I produce a new line every 100 milliseconds for each of the 10 devices.

If all the devices are sending data to one receiver, how are you keeping the packets separate? How are you preventing two devices from sending at once?

So I don't see why the buffer isn't emptied every time a newline is in the buffer? Or maybe I misunderstand something

Without seeing ALL of your Processing code, you won't get any more answers from me.

This code block is empty, could you please write your reaction again.

That was a clue-by-four. Please whack yourself with it.

The readBuffer function is in the draw() part of the processing code so it should be reading out the buffer 60 times per second.

You have 10 devices sending packets of data 10 times a second. That's 100 packets per second. You say you are reading 60 packets per second, and you don't understand why you get overflows. Hmmm...

PaulS:

The readBuffer function is in the draw() part of the processing code so it should be reading out the buffer 60 times per second.

You have 10 devices sending packets of data 10 times a second. That's 100 packets per second. You say you are reading 60 packets per second, and you don't understand why you get overflows. Hmmm...

Genius! I just upped the frame rate and now it works as expected. It is logical of course but sometimes one starts with the most difficult solutions.

If all the devices are sending data to one receiver, how are you keeping the packets separate? How are you preventing two devices from sending at once?

I don't prevent the devices from sending at the same time. They're completely independent. I wouldn't know how to time them... So if you have any suggestions I can check out, I'd appreciate it. I mark the packets with an id: Serial.println(",5"); The last line of my Arduino code is the id of the device, that way I can determine which data belongs to what device.

Thanks for your help, d.