element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
IoT on Wheels Design Challenge
  • Challenges & Projects
  • Design Challenges
  • IoT on Wheels Design Challenge
  • More
  • Cancel
IoT on Wheels Design Challenge
Blog walkingwheels on Water  #8 Import library of X-NUCLEO-IKS01A2 for better test
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fyaocn
  • Date Created: 11 Oct 2017 8:44 AM Date Created
  • Views 604 views
  • Likes 2 likes
  • Comments 2 comments
  • walkingwheels
Related
Recommended

walkingwheels on Water  #8 Import library of X-NUCLEO-IKS01A2 for better test

fyaocn
fyaocn
11 Oct 2017

1. Present progress,

I have tried to test the BlueNRG extension board. But come to find out the board is broke by mistake. It can not work. At the beginning of the design , I have flashed program and test with BLE scanning APP, everything goes fine. I have to skip the repair mode to next stage, I will figure out what happened later.

For Remote control part, WIFI via cloud is challenge part as option work. I think I should use this part now.

2 Another work is migration of X-NUCLEO-IKS01A1 sample by Import library of  X-NUCLEO-IKS01A2X-NUCLEO-IKS01A2 Again I can not acess undisclosed part of code in mbed with brief introduction only

image

But in the end, I made it.  Full code as follows,

/* Includes */
#include "mbed.h"
#include "XNucleoIKS01A2.h"


/* Instantiate the expansion board */
static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance();


/* Retrieve the composing elements of the expansion board */
static GyroSensor *gyroscope = mems_expansion_board->acc_gyro;
static MotionSensor *accelerometer = mems_expansion_board->accelerometer;
static MagneticSensor *magnetometer = mems_expansion_board->magnetometer;
static HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor;
static PressureSensor *pressure_sensor = mems_expansion_board->pt_sensor;
static TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor;
static TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor;


/* Helper function for printing floats & doubles */
static char *printDouble(char* str, double v, int decimalDigits=2)
{
  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);


  /* 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;
}




/* Simple main function */
int main() {
  uint8_t id;
  float value1, value2;
  char buffer1[32], buffer2[32];
  int32_t axes[3];
  
  printf("\r\n--- Starting new run ---\r\n");


  humidity_sensor->read_id(&id);
  printf("HTS221  humidity & temperature    = 0x%X\r\n", id);
  pressure_sensor->read_id(&id);
  printf("LPS25H  pressure & temperature    = 0x%X\r\n", id);
  magnetometer->read_id(&id);
  printf("LIS3MDL magnetometer              = 0x%X\r\n", id);
  gyroscope->read_id(&id);
  printf("LSM6DS0 accelerometer & gyroscope = 0x%X\r\n", id);
  
  wait(3);

  while(1) {
    printf("\r\n");


    temp_sensor1->get_temperature(&value1);
    humidity_sensor->get_humidity(&value2);
    printf("HTS221: [temp] %7s°C,   [hum] %s%%\r\n", printDouble(buffer1, value1), printDouble(buffer2, value2));
    
    temp_sensor2->get_fahrenheit(&value1);
    pressure_sensor->get_pressure(&value2);
    printf("LPS25H: [temp] %7s°F, [press] %smbar\r\n", printDouble(buffer1, value1), printDouble(buffer2, value2));


    printf("---\r\n");


    magnetometer->get_m_axes(axes);
    printf("LIS3MDL [mag/mgauss]:  %7ld, %7ld, %7ld\r\n", axes[0], axes[1], axes[2]);


    accelerometer->get_x_axes(axes);
    printf("LSM6DS0 [acc/mg]:      %7ld, %7ld, %7ld\r\n", axes[0], axes[1], axes[2]);


    gyroscope->get_g_axes(axes);3
    printf("LSM6DS0 [gyro/mdps]:   %7ld, %7ld, %7ld\r\n", axes[0], axes[1], axes[2]);


    wait(1.5);
  }
}

 

3. First, declare the instance,

static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance();

Even if you are not familiar with hardware of pins, you can still make it by declare an empty instance(). If it is NULL, D14 and D15 shall be declared as I2C port for sensors.

Then declare variables pointers for sensor data,

/* Retrieve the composing elements of the expansion board */
static GyroSensor *gyroscope = mems_expansion_board->acc_gyro;
static MotionSensor *accelerometer = mems_expansion_board->accelerometer;
static MagneticSensor *magnetometer = mems_expansion_board->magnetometer;
static HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor;
static PressureSensor *pressure_sensor = mems_expansion_board->pt_sensor;
static TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor;
static TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor;

 

Then I got the full feedback list for sensors, unlike last test in  #4 Coding on Nucleo-STM32L476 with MEMS board X-NUCLEO-IKS01A2 , only similar sensor of temperature is shown,

image

But the form of data is still not fixed. I shall adjust them one by one.

  • Sign in to reply
  • DAB
    DAB over 8 years ago

    Nice update.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • e14phil
    e14phil over 8 years ago

    Looking good.   Please make sure you are tagging your blogs for the IoT on Wheels Challenge.

     

    Phil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube