This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Increasing Thingy:52 motion sensor MPU-9250 sampling rate beyond 200Hz

Hi,

I am trying to increase the sampling rate of the motion sensor on a Thingy:52. I managed to update the firmware and increase the BLE_GAP_ADV_INTERVAL_MAX from 200 to 1000. But when I set the characteristic over 200 the Thingy crashes.

What might be the reason for that? I am not using any other sensors so I would be willing to disable them in the firmware if that could help. How can not needed sensors be disabled in the Thingy firmware?. Also, would connecting MPU-9250 in SPI configuration help?

In the MPU-9250 spec http://www.invensense.com/wp-content/uploads/2015/02/PS-MPU-9250A-01-v1.1.pdf the maximum sampling rate is 32kHz although my problem will probably require 500kHz I would like to get to 32kHz if that is achievable on the Thingy. Energy consumption is not the issue at the moment for me.

Thanks!

Matej 

Parents
  • Hi Matej, 

    Could you point to what exactly you modified ? 

    Have you checked which error you received ? mpu_set_sample_rate() allows rate from 4Hz to 1kHz

  • Hi, 

    here is the changes I did on the firmware so far but I think only the first one is relevant in this case:

    • in ble_tms.h I changed the #define BLE_TMS_CONFIG_MPUF_MAX from 200 to 1000
    • enabled logging #define NRF_LOG_ENABLED 1 in sdk_config.h
    • changed the drv_motion_evt_handler() to include the timestamp instead of compass data - I couldn't just add the timestamp as the max payload is 20 bytes

    I communicate with the device through Chrome and Web Bluetooth API. I set the motion characteristic like so:

    sensor.configCharacteristic = await sensor.service.getCharacteristic(TMS_CONFIG_UUID);
    console.log('char', sensor.configCharacteristic);
    
    let val = await sensor.configCharacteristic.readValue();
    console.log(val);
    console.log('Step counter int - ms:' + val.getUint16(0, true));
    console.log('Temperature compensation interval - ms:' + val.getUint16(2, true));
    console.log('Magnetometer compensation interval - ms:' + val.getUint16(4, true));
    console.log('Motion processing unit frequency - Hz:' + val.getUint16(6, true));
    console.log('Wake on motion:' + val.getUint8(8, true));
    
    val.setUint16(6, 1000, true);
    await sensor.configCharacteristic.writeValue(val);

    Then I connect with the NRF connect app to the Thingy and when I try to read Thingy Raw Data Characteristic it would disconnect in 1 or 2 seconds. I get this log:

    nRF Connect, 2019-07-22
    Thingy1 (E6:69:EC:CD:57:17)
    V       23:58:09.541    Connecting to E6:69:EC:CD:57:17...
    D       23:58:09.541    gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
    D       23:58:10.380    [Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I       23:58:10.380    Connected to E6:69:EC:CD:57:17
    D       23:58:10.397    [Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
    V       23:58:10.427    Discovering services...
    D       23:58:10.427    gatt.discoverServices()
    I       23:58:10.777    Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
    D       23:58:12.118    [Callback] Services discovered with status: 0
    I       23:58:12.118    Services discovered
    V       23:58:12.202    Generic Access (0x1800)
    - Device Name [R] (0x2A00)
    - Appearance [R] (0x2A01)
    - Peripheral Preferred Connection Parameters [R] (0x2A04)
    - Central Address Resolution [R] (0x2AA6)
    Generic Attribute (0x1801)
    - Service Changed [I] (0x2A05)
     Client Characteristic Configuration (0x2902)
    Thingy Configuration Service (ef680100-9b35-4933-9b10-52ffa9740042)
    - Thingy Name Characteristic [R W] (ef680101-9b35-4933-9b10-52ffa9740042)
    - Thingy Advertising Parameters Characteristic [R W] (ef680102-9b35-4933-9b10-52ffa9740042)
    - Thingy Connection Parameters Characteristic [R W] (ef680104-9b35-4933-9b10-52ffa9740042)
    - Thingy Eddystone URL Characteristic [R W] (ef680105-9b35-4933-9b10-52ffa9740042)
    - Thingy Cloud Token Characteristic [R W] (ef680106-9b35-4933-9b10-52ffa9740042)
    - Thingy FW Version Characteristic [R] (ef680107-9b35-4933-9b10-52ffa9740042)
    - Thingy MTU Request Characteristic [R W] (ef680108-9b35-4933-9b10-52ffa9740042)
    - Unknown Characteristic [R W] (ef680109-9b35-4933-9b10-52ffa9740042)
    Thingy Environment Service (ef680200-9b35-4933-9b10-52ffa9740042)
    - Thingy Temperature Characteristic [N] (ef680201-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Pressure Characteristic [N] (ef680202-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Humidity Characteristic [N] (ef680203-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Air Quality Characteristic [N] (ef680204-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Light Intensity Characteristic [N] (ef680205-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Environment Configuration Characteristic [R W] (ef680206-9b35-4933-9b10-52ffa9740042)
    Thingy Motion Service (ef680400-9b35-4933-9b10-52ffa9740042)
    - Thingy Motion Configuration Characteristic [R W] (ef680401-9b35-4933-9b10-52ffa9740042)
    - Thingy Tap Characteristic [N] (ef680402-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Orientation Characteristic [N] (ef680403-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Quaternion Characteristic [N] (ef680404-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Pedometer Characteristic [N] (ef680405-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Raw Data Characteristic [N] (ef680406-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Euler Characteristic [N] (ef680407-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Rotation Characteristic [N] (ef680408-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Heading Characteristic [N] (ef680409-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Gravity Vector Characteristic [N] (ef68040a-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    Thingy User Interface Service (ef680300-9b35-4933-9b10-52ffa9740042)
    - Thingy Button Characteristic [N] (ef680302-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy LED Characteristic [R W] (ef680301-9b35-4933-9b10-52ffa9740042)
    - Thingy External Pin Characteristic [R W] (ef680303-9b35-4933-9b10-52ffa9740042)
    Thingy Sound Service (ef680500-9b35-4933-9b10-52ffa9740042)
    - Thingy Sound Configuration Characteristic [R W] (ef680501-9b35-4933-9b10-52ffa9740042)
    - Thingy Speaker Data Characteristic [WNR] (ef680502-9b35-4933-9b10-52ffa9740042)
    - Thingy Speaker Status Characteristic [N] (ef680503-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Microphone Characteristic [N] (ef680504-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    Battery Service (0x180F)
    - Battery Level [N R] (0x2A19)
     Client Characteristic Configuration (0x2902)
    Secure DFU Service (0xFE59)
    - Buttonless DFU [I W] (8ec90003-f315-4f60-9fb8-838830daea50)
     Client Characteristic Configuration (0x2902)
    I       23:58:12.223    Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 3200ms)
    V       23:58:20.341    Enabling notifications for ef680406-9b35-4933-9b10-52ffa9740042
    D       23:58:20.341    gatt.setCharacteristicNotification(ef680406-9b35-4933-9b10-52ffa9740042, true)
    D       23:58:20.343    gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x0100)
    I       23:58:20.475    Data written to descr. 00002902-0000-1000-8000-00805f9b34fb, value: (0x) 01-00
    A       23:58:20.475    "Notifications enabled" sent
    V       23:58:20.483    Notifications enabled for ef680406-9b35-4933-9b10-52ffa9740042
    D       23:58:24.447    [Callback] Connection state changed with status: 8 and new state: DISCONNECTED (0)
    E       23:58:24.447    Error 8 (0x8): GATT CONN TIMEOUT
    I       23:58:24.448    Disconnected
    D       23:58:24.545    [Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED

    Thingy disconnects also when reading some other characteristic not just raw data so I don't think that changing drv_motion_evt_handler() has an effect here. If it is set to 100Hz then everything works fine.

    Hope this helps you

Reply
  • Hi, 

    here is the changes I did on the firmware so far but I think only the first one is relevant in this case:

    • in ble_tms.h I changed the #define BLE_TMS_CONFIG_MPUF_MAX from 200 to 1000
    • enabled logging #define NRF_LOG_ENABLED 1 in sdk_config.h
    • changed the drv_motion_evt_handler() to include the timestamp instead of compass data - I couldn't just add the timestamp as the max payload is 20 bytes

    I communicate with the device through Chrome and Web Bluetooth API. I set the motion characteristic like so:

    sensor.configCharacteristic = await sensor.service.getCharacteristic(TMS_CONFIG_UUID);
    console.log('char', sensor.configCharacteristic);
    
    let val = await sensor.configCharacteristic.readValue();
    console.log(val);
    console.log('Step counter int - ms:' + val.getUint16(0, true));
    console.log('Temperature compensation interval - ms:' + val.getUint16(2, true));
    console.log('Magnetometer compensation interval - ms:' + val.getUint16(4, true));
    console.log('Motion processing unit frequency - Hz:' + val.getUint16(6, true));
    console.log('Wake on motion:' + val.getUint8(8, true));
    
    val.setUint16(6, 1000, true);
    await sensor.configCharacteristic.writeValue(val);

    Then I connect with the NRF connect app to the Thingy and when I try to read Thingy Raw Data Characteristic it would disconnect in 1 or 2 seconds. I get this log:

    nRF Connect, 2019-07-22
    Thingy1 (E6:69:EC:CD:57:17)
    V       23:58:09.541    Connecting to E6:69:EC:CD:57:17...
    D       23:58:09.541    gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
    D       23:58:10.380    [Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I       23:58:10.380    Connected to E6:69:EC:CD:57:17
    D       23:58:10.397    [Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
    V       23:58:10.427    Discovering services...
    D       23:58:10.427    gatt.discoverServices()
    I       23:58:10.777    Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
    D       23:58:12.118    [Callback] Services discovered with status: 0
    I       23:58:12.118    Services discovered
    V       23:58:12.202    Generic Access (0x1800)
    - Device Name [R] (0x2A00)
    - Appearance [R] (0x2A01)
    - Peripheral Preferred Connection Parameters [R] (0x2A04)
    - Central Address Resolution [R] (0x2AA6)
    Generic Attribute (0x1801)
    - Service Changed [I] (0x2A05)
     Client Characteristic Configuration (0x2902)
    Thingy Configuration Service (ef680100-9b35-4933-9b10-52ffa9740042)
    - Thingy Name Characteristic [R W] (ef680101-9b35-4933-9b10-52ffa9740042)
    - Thingy Advertising Parameters Characteristic [R W] (ef680102-9b35-4933-9b10-52ffa9740042)
    - Thingy Connection Parameters Characteristic [R W] (ef680104-9b35-4933-9b10-52ffa9740042)
    - Thingy Eddystone URL Characteristic [R W] (ef680105-9b35-4933-9b10-52ffa9740042)
    - Thingy Cloud Token Characteristic [R W] (ef680106-9b35-4933-9b10-52ffa9740042)
    - Thingy FW Version Characteristic [R] (ef680107-9b35-4933-9b10-52ffa9740042)
    - Thingy MTU Request Characteristic [R W] (ef680108-9b35-4933-9b10-52ffa9740042)
    - Unknown Characteristic [R W] (ef680109-9b35-4933-9b10-52ffa9740042)
    Thingy Environment Service (ef680200-9b35-4933-9b10-52ffa9740042)
    - Thingy Temperature Characteristic [N] (ef680201-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Pressure Characteristic [N] (ef680202-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Humidity Characteristic [N] (ef680203-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Air Quality Characteristic [N] (ef680204-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Light Intensity Characteristic [N] (ef680205-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Environment Configuration Characteristic [R W] (ef680206-9b35-4933-9b10-52ffa9740042)
    Thingy Motion Service (ef680400-9b35-4933-9b10-52ffa9740042)
    - Thingy Motion Configuration Characteristic [R W] (ef680401-9b35-4933-9b10-52ffa9740042)
    - Thingy Tap Characteristic [N] (ef680402-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Orientation Characteristic [N] (ef680403-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Quaternion Characteristic [N] (ef680404-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Pedometer Characteristic [N] (ef680405-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Raw Data Characteristic [N] (ef680406-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Euler Characteristic [N] (ef680407-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Rotation Characteristic [N] (ef680408-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Heading Characteristic [N] (ef680409-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Gravity Vector Characteristic [N] (ef68040a-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    Thingy User Interface Service (ef680300-9b35-4933-9b10-52ffa9740042)
    - Thingy Button Characteristic [N] (ef680302-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy LED Characteristic [R W] (ef680301-9b35-4933-9b10-52ffa9740042)
    - Thingy External Pin Characteristic [R W] (ef680303-9b35-4933-9b10-52ffa9740042)
    Thingy Sound Service (ef680500-9b35-4933-9b10-52ffa9740042)
    - Thingy Sound Configuration Characteristic [R W] (ef680501-9b35-4933-9b10-52ffa9740042)
    - Thingy Speaker Data Characteristic [WNR] (ef680502-9b35-4933-9b10-52ffa9740042)
    - Thingy Speaker Status Characteristic [N] (ef680503-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    - Thingy Microphone Characteristic [N] (ef680504-9b35-4933-9b10-52ffa9740042)
     Client Characteristic Configuration (0x2902)
    Battery Service (0x180F)
    - Battery Level [N R] (0x2A19)
     Client Characteristic Configuration (0x2902)
    Secure DFU Service (0xFE59)
    - Buttonless DFU [I W] (8ec90003-f315-4f60-9fb8-838830daea50)
     Client Characteristic Configuration (0x2902)
    I       23:58:12.223    Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 3200ms)
    V       23:58:20.341    Enabling notifications for ef680406-9b35-4933-9b10-52ffa9740042
    D       23:58:20.341    gatt.setCharacteristicNotification(ef680406-9b35-4933-9b10-52ffa9740042, true)
    D       23:58:20.343    gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x0100)
    I       23:58:20.475    Data written to descr. 00002902-0000-1000-8000-00805f9b34fb, value: (0x) 01-00
    A       23:58:20.475    "Notifications enabled" sent
    V       23:58:20.483    Notifications enabled for ef680406-9b35-4933-9b10-52ffa9740042
    D       23:58:24.447    [Callback] Connection state changed with status: 8 and new state: DISCONNECTED (0)
    E       23:58:24.447    Error 8 (0x8): GATT CONN TIMEOUT
    I       23:58:24.448    Disconnected
    D       23:58:24.545    [Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED

    Thingy disconnects also when reading some other characteristic not just raw data so I don't think that changing drv_motion_evt_handler() has an effect here. If it is set to 100Hz then everything works fine.

    Hope this helps you

Children
Related