Smart Sensor BHy1 design guide

Introduction

This document is meant as a reference guide on how to design using Bosch Sensortec’s BHy1. BHy1 family includes two parts, one is BHA250 series, the other is BHI160 series.

Selecting the right part


The BHA250 contains part number: BHA250 and BHA250B. The BHA250/BHA250B is sensor hub which integrated Accelerometer. Figure1 shows the BHA250 laser marking.

                                                                                             Fig1

The BHI160 contains part number: BHI160and BHI160B. The BHI160/ BHI160B is smart sensor which integrated IMU(ACC+Gyro). Figure2 shows the laser marking.

                                                                                                 Fig2

Common Characteristics

Key features

  • 1xI2C(3.4MHz) Host Interface; 1xI2C(1MHz) Aux Interface; up to 3 GPIOs
  • 32-bit Floating-point; 96 KB ROM; 48 KB RAM
  • Max ODR is 200Hz

 Difference between products

                                                Table 1: Difference on BHA250 and BHI160

                                          Table 2: Accelerometer Parameter on BHA250 and BHI160

                                                       Table 3: BHI160 Gyroscope Parameter

 Available evaluation tools and software

To best to evaluate the products from the BHy1 family is the following combination of evaluation tools:

Reference design

See Figure 3 for BHA250 schematic of a typical use-case.

                                                                     Figure3  BHA250/BHA250B typical schematic

Bill of materials:

Note: R3 and R4 are mandatory, even if no external sensor is attached.

Layout recommendations

Landing Pattern

                                         Figure5: BHA250/BHA250B Landing Pattern

                                                      Figure6: BHI160/BHI160B Landing Pattern

 Typical Layout

                                                      Figure7: BHA250/BHA250B Layout

                                                           Figure8: BHI160/BHI160B Layout

Manufacturing notes

BHy1 on COINES

COINES setup

 

 

 

Platform: Windows
gcc: "C:\DiaSemi\SmartSnippetsStudio\Tools\mingw64_targeting32\bin\gcc.exe C:\TDM-GCC-64\bin\gcc.exe".
[ MKDIR ] build
[ CC ] bhy_activity_recognition.c
[ CC ] ../../../../sensorAPI/bhy/src/BHy_support.c
[ CC ] ../../../../sensorAPI/bhy/src/bhy_uc_driver.c
[ CC ] ../../../../sensorAPI/bhy/src/bhy.c
[ CC ] ../../../../sensorAPI/bhy/AppBoard_usb_driver/AppBoard_usb_driver.c
[ MAKE ] coinesAPI
[ MKDIR ] build
[ CC ] coines.c
[ CC ] comm_intf/comm_intf.c
[ CC ] comm_intf/comm_ringbuffer.c
[ CC ] comm_driver/usb.c
[ CC ] comm_driver/legacy_usb/legacy_usb_support.c
[ AR ] libcoines
[ LD ] bhy_activity_recognition.exe
Operation finished successfully

Running on BHy1 shuttle board

Connect with APP2.0 board (BHy1 Shuttle board) and compile the sample code (..\..\examples\c\bhy\rotation_vector),

Click  to run and get the output on the console.

Running example 'bhy_rotation_vector.exe' ...

uploading RAM patch...

W: 1.000 X: 0.000 Y: 0.000 Z: 0.000 

W: 1.000 X:-0.000 Y: 0.000 Z: 0.000 

W: 1.000 X:-0.000 Y: 0.000 Z: 0.000 

W: 0.999 X: 0.005 Y: 0.018 Z: 0.000 

W: 0.999 X: 0.005 Y: 0.018 Z: 0.000 

W: 0.999 X: 0.005 Y: 0.018 Z: 0.000 

W: 0.999 X: 0.005 Y: 0.018 Z: 0.000 

BHy1 example code on COINES

Activity recognition example

Data parsing for activity recognition is available in COINES. The user can open the “bhy_activity_recognition.c” in COINES, compile and run. The output will be shown in the COINES console.

The code is shown as below.

 

 

