Sumit Mourya
Lurker
Hello all,
I'am serially trasmitting arduino ADC Data to android device via USB OTG. my issue is that When Iam debugging the app I found that the data is getting received very slowly on the device.
below is the code for receiving the data. The serial library reads the data in a broadcast receiver and the data is passed to a USBSerial interface callback method. I assume it is slow because I put a Breakpoint inside if loop to check the buffer after receiving 3 seconds of data, but it never comes at the Breakpoint . Debugging method is through WiFi.
UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() { //Defining a Callback which triggers whenever data is read.
@override
public void onReceivedData(byte[] arg0) {
buffer = arg0;
int len ;
if (buffer.length > 5) {
String strIncom = new String(buffer, 0, 5);
if (strIncom.indexOf('s') == 0 && strIncom.indexOf('.') == 2) {
strIncom = strIncom.replace("s", "");
finaldata1 = Double.parseDouble(strIncom);
chdata = (int) Math.round((finaldata1 * 1023) / 5);
buffer_bt[ind_bt] = (int)chdata;
if (ind_bt>=Fs*3)
{
ind_bt=0;
for (int uu=0; uu<Fs*3; uu++) {
copy_buffer_bt[uu] = buffer_bt[uu];
}
ready_bt=1;
}
ind_bt = ind_bt +1;
}
}
}
};
My arduino side code is
void callback() // timer interrupt function called at a frequency of 256Hz.
{
if (b == 'a')
{
Serial.print('s');
Serial.print(floatmap(sensorValue,0,1023,0,5),2);
}
}
float floatmap(float x, float inMin, float inMax, float outMin, float outMax)
{
return(( x- inMin)*(outMax-outMin)/(inMax-inMin)+outMin);
}
kindly help!
I'am serially trasmitting arduino ADC Data to android device via USB OTG. my issue is that When Iam debugging the app I found that the data is getting received very slowly on the device.
below is the code for receiving the data. The serial library reads the data in a broadcast receiver and the data is passed to a USBSerial interface callback method. I assume it is slow because I put a Breakpoint inside if loop to check the buffer after receiving 3 seconds of data, but it never comes at the Breakpoint . Debugging method is through WiFi.
UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() { //Defining a Callback which triggers whenever data is read.
@override
public void onReceivedData(byte[] arg0) {
buffer = arg0;
int len ;
if (buffer.length > 5) {
String strIncom = new String(buffer, 0, 5);
if (strIncom.indexOf('s') == 0 && strIncom.indexOf('.') == 2) {
strIncom = strIncom.replace("s", "");
finaldata1 = Double.parseDouble(strIncom);
chdata = (int) Math.round((finaldata1 * 1023) / 5);
buffer_bt[ind_bt] = (int)chdata;
if (ind_bt>=Fs*3)
{
ind_bt=0;
for (int uu=0; uu<Fs*3; uu++) {
copy_buffer_bt[uu] = buffer_bt[uu];
}
ready_bt=1;
}
ind_bt = ind_bt +1;
}
}
}
};
My arduino side code is
void callback() // timer interrupt function called at a frequency of 256Hz.
{
if (b == 'a')
{
Serial.print('s');
Serial.print(floatmap(sensorValue,0,1023,0,5),2);
}
}
float floatmap(float x, float inMin, float inMax, float outMin, float outMax)
{
return(( x- inMin)*(outMax-outMin)/(inMax-inMin)+outMin);
}
kindly help!