Slow data transmission from Arduino+Bluesmirf to P

Hi there,

I am trying to use a Bluesmirf bluetooth component attached to an Arduino duemillanove to send sensor values to my processing sketch. I finally managed to read values on the processing side, but I notice the data exchange is REALLY SLOW. I added some simple code to measure how much time it takes between readings. Using the USB cable I get 30ms average, but using the same code with the Smirf it takes 10x ( 300ms), making my project unusable.

Is this normal or I’m doing something wrong? Here’s the Arduino code:

// Arduino code
int counter = 0;

void setup()
{
  Serial.begin(9600); 
  while( Serial.available() <= 0 )
  {
    Serial.print('\r', BYTE );
    delay(300);
  }
}
 
void loop() 
{
  while( Serial.available() > 0 )
  {
    int inByte = Serial.read();
     counter++;
    if(counter >= 200 )
      counter = 0;

    Serial.print( 0, DEC );
    Serial.print( ',' );
    Serial.print( 1, DEC );
    Serial.print( ',' );
    Serial.print( 2, DEC );
    Serial.print( ',' );
    Serial.print( 3, DEC );
    Serial.print( ',' );
    Serial.println( counter, DEC );
  }
}

And the Processing one:

// Processing code

import cc.arduino.*;
import processing.serial.*;

Serial myPort;
boolean madeContact = false;
int lineFeed = 10;
int lastValue = 0;
int lastPing = millis();

void setup() 
{
  size(400, 200);
  println( Serial.list() );
  myPort = new Serial(this, Serial.list()[0], 9600 );
  myPort.bufferUntil( lineFeed );
}

void draw() {
  background(0);
  if( madeContact == false )
  {
    println( "----------------" );
    myPort.write('\r');
    delay(500);
  }
 
  stroke(255);
  line( 10, lastValue, 50, lastValue );
 
}

void serialEvent(Serial p )
{
  if( madeContact == false)
  {
    myPort.clear();
    madeContact = true;
    myPort.write( '\r' );
  }
  String myString = myPort.readStringUntil( lineFeed );
  if( myString != null )
  {
    myString = trim( myString );
    int sensors[] = int( split( myString, ',') );
    if( sensors.length == 5 )
    {
      for( int sensorNum=0; sensorNum<sensors.length; sensorNum++ )
      {
        print( "Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
      }
      lastValue = sensors[4];
      int time = millis() - lastPing;
      lastPing = millis();
      print( "  ::::  " );
      print( time );
      println();
      myPort.write( '\r' );
    }
  }
}

Thanks in advance!

You use 9600 baud
why not use faster transferrate?
here are som steps to change the baudrate of smirf:

just shooting of the hip here, don’t have this module…

Just reflect the baudrate in the sketch… :slight_smile:

Bluetooth is an old gsm phone standard and is inherently slow.
D.

Hey, thanks for the reply. I will definitely try to change the baud rate. However, since that's the rate set at the sketch, shouldn't it be that slow as well when connected via USB? Also, even though bluetooth may be a slow protocol, there are those devices like the Wiimote. Since they are intended for gaming they really need a FAST response (and indeed they seem to be fast enough).

In the example I posted I'm sending just a few integers, doesn't look like it should be that heavy...

thanks again

shouldn’t it be that slow as well when connected via USB?

Yes it should.

But all the baud rates both in processing and Arduino sketch should be the same, but as I said, I have not used this device, and I only have unhappy memories with bluetooth, but it is fast enough to support speach and wiimote so there should not be any trouble with few integers :wink:

9800 baud is 1,2 char every ms at optimal speed but the arduino needs time to process the data before it is sent (your code) so 30 ms sounds about right.

Oups! I tried attaching a cheap Conceptronic bluetooth dongle to my macbook and it happened to work (0ms delay). So looks like there’s an issue with my mac’s built-in bluetooth component??! does this sound familiar to anyone? (I’m on a Macbook Pro / Leopard 10.5.8)

thanks!