/* @brief This API is used for parsing the activity recognition data from BHY
*
* @param[in] sensor_data: bhy data
* @param[in] sensor_id: bhy id
*
* @return void
*
*/
void sensors_callback(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
float temp;
u8 index;
/* Since a timestamp is always sent before every new data, and that the callbacks */
/* are called while the parsing is done, then the system timestamp is always equal */
/* to the sample timestamp. (in callback mode only) */
temp = g_system_timestamp / 3200000.;

for (index = 6; index <= 8; index++)
{
outBuffer[index] = floorf(temp) + '0';
temp = (temp - floorf(temp)) * 10;
}

for (index = 10; index <= 12; index++)
{
outBuffer[index] = floorf(temp) + '0';
temp = (temp - floorf(temp)) * 10;
}
/* if there are no changes then it will read X */
outBuffer[22] = 'X';
outBuffer[35] = 'X';
outBuffer[48] = 'X';
outBuffer[61] = 'X';
outBuffer[74] = 'X';
outBuffer[87] = 'X';

/* '0' means "end of activity and '1' means start of activity */
if (sensor_data->data_scalar_u16.data & 0b0000000000000001)
outBuffer[22] = '0';
if (sensor_data->data_scalar_u16.data & 0b0000000000000010)
outBuffer[35] = '0';
if (sensor_data->data_scalar_u16.data & 0b0000000000000100)
outBuffer[48] = '0';
if (sensor_data->data_scalar_u16.data & 0b0000000000001000)
outBuffer[61] = '0';
if (sensor_data->data_scalar_u16.data & 0b0000000000010000)
outBuffer[74] = '0';
if (sensor_data->data_scalar_u16.data & 0b0000000000100000)
outBuffer[87] = '0';
if (sensor_data->data_scalar_u16.data & 0b0000000100000000)
outBuffer[22] = '1';
if (sensor_data->data_scalar_u16.data & 0b0000001000000000)
outBuffer[35] = '1';
if (sensor_data->data_scalar_u16.data & 0b0000010000000000)
outBuffer[48] = '1';
if (sensor_data->data_scalar_u16.data & 0b0000100000000000)
outBuffer[61] = '1';
if (sensor_data->data_scalar_u16.data & 0b0001000000000000)
outBuffer[74] = '1';
if (sensor_data->data_scalar_u16.data & 0b0010000000000000)
outBuffer[87] = '1';

fprintf(stderr, "%s", outBuffer);
/* activity recognition is not time critical, so let's wait a little bit */
mdelay(200);
}

 

 

 Gesture recognition example

Data parsing for gesture recognition is available in COINES. The user can open the “bhy_gesture_recognition.c” in COINES, compile and run. The output will be shown in COINES console.

In the example code, three gestures are enabled, which are “Glance, Pickup and Significant Motion”. The code is shown as below.

 

 

/* @brief This API is used for parsing the activity recognition data from BHY
*
* @param[in] sensor_data: bhy data
* @param[in] sensor_id: bhy id
*
* @return void
*
*/
void sensors_callback(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
float temp;
u8 index;
/* Since a timestamp is always sent before every new data, and that the callbacks */
/* are called while the parsing is done, then the system timestamp is always equal */
/* to the sample timestamp. (in callback mode only) */
temp = g_system_timestamp / 3200000.;

for (index = 6; index <= 8; index++)
{
outBuffer[index] = floorf(temp) + '0';
temp = (temp - floorf(temp)) * 10;
}

for (index = 10; index <= 12; index++)
{
outBuffer[index] = floorf(temp) + '0';
temp = (temp - floorf(temp)) * 10;
}

sensor_id &= 0x1F;
/* gesture recognition sensors are always one-shot, so you need to */
/* re-enable them every time if you want to catch every event */
bhy_enable_virtual_sensor(sensor_id, VS_WAKEUP, 1, 0, VS_FLUSH_NONE, 0, 0);

switch (sensor_id)
{
case VS_TYPE_GLANCE:
strcpy(&outBuffer[24], "Glance \r\n");
break;
case VS_TYPE_PICKUP:
strcpy(&outBuffer[24], "Pickup \r\n");
break;
case VS_TYPE_SIGNIFICANT_MOTION:
strcpy(&outBuffer[24], "Sig motion\r\n");
break;
default:
strcpy(&outBuffer[24], "Unknown \r\n");
break;
}

fprintf(stderr, "%s", outBuffer);
fflush(stderr);
}

 

 

