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
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,
But the form of data is still not fixed. I shall adjust them one by one.