We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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!
Answers
And it is May 2016, and another one stumbled in the same problem. I posted an question regarding conversion from string to int, but apparently I have the same problem as you posted. I was sending data every 10ms, and therefore the ammount of data was out of control, consequentially I couldn't convert to integer. Sending data every 200ms works Ok.
Hi rgorazd! The problem it's caused by the ketai class. In the file "KBluetoothConnection.class" exist a line: "Thread.sleep(100L);". This line causes the delay to read the bluetooth, because the process is executed with a for in bucle ( for(;;){...} ). You need download the ketai in the github, modify the line and compile the ketai files.
you guys have a workflow for setting this system up ? im trying to call functions via BT but cant find how t add android mode to my P2 tho i do see it is or should be in the top right drop down bar but is not