•   over 5 years ago

Android - Unable to Detect Accelerometer X-Axis Changes

Hello there. I am able to pass verification and listen for button clicks. However, my app is unable to detect changes in the X-axis via accelerometer. I have been able to grab a reference to the Accelerometer service, enable the accelerometer, and enable the X-axis notification without any issues. The problem is that no notifications and characteristic changes are being detected. I have shook the device for 5 seconds straight without any result. Here is my code:

//Enable accelerometer by passing (byte[]) { (byte)0x01 }
//UUID for mAccelerometerConfigCharacteristic:
// "ffffffA1-00f7-4000-b000-000000000000"

private void setAccelerometerMode(byte[] mode) {
if (mAccelerometerConfigCharacteristic != null)
{
Log.i(TAG, "Starting accelerometer config write...");

mAccelerometerConfigCharacteristic.setValue(mode);

if (mBluetoothLeService != null)
{
if (mBluetoothLeService.writeCharacteristic(mAccelerometerConfigCharacteristic)) {
Log.i(TAG, "Write request sent successfully.");
}
}
}
}

//Enable X-axis notification by passing (byte[]) { (byte) 0x01, (byte) 0x00 }
//UUID for mAccelerometerXAxisNotifyCharacteristic:
// "ffffffA3-00f7-4000-b000-000000000000"

//UUID for SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG:
// "00002902-0000-1000-8000-00805f9b34fb"

private void setAccelerometerXAxisNotification(byte[] mode) {
if (mAccelerometerXAxisNotifyCharacteristic != null)
{
Log.i(TAG, "Starting X axis notify write...");

if (mBluetoothLeService != null)
{
mBluetoothLeService.setCharacteristicNotification(mAccelerometerXAxisNotifyCharacteristic, true);

BluetoothGattDescriptor descriptor = mAccelerometerXAxisNotifyCharacteristic.getDescriptor(
UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(mode);
mBluetoothLeService.writeDescriptor(descriptor);
}
}
}

Thanks in advance for your help!

  • 3 comments

  • Manager   •   over 5 years ago

    Hi shaq1nj,

    We checked this, and this is doesn’t work as documented.
    So to enable accelerometer you will have to write to FFF2 with different value. See below comments.
    Sorry for this undocumented change. We will update the developer's guide.

    //Enable accelerometer by passing (byte[]) { (byte)0x10 }
    //UUID for mAccelerometerConfigCharacteristic:
    // "fffffff2-00f7-4000-b000-000000000000"

    Please reply back with your results.

  •   •   over 5 years ago

    Thanks for your help! Everything works fine now. Changes in the X, Y, and Z axes are being reported as expected. Now I just need to decrease the latency delay, and I should be all set.

  • Manager   •   over 5 years ago

    You must disable the accelerometer yourself when you are done. Disable with 0x00.

Comments are closed.