"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:
54:d812bb378d46
Parent:
51:5ce8202680b4
Child:
56:ad6a0fcf899a
diff -r 7b6bec832e62 -r d812bb378d46 main.cpp
--- a/main.cpp	Wed Jul 01 13:12:11 2015 +0200
+++ b/main.cpp	Wed Jul 01 15:29:57 2015 +0200
@@ -142,11 +142,31 @@
 {
   int i = 1;
   int intPart, fractPart;
+  int len;
+  char *ptr;
 
+  /* prepare decimal digits multiplicator */
   for (;decimalDigits!=0; i*=10, decimalDigits--);
+
+  /* calculate integer & fractinal parts */
   intPart = (int)v;
   fractPart = (int)((v-(double)(int)v)*i);
-  sprintf(str, "%i.%i", intPart, fractPart);
+
+  /* fill in integer part */
+  sprintf(str, "%i.", intPart);
+
+  /* prepare fill in of fractional part */
+  len = strlen(str);
+  ptr = &str[len];
+
+  /* fill in leading fractional zeros */
+  for (i/=10;i>1; i/=10, ptr++) {
+	  if(fractPart >= i) break;
+	  *ptr = '0';
+  }
+
+  /* fill in (rest of) fractional part */
+  sprintf(ptr, "%i", fractPart);
 
   return str;
 }
@@ -212,14 +232,14 @@
 	ret |= (!CALL_METH(gyroscope, Get_G_Axes, (int32_t *)&GYR_Value, 0) ? 0x0 : 0x40);
 
 	/* Print Values Out */
-        printf("I2C errors: 0x%.2x      X         Y         Z\n", ret); 
+        printf("I2C [errors]: 0x%.2x    X         Y         Z\n", ret); 
         printf("MAG [mgauss]: %9ld %9ld %9ld\n", 
 	       MAG_Value.AXIS_X, MAG_Value.AXIS_Y, MAG_Value.AXIS_Z);
         printf("ACC [mg]:     %9ld %9ld %9ld\n", 
 	       ACC_Value.AXIS_X, ACC_Value.AXIS_Y, ACC_Value.AXIS_Z);
         printf("GYR [mdps]:   %9ld %9ld %9ld\n", 
 	       GYR_Value.AXIS_X, GYR_Value.AXIS_Y, GYR_Value.AXIS_Z);
-        printf("---\nTEMP | HUMIDITY: %s°C | %s%%\nTEMP | PRESSURE: %s°F | %smbar\n", 
+        printf("---\nTEMP | HUMIDITY: %s°C |   %s%%\nTEMP | PRESSURE: %s°F | %4smbar\n", 
 	       printDouble(buffer1, TEMPERATURE_Value), 
 	       printDouble(buffer2, HUMIDITY_Value), 
 	       printDouble(buffer4, PRESSURE_Temp_Value),