Pages: [1]   Go Down
Author Topic: Slow data transmission from Arduino+Bluesmirf to P  (Read 339 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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:

Code:
// 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!
Logged

Pages: [1]   Go Up
Jump to: