slow bluetooth

edited January 2016 in Android Mode

Hi,

I'm trying to get two values as string structure from Arduino. Data coming pretty fast. (115200 baudrate - 50 ms delay) (my goal 10ms)

I would like to plot one of the values on the screen. But ploting is as the picture below.

Where is the problem? What should I do?

Thanks,

import android.content.Intent;
import android.os.Bundle;
import ketai.net.bluetooth.*;
import ketai.ui.*;
import ketai.net.*;
import oscP5.*;


KetaiBluetooth bt;
String info = "";
KetaiList klist;
float val1, val2;
//ArrayList<String> names;
int xPos = 1;        
float height_old = 0;
float height_new = 0;
boolean veri = true;
float[] gelen;


void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  bt = new KetaiBluetooth(this);
}




void setup()
{   
  background(0);    
  bt.start();
  stroke(255);
  fill(0xff); 
  textSize(32);

  if (bt.getDiscoveredDeviceNames().size() > 0)
  klist = new KetaiList(this, bt.getDiscoveredDeviceNames());
  else if (bt.getPairedDeviceNames().size() > 0)
  klist = new KetaiList(this, bt.getPairedDeviceNames());

  bt.discoverDevices();

  xPos = (width/4)+1;        
  height_old = (height/2)-5;
  stroke(0,0xff,0xff);
  strokeWeight(5);
  line(((width/4)-3),0,((width/4)-3),height);
  line(0,(height/2),width,(height/2));

  stroke(0xff, 0, 0);
  strokeWeight(2);
}


void draw()
{
  text(val1,50,50); 
  val1 = map(val1, 0, 1023, 0, (height/2)-5);
  height_new = (height/2)-5 - val1; 
  stroke(0);
  line(xPos,0,xPos,(height/2)-5);
  stroke(0xff, 0, 0);
  line(xPos - 1, height_old, xPos, height_new);
  height_old = height_new;

  if (xPos >= width) {
    xPos = width/4;
  }
  else {
    xPos++;
  }
}


void onBluetoothDataEvent(String who, byte[] data)
{
  info+= new String(data);  
  gelen = float(split(info, ' '));
  val1=gelen[0];
  val2=gelen[1];
  println(info); 
}


void onKetaiListSelection(KetaiList klist)
{
 String selection = klist.getSelection();
 bt.connectToDeviceByName(selection);

 klist = null;
}

1 2

Answers

  • void onBluetoothDataEvent(String who, byte[] data)
    {
      info+= new String(data);  
      gelen = float(split(info, ' '));
      val1=gelen[0];
      val2=gelen[1];
      println(info); 
    }
    

    you're adding the new values to the END of a string then reading the FIRST two values from the string.

  • There is no change.

    info = new String(data);

  • edited January 2016

    what exactly is the problem you are trying to show with those pictures? what are you expecting?

  • edited January 2016

    I try to draw an analog value mesaured by arduino to an android device.

    I could get values very slowly. So, the drawing is as seen pictures.

    I expect synchronously and continuously.

Sign In or Register to comment.