Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accelerometer data over Bluetooth does not work #7

Open
smartyw opened this issue Jun 1, 2018 · 0 comments
Open

accelerometer data over Bluetooth does not work #7

smartyw opened this issue Jun 1, 2018 · 0 comments

Comments

@smartyw
Copy link

smartyw commented Jun 1, 2018

With the accelerometer service included in a hex file by including the following line of code:

    new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);

it should be possible for a connected Bluetooth client like a smartphone to switch on accelerometer data notifications. After enabling notifications, none are ever received however.

Here's a simple test application:

/**
 * This is a simple template for use with Calliope mini.
 *
 * @copyright (c) Calliope gGmbH.
 * @author Matthias L. Jugel.
 *
 * Licensed under the Apache License 2.0
 */

#include <MicroBit.h>

MicroBit uBit;

void onConnected(MicroBitEvent)
{
    uBit.display.scroll("C");
}

void onDisconnected(MicroBitEvent)
{
    uBit.display.scroll("D");
}

int main(void)
{
    uBit.init();
    uBit.serial.baud(115200);
    uBit.serial.send("Calliope BLE accelerometer test v1.0\r\n");
    uBit.display.scroll("BLE ACC");
    uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected);
    uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected);

    uBit.accelerometer.setRange(8);
    new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);

    release_fiber();
}

Furthermore, reading the Accelerometer Data characteristic always returns a value of zero. Here's a screenshot of nRF Connect showing this:

image

I investigated and found a clue.

There are two accelerometer drivers in the source tree. One of them creates events for component ID MICROBIT_ID_ACCELEROMETER (=4) and the other uses component ID (BMX055_ACC_ADDRESS<<1)=48.

The MicroBitAccelerometerService.cpp class registers for events from MICROBIT_ID_ACCELEROMETER but never receives any callbacks for that event.

I changed MicroBitAccelerometerService.cpp to register for events from component ID 4:

     printf("About to register for accelerometer events\r\n");
    if (EventModel::defaultEventBus) {
        int id = BMX055_ACC_ADDRESS<<1;
        printf("id=%d\r\n",id);
        EventModel::defaultEventBus->listen(id, MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE, this, &MicroBitAccelerometerService::accelerometerUpdate,  MESSAGE_BUS_LISTENER_IMMEDIATE);
    }

But this made no difference. Callbacks were not received.

As an experiment, I then registered for the same events from MICROBIT_ID_ACCELEROMETER from within my main method, like this:

 int main(void)
{
    uBit.init();
    uBit.serial.baud(115200);
    uBit.serial.send("Calliope BLE accelerometer test v1.0\r\n");
    uBit.display.scroll("BLE ACC");
    uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected);
    uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected);

    uBit.accelerometer.setRange(8);
    new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);

    // id =    BMX055_ACC_ADDRESS<<1;
    // MICROBIT_ID_ACCELEROMETER, MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE

    int id =    BMX055_ACC_ADDRESS<<1;

    uBit.serial.printf("MICROBIT_ID_ACCELEROMETER: %d\r\n",MICROBIT_ID_ACCELEROMETER);
    uBit.serial.printf("id                       : %d\r\n",id);

   uBit.messageBus.listen(MICROBIT_ID_ACCELEROMETER, MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE, onAccelerometerUpdate);

    release_fiber();
}

Now I receive callbacks in the accelerometer service class and the Bluetooth accelerometer service is working.

So, somewhere I think there's a mix up with component IDs used for events. I'm also not sure why you include both accelerometer drivers in the build. Is that deliberate or a mistake?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant