2187 views|2 replies

98

Posts

0

Resources
The OP
 

Competition Sharing 3: RSL10 Bluetooth SoC BMM150 Geomagnetic Sensor Data Collection [Copy link]

 

equipment:

RSL10-SENSE-GEVK: RSL10 Sensor Development Kit

From the schematic diagram, the geomagnetic sensor and BHI160 are together. There is no official routine code. I will share it here. Let's go directly to the code.

//-----------------------------------------------------------------------------
// Copyright (c) 2018 Semiconductor Components Industries LLC
// (d/b/a "ON Semiconductor").  All rights reserved.
// This software and/or documentation is licensed by ON Semiconductor under
// limited terms and conditions.  The terms and conditions pertaining to the
// software and/or documentation are available at
// http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf ("ON Semiconductor Standard
// Terms and Conditions of Sale, Section 8 Software") and if applicable the
// software license agreement.  Do not use this software and/or documentation
// unless you have carefully read and you agree to the limited terms and
// conditions.  By using this software and/or documentation, you agree to the
// limited terms and conditions.
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <BDK.h>
#include <BSP_Components.h>
#include <BLE_Components.h>
#include <SoftwareTimer.h>

/** Converts measured orientation data into degrees.
 *
 * GREEN LED will be turned on if board heading is within 10 degrees of
 * magnetic north (<=10 or >=350).
 */
void ao_vector_cb(bhy_data_generic_t *data, bhy_virtual_sensor_t sensor)
{
    float h = data->data_vector.x / 32768.0f * 360.0f;
    float p = data->data_vector.y / 32768.0f * 360.0f;
    float y = data->data_vector.z / 32768.0f * 360.0f;

    if (h > 350.0f || h < 10.0f)
    {
        LED_On(LED_GREEN);
    }
    else
    {
        LED_Off(LED_GREEN);
    }

    printf("Orientation: h=%.1f p=%.1f, y=%.1f (%d)\r\n", h, p, y, data->data_vector.status);
}

/** Converts measured linear acceleration data based on sensors dynamic range
 * and prints it to debug terminal.
 *
 * Also turns on RED LED if total acceleration applied to the board is over 1g.
 */
void la_vector_cb(bhy_data_generic_t *data, bhy_virtual_sensor_t sensor)
{
    /* Linear Acceleration sensor values are scaled using dynamic range. */
    uint16_t dyn_range = BHI160_NDOF_GetAccelDynamicRange();

    float x = data->data_vector.x / 32768.0f * dyn_range;
    float y = data->data_vector.y / 32768.0f * dyn_range;
    float z = data->data_vector.z / 32768.0f * dyn_range;

    if (fabsf(x) + fabsf(y) + fabsf(z) >= 1.0f)
    {
        LED_On(LED_RED);
    }
    else
    {
        LED_Off(LED_RED);
    }

    printf("Linear Accel: x=%.2f g, y=%.2f g, z=%.2f g\r\n", x, y, z);
}

void gyro_vector_cb(bhy_data_generic_t *data, bhy_virtual_sensor_t sensor)
{
    uint16_t dyn_range = BHI160_NDOF_GetGyroDynamicRange();

    float x = data->data_vector.x / 32768.0f * dyn_range;
    float y = data->data_vector.y / 32768.0f * dyn_range;
    float z = data->data_vector.z / 32768.0f * dyn_range;

    if (fabsf(z) > 45.0f)
    {
        LED_On(LED_BLUE);
    }
    else
    {
        LED_Off(LED_BLUE);
    }

    printf("Rate of Rotation: x=%.2f /s, y=%.2f /s, z=%.2f /s\r\n", x, y, z);

}

void magn_vector_cb(bhy_data_generic_t *data, bhy_virtual_sensor_t sensor)
{
    uint16_t dyn_range = BHI160_NDOF_GetMagDynamicRange();

    float x = data->data_vector.x / 32768.0f * dyn_range;
    float y = data->data_vector.y / 32768.0f * dyn_range;
    float z = data->data_vector.z / 32768.0f * dyn_range;

    printf("magnet: x=%.2f g, y=%.2f g, z=%.2f g\r\n", x, y, z);

}


void bhi160_init()
{
    int32_t retval;
    /* Initialize all needed BDK components. */
    BDK_BLE_Initialize();
    BLE_BASS_Initialize(50,1);
    BLE_ICS_Initialize(&CustomService_WriteInd);
    /* Initialize all LEDs to eliminate any currents from disabled DIO pads. */
    LED_Initialize(LED_RED);
    LED_Initialize(LED_GREEN);
    LED_Initialize(LED_BLUE);

    /* Increase I2C bus speed to 400kHz. */
    HAL_I2C_SetBusSpeed(HAL_I2C_BUS_SPEED_FAST);

    /* Initialize BHI160.
     * This may take a while depending on bus speed because RAM patch has to be
     * uploaded into BHI160 to enable support for BMM150 magnetometer.
     *
     * Set temporary timer to see how long it took to initialize and load the
     * RAM patch.
     */
    LED_On(LED_GREEN);
    {
        printf("Initializing BHI160.\r\n");

        struct SwTimer tim;
        struct SwTimer_Duration tim_dur;

        SwTimer_Initialize(&tim);
        SwTimer_Start(&tim);

        retval = BHI160_NDOF_Initialize();
        ASSERT_DEBUG(retval == BHY_SUCCESS);

        SwTimer_GetElapsed(&tim, &tim_dur);
        SwTimer_Remove(&tim);

        printf("BHI160 initialized in %lu seconds and %lu ns.\r\n",
                tim_dur.seconds, tim_dur.nanoseconds);
    }
    LED_Off(LED_GREEN);

    /* Enable desired virtual sensor outputs. */

    retval = BHI160_NDOF_EnableSensor(BHI160_NDOF_S_ORIENTATION, &ao_vector_cb, 5);
    ASSERT_DEBUG(retval == BHY_SUCCESS);

    retval = BHI160_NDOF_EnableSensor(BHI160_NDOF_S_LINEAR_ACCELERATION, &la_vector_cb, 50);
    ASSERT_DEBUG(retval == BHY_SUCCESS);

    retval = BHI160_NDOF_EnableSensor(BHI160_NDOF_S_RATE_OF_ROTATION, &gyro_vector_cb, 50);
    ASSERT_DEBUG(retval == BHY_SUCCESS);

    retval = BHI160_NDOF_EnableSensor(BHI160_NDOF_S_MAGNETIC_FIELD, &magn_vector_cb, 50);
    ASSERT_DEBUG(retval == BHY_SUCCESS);

    printf("APP: Entering main loop.\r\n");
}

int main(void)
{
    BDK_Initialize();
    bhi160_init();
    printf("\r\nAPP: BME680_BSEC example.\r\n");

    printf("APP: Entering main loop.\r\n");
    while (1)
    {
        /* Execute any events that occurred and refresh Watchdog. */
        BDK_Schedule();


        SYS_WAIT_FOR_INTERRUPT;
    }

    return 0;
}

Latest reply

Well done BHI160 is known to have the lowest power consumption in the industry. Do you feel the same?   Details Published on 2021-6-14 10:53
 
 

6555

Posts

0

Resources
2
 

Well done

BHI160 is known to have the lowest power consumption in the industry. Do you feel the same?

Comments

I don't have an oscilloscope at home so I can't test it.  Details Published on 2021-6-14 12:05
 
 
 

98

Posts

0

Resources
3
 
Jacktang posted on 2021-6-14 10:53 Well done. BHI160 is known to have the lowest power consumption in the industry. Does the OP feel the same?

I don't have an oscilloscope at home so I can't test it.

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list