So, I'm using Processing to communicate with an Arduino through a Bluetooth serial port.
I'm trying to understand why when I write bytes to the Serial port, it's very slow.
Here's an example to understand:
import processing.serial.*;
Serial myPort;
byte arr[] = {0,1,2,3,4,5,6,7,8,9,
0,1,2,3,4,5,6,7,8,9,
0,1,2,3,4,5,6,7,8,9,
0,1,2,3,4,5,6,7,8,9,
0,1,2,3,4,5,6,7,8,9};
void setup()
{
size(400, 600);
myPort = new Serial(this, "/dev/tty.HC-05-DevB", 57600);
}
void draw()
{
myPort.write(arr);
//myPort.write((byte)1);
println(millis());
}
This gives me the following output:
3183
3200
3401
3652
3902
4152
4402
4652
4902
5152
5402
5655
5902
6152
..
So I'm sending a 'frame' of 50bytes 4 times a second. But the STRANGE thing is that if I send, instead of a 50bytes frame, just a single byte (uncommenting the 18th line and commenting the 17th), the result is EXACTLY the same.
How can this be possible? If the max speed is 4 bytes per second, how it comes that i can send 4 frames of 50 bytes in one second?
Thank you for the help, I've also tried looking in the Processing source code to understand how this works but no luck..