Gravity vector example

Data parsing for gravity vector is available in COINES. The user can open the “bhy_gravity_vector.c” in COINES, compile and run. The output will be shown in COINES console.

The code is shown as below.

 

 

/* @brief This API is used for parsing the activity recognition data from BHY
*
* @param[in] sensor_data: bhy data
* @param[in] sensor_id: bhy id
*
* @return void
*
*/
void sensors_callback(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
float temp;
u8 index;

temp = sensor_data->data_vector.x / 8192.;
outBuffer[3] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
outBuffer[4] = floorf(temp) + '0';

for (index = 6; index <= 8; index++)
{
temp = (temp - floorf(temp)) * 10;
outBuffer[index] = floorf(temp) + '0';
}

temp = sensor_data->data_vector.y / 8192.;
outBuffer[13] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
outBuffer[14] = floorf(temp) + '0';

for (index = 16; index <= 18; index++)
{
temp = (temp - floorf(temp)) * 10;
outBuffer[index] = floorf(temp) + '0';
}

temp = sensor_data->data_vector.z / 8192.;
outBuffer[23] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
outBuffer[24] = floorf(temp) + '0';

for (index = 26; index <= 28; index++)
{
temp = (temp - floorf(temp)) * 10;
outBuffer[index] = floorf(temp) + '0';
}

fprintf(stderr, "%s", outBuffer);
fflush(stderr);
}

 

 

Rotation vector example

Data parsing for Rotation Vector is available in COINES. The user can open the “bhy_rotation_vector.c” in COINES, compile and run. The output will be shown in COINES console.

The code is shown as below.

 

 

/* @brief This API is used for parsing the activity recognition data from BHY
*
* @param[in] sensor_data: bhy data
* @param[in] sensor_id: bhy id
*
* @return void
*
*/
void sensors_callback(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
float temp;
u8 index;

temp = sensor_data->data_quaternion.w / 16384.;
outBuffer[3] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
outBuffer[4] = floorf(temp) + '0';

for (index = 6; index <= 8; index++)
{
temp = (temp - floorf(temp)) * 10;
outBuffer[index] = floorf(temp) + '0';
}

temp = sensor_data->data_quaternion.x / 16384.;
outBuffer[13] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
outBuffer[14] = floorf(temp) + '0';

for (index = 16; index <= 18; index++)
{
temp = (temp - floorf(temp)) * 10;
outBuffer[index] = floorf(temp) + '0';
}

temp = sensor_data->data_quaternion.y / 16384.;
outBuffer[23] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
outBuffer[24] = floorf(temp) + '0';

for (index = 26; index <= 28; index++)
{
temp = (temp - floorf(temp)) * 10;
outBuffer[index] = floorf(temp) + '0';
}

temp = sensor_data->data_quaternion.z / 16384.;
outBuffer[33] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
outBuffer[34] = floorf(temp) + '0';

for (index = 36; index <= 38; index++)
{
temp = (temp - floorf(temp)) * 10;
outBuffer[index] = floorf(temp) + '0';
}

fprintf(stderr, "%s", outBuffer);
fflush(stderr);

}

 

 

 Create customer example

Customer can create their own case based on the sensor they used in the folder “examples”, for example, BHI160 Shuttle board, we can create a new folder “acc_gyro data output”

Create the file and copy “Makefile” from other bhy example(like gravity_vector)

Modify the Makefile                                          

#CCE_Board_Definitions:BHI160;BHI160B;BHA250;BHA250B

COINES_INSTALL_PATH ?= ../../../..

EXAMPLE_FILE ?= acc_gyro data output.c

SHUTTLE_BOARD ?= BHI160

CFLAGS += -DBST_APPBOARD_VIA_USB -D$(SHUTTLE_BOARD) 

include $(COINES_INSTALL_PATH)/examples/c/examples.mk

Now, you can make, compile and run your own code via COINES.

Further reads

                                

2 replies