"Sensors Reader" Sample Application for X-NUCLEO-IKS01A1 Expansion Board

Dependencies:   X_NUCLEO_IKS01A1 mbed

Fork of Sensors_Reader by ST Expansion SW Team

X-NUCLEO-IKS01A1 MEMS Inertial & Environmental Sensor Nucleo Expansion Board Firmware Package

Introduction

This firmware package includes Components Device Drivers, Board Support Package and example applications for STMicroelectronics X-NUCLEO-IKS01A1 MEMS Inertial & Environmental Nucleo Expansion Board.

Example Application

First of all, the example application outputs information retrieved from the Expansion Board over UART. Launch a terminal application (e.g.: PuTTY on Windows, Minicom on Linux) and set the UART port to 9600 bps, 8 bit, No Parity, 1 stop bit.

The "Sensors Reader" program is a more complex example of how to use the X-NUCLEO-IKS01A1 expansion board featuring among others:

  • Support for LSM6DS3 3D Accelerometer & Gyroscope (on DIL 24-pin socket) including free-fall detection
  • Usage of LED & Ticker
  • Exploitation of wait for event
  • (Top-/Bottom-Half) Interrupt handling
Revision:
2:00f62b148a07
Parent:
1:9458657e49ee
Child:
3:c35414b03a65
--- a/main.cpp	Wed Apr 15 15:56:11 2015 +0200
+++ b/main.cpp	Thu Apr 16 10:38:54 2015 +0200
@@ -64,7 +64,7 @@
 
 
 /*** Macros ------------------------------------------------------------------- ***/
-#define APP_LOOP_PERIOD 1000 // in ms
+#define APP_LOOP_PERIOD 1300 // in ms
 
 #if defined(TARGET_K64F)
 #define USER_BUTTON (SW2)
@@ -127,6 +127,20 @@
 
 
 /*** Helper Functions (2/2) ------------------------------------------------------------ ***/
+/* print floats & doubles */
+static char *printDouble(char* str, double v, int decimalDigits=2)
+{
+  int i = 1;
+  int intPart, fractPart;
+
+  for (;decimalDigits!=0; i*=10, decimalDigits--);
+  intPart = (int)v;
+  fractPart = (int)((v-(double)(int)v)*i);
+  sprintf(str, "%i.%i", intPart, fractPart);
+
+  return str;
+}
+
 /* Initialization function */
 static void init(void) {
 	uint8_t hts221_id;
@@ -137,7 +151,7 @@
 
 	/* Determine ID of Humidity & Tempreture Sensor */
 	mems_expansion_board->ht_sensor.ReadID(&hts221_id);
-    	printf("HTS221_ID = 0x%x\n\t\r", hts221_id);
+    	printf("HTS221_ID = 0x%x (%u)\n", hts221_id, hts221_id);
 }
 
 /* Main cycle function */
@@ -148,9 +162,13 @@
 	AxesRaw_TypeDef MAG_Value;
 	AxesRaw_TypeDef ACC_Value;
 	AxesRaw_TypeDef GYR_Value;
-	
+	char buffer1[32];
+	char buffer2[32];
+	char buffer3[32];
+
 	/* Switch LED On */
 	myled = 1;
+	printf("===\n");
 
 	/* Determine Environmental Values */
         mems_expansion_board->ht_sensor.GetTemperature(&TEMPERATURE_Value);
@@ -161,13 +179,15 @@
         mems_expansion_board->gyroscope.Get_G_Axes((int32_t *)&GYR_Value);
 
 	/* Print Values Out */
-        printf("TEMP: %f HUMIDITY: %f PRESSURE: %f\t\r\n ", 
-	       TEMPERATURE_Value, HUMIDITY_Value, PRESSURE_Value);
-        printf("X_AXIS: %ld, Y_AXIS: %ld, Z_AXIS: %ld\t\r\n ", 
+        printf("TEMP: %s, HUMIDITY: %s, PRESSURE: %s\n", 
+	       printDouble(buffer1, TEMPERATURE_Value), 
+	       printDouble(buffer2, HUMIDITY_Value), 
+	       printDouble(buffer3, PRESSURE_Value));
+        printf("X_MAG: %ld, Y_MAG: %ld, Z_MAG: %ld\n", 
 	       MAG_Value.AXIS_X, MAG_Value.AXIS_Y, MAG_Value.AXIS_Z);
-        printf("X_ACC: %ld, Y_ACC: %ld, Z_ACC: %ld\t\r\n ", 
+        printf("X_ACC: %ld, Y_ACC: %ld, Z_ACC: %ld\n", 
 	       ACC_Value.AXIS_X, ACC_Value.AXIS_Y, ACC_Value.AXIS_Z);
-        printf("X_GYR: %ld, Y_GYR: %ld, Z_GYR: %ld\t\r\n ", 
+        printf("X_GYR: %ld, Y_GYR: %ld, Z_GYR: %ld\n", 
 	       GYR_Value.AXIS_X, GYR_Value.AXIS_Y, GYR_Value.AXIS_Z);
 	
 	/* Switch LED Off */