Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

Modify onBluetoothDataEvent() function execution?

$
0
0

Hi!! Actually, I'm working with communication between a GY-80 IMU and Android APP via Bluetooth. The communication its correct, using 115200 bauds in the two bluetooth. The problem it's when I'm using the onBluetoothDataEvent() function to read data of the bluetooth, the string return me a lot of lines of the Arduino port serial .

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

void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

bt = new KetaiBluetooth(this);

}

void onActivityResult(int requestCode, int resultCode, Intent data) {

bt.onActivityResult(requestCode, resultCode, data); contador+=1;

}

void setup() {

    bt.start();

    bt.getPairedDeviceNames();

    bt.connectToDeviceByName("HC-06");

} //Function to take bytes data from bluetooth this function is executed 1 time every 0.1 seconds

void onBluetoothDataEvent(String who, byte[] data) {

//Transform data to string

 info = new String(data); //

}

Investigating, I saw that the function it's executed 10 times in 1 second, and this cause to accumulate data on the temporal string variable "info", because Arduino it's sending 100 times per secon (0.01 delay), and the function onBluetoothDataEvent() it's reading bytes variable at 1 time every 0,1 second (checked with a simple counter inside the function). Using other App of Android, I received 1:1 transmissions and data view, discarding to be a problem bluetooth mobile.

Any possibility to change the execution of the function onBluetoothDataEvent() to read at real time bluetooth data?

Thanks and sorry for my poor English!


Viewing all articles
Browse latest Browse all 941

Trending Articles