Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Serial Library and Arduino

$
0
0
Hi to everyone.
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:
  1. import processing.serial.*;
  2. Serial myPort;
  3. byte arr[] = {0,1,2,3,4,5,6,7,8,9,
  4.               0,1,2,3,4,5,6,7,8,9,
  5.               0,1,2,3,4,5,6,7,8,9,
  6.               0,1,2,3,4,5,6,7,8,9,
  7.               0,1,2,3,4,5,6,7,8,9};

  8. void setup() 
  9. {
  10.   size(400, 600);
  11.   myPort = new Serial(this, "/dev/tty.HC-05-DevB", 57600);
  12. }

  13. void draw()
  14. {
  15.  myPort.write(arr); 
  16.  //myPort.write((byte)1);
  17.  println(millis());
  18. }
This gives me the following output:
  1. 3183
  2. 3200
  3. 3401
  4. 3652
  5. 3902
  6. 4152
  7. 4402
  8. 4652
  9. 4902
  10. 5152
  11. 5402
  12. 5655
  13. 5902
  14. 6152
  15. ..
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..

Viewing all articles
Browse latest Browse all 1768

Trending Articles