Sample Program required
Answer
10/18/18 3:15 PM

Hi,

Can someone send a basic code to initialise and test my acclerator sensor?

I am facing issues whenever I write the code.  

0 (0 Votes)
RE: Sample Program required
Answer
10/18/18 3:46 PM as a reply to Alberto Icardi.
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);
	}
}

Hello Alberto,

i am not sure but i think you try to do some stuff with the BMA280 or BMI160.

A few days ago i wrote a little API to read the sensor values.

Call the init function in your appInitSystem. Then you can add the "printBMA280GData" to a timer task for example.

I hope this was helpfull.

Best regards,

Christian

0 (0 Votes)
RE: Sample Program required
Answer
10/19/18 9:45 AM as a reply to Christian Köhler.

Than you Cristian.

 

I have created a new C project. 

May I know where I should copy and paste this code?

In source or sdk ?

 

Thanks in advance.

0 (0 Votes)
RE: Sample Program required
Answer
10/19/18 11:13 AM as a reply to Alberto Icardi.

Hello Alberto,

the fastest way to include the code is to implement the functions in your AppController.c file.

To use the sensor functionality you have to include the header "XdkSensorHandle.h" in the AppController.c file.

Then just copy and paste the BMA280_InitializeAccelerometer() and the BMA280_ReadAccelerometerGData() to the file.

After that you can call the init function in the AppControllerEnable function for example.

In the AppController.c you should have a function like AppControllerFire with an endless loop in it.

In this endless loop you can call the read function and print the value to the serial console.

I recommend to add an delay like "vTaskDelay(500)", otherwise the endless loop is way too fast.

I hope this was helpfull. If you have any further questions feel free to ask.

Best regards,

Christian

0 (0 Votes)
RE: Sample Program required
Answer
10/19/18 2:06 PM as a reply to Christian Köhler.
Hello Alberto,

please take a look at my detailed answer to your question in your other thread Initialise XDK sensor . There you will find detailed information about to make first steps with the different sensors of the XDK.

In addtion, thank you Christian for your fast reply and helpful input.

If you have any further questions, please feel free to ask.

Kind regards,
Franjo
0 (0 Votes)
RE: Sample Program required
Answer
11/2/18 8:19 AM as a reply to Franjo Stjepandic.

Hello,

I copied and pasted the sample code that you had given me. But still there are erros in the code.

Kindly let me know how to resolve it. check the screenshot that I had attached to this message.

0 (0 Votes)
RE: Sample Program required
Answer
11/2/18 8:20 AM as a reply to Alberto Icardi.

Hello KOhler,

Hello,

I copied and pasted the sample code that you had given me. But still there are erros in the code.

Kindly let me know how to resolve it. check the screenshot that I had attached to this message.

0 (0 Votes)
RE: Sample Program required
Answer
11/2/18 9:18 AM as a reply to Alberto Icardi.
i AM ALSO FACING ISSUES WITH INITIALISING AND READING THIS DATA IN MY SD CARD.
0 (0 Votes)
RE: Sample Program required
Answer
11/2/18 10:24 AM as a reply to Alberto Icardi.

The program must have a range of 2G and a band width of 300Hz.

And also the program to reading the files on my 32GB memory card. 

0 (0 Votes)
RE: Sample Program required
Answer
11/2/18 1:12 PM as a reply to Alberto Icardi.
Hello Alberto,

to solve the first issue with the Sensor Handle, you simply need to add the following line in the includes at the beginning of your code:

#include "XdkSensorHandle.h"

Regarding the issues you are facing with the SD Card, could you please go more into detail about reading the data on your SD Card? What exactly are you facing here?

In regards to your application specifics, the bandwidth and sensor range can be set with the following two functions for the accelerometer.
 
Accelerometer_setBandwidth()
Accelerometer_setRange()
Unfortunately, a bandwidth of 300Hz is not available, here you would have to choose between 250Hz and 500Hz.

In regards to the SD card reading functionality, I recommend taking a look at the SdCardExample and adapt the part from there to suit your needs. Otherwise, you could also let implement the functionality for you by purchasing a Premium Support package.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Sample Program required
Answer
11/2/18 4:24 PM as a reply to Franjo Stjepandic.

With regard to SD card.

I need the code to initialise my SD card and copy the readings into the SD card.

0 (0 Votes)
RE: Sample Program required
Answer
11/5/18 5:24 PM as a reply to Alberto Icardi.
Hello Alberto,

again, I hardly recommend you to take a deep view at the XDK knowledgebase , which gets accessible after a free registration. Especially as a beginner with the XDK, you will find a lot of helpful articles regarding the Bosch XDK. Within the SD Card article, which is located at the knowledgebase menu entry Data Storage , you will find everything you need, to solve your current issue.

If you prefer a non effort solution and like the thought of getting your custom applications developed by XDK professionals, the earlier mentioned Premium Support package would make this possible.

Kind regards,
Franjo
0 (0 Votes)