Acclerator sensor
Answer
11/5/18 8:06 AM
#include "XdkSensorHandle.h"
Retcode_T BMA280_InitializeAccelerometer(Accelerometer_Bandwidth_T bandwidth, Accelerometer_Range_T range){
 Retcode_T retcode = (Retcode_T) RETCODE_SUCCESS;
 retcode = Accelerometer_init(xdkAccelerometers_BMA280_Handle);
 if(RETCODE_SUCCESS == retcode){
  retcode = Accelerometer_setBandwidth(xdkAccelerometers_BMA280_Handle, bandwidth);
 }
 if(RETCODE_SUCCESS == retcode){
  retcode = Accelerometer_setRange(xdkAccelerometers_BMA280_Handle, range);
 }
 if(RETCODE_SUCCESS == retcode){
  printf("BMA280 Accelerometer Initializing : Succeed \r\n");
 }
 if(RETCODE_SUCCESS != retcode){
  printf("BMA280 Accelerometer Initializing : Failed \r\n");
 }
 return retcode;
}
Retcode_T BMA280_ReadAccelerometerGData(int32_t *xData, int32_t *yData, int32_t *zData){
 Retcode_T retcode = (Retcode_T) RETCODE_SUCCESS;
 Accelerometer_XyzData_T bma280g = {INT32_C(0), INT32_C(0), INT32_C(0)};
 retcode = Accelerometer_readXyzGValue(xdkAccelerometers_BMA280_Handle, &bma280g);
 if(RETCODE_SUCCESS == retcode){
  *xData = bma280g.xAxisData;
  *yData = bma280g.yAxisData;
  *zData = bma280g.zAxisData;
 }
 return retcode;
}
void printBMA280GData(void *pvParameters){
 Retcode_T retcode = (Retcode_T) RETCODE_SUCCESS;
 BCDS_UNUSED(pvParameters);
 int32_t xData = 0;
 int32_t yData = 0;
 int32_t zData = 0;
 retcode = BMA280_ReadAccelerometerGData(&xData, &yData, &zData);
 if(RETCODE_SUCCESS == retcode){
  printf("BMA280 Data : [x]: %6d mg \t [y]: %6d mg \t [z]: %6d mg \r\n", (int) xData, (int) yData, (int) zData);
 }
}

 

This is my sample code for using the acclerator sensor. I need a bandwidth of 300HZ and range 2G. What are the changes that I should make in the coding to include these values.

Can someone modify the code and send include these values?

I also need the code to initialise my SD card and read all the values acquired from the acclerator sensor.

Alberto.

0 (0 Votes)
RE: Acclerator sensor
Answer
11/5/18 8:34 AM as a reply to Alberto Icardi.

Hello Alberto,

i'm glad to see my code snippet i posted in an earlier thread was helpful to you.

You are able to configure the bandwidth and range of the sensor by calling the BMA280_InitializeAccelerometer() function with the corresponding parameter. These parameter are enum types in the header file BCDS_Accelerometer.h . You can find this header in the path: YourProjectName/SDK/xdk110/Platform/Sensors/include/BCDS_Accelerometer.h.

If you want to set the bandwidth to 300Hz and the range to +-2G you have to call the Init function in your main programm like that:

BMA280_InitializeAccelerometer(ACCELEROMETER_BMA280_BANDWIDTH_500HZ, ACCELEROMETER_BMA280_RANGE_2G);

Please notice there is no option to set the Sensor to a value of 300Hz. The two possibilities are 250Hz or 500Hz.

This should answer your first question.

In the next step you want to write the sensor data to a file on the SD card. To get a proper understand of the SD card and the usage of it, i recommend the corresponding learning section on the XDK Knowledge Base. There is a good tutorial you can follow up. I also recommend the learning section of this website. The tutorials are very helpful to start with a topic.

I hope i was able to answer your questions.

Best regards,

Christian

0 (0 Votes)
RE: Acclerator sensor
Answer
11/5/18 5:38 PM as a reply to Christian Köhler.
Hello guys,

Christian, thank you for the helping hand.

Alberto, I answered a similar request of yours in your other thread Sample Program required .

As Christian stated, the Knowledgebase article about the SD card is very helpful to implement the SD card functionality.

Kind regards,
Franjo
0 (0 Votes)