/////////////////////////////////// // // ikso_1 project // // created 6/14/21 by tj // rev 0 // /////////////////////////////////// // // ikso example file for class // // Simple reads // // modified from STM example // /////////////////////////////////// #include "mbed.h" #include #include "XNucleoIKS01A3.h" // for IKSO //#include "rtos.h" void enable_sensors(void); /////////////////////////////////// // setup the IKSO board // Required pins are in the documentation static XNucleoIKS01A3 * ikso_board = XNucleoIKS01A3::instance(D14, D15, D4, D5, A3, D6, A4); // // Assign pointers to each part - only include parts being used // note: 2 ways to code the access to these // (*ikso_board).SENSOR or ikso_board->SENSOR static LIS2MDLSensor * magnetometer = (*ikso_board).magnetometer; static HTS221Sensor * humidity_temp = (*ikso_board).ht_sensor; static LPS22HHSensor * pressure_temp = (*ikso_board).pt_sensor; static LSM6DSOSensor * accelerometer_gyro = ikso_board->acc_gyro; static LIS2DW12Sensor * accelerometer = ikso_board->accelerometer; static STTS751Sensor * temp = ikso_board->t_sensor; ////////////////////////////////////// void splash(void); void enable_sensors(); void sensor_id(); int main(void){ setbuf(stdout, NULL); // disable buffering // temporary variables float val1; float val2; int axis[3]; splash(); // enable the sensors enable_sensors(); // print sensor IDs sensor_id(); printf("\n\n........Reading Sensors .......\n\n"); magnetometer->get_m_axes(axis); printf("LIS2MDL [mag/mgauss]:\t%6i, %6i, %6i\n\n", axis[0], axis[1], axis[2]); temp->get_temperature(&val1); printf("STTS751:\t[temp] %.1f C\n", val1); humidity_temp->get_temperature(&val1); humidity_temp->get_humidity(&val2); printf("HTS221:\t\t[temp] %.1f C,\t[hum] %.1f mbar\n", val1, val2); pressure_temp->get_temperature(&val1); pressure_temp->get_pressure(&val2); printf("LPS22HH:\t[temp] %.1f C,\t[press] %.0f mbar\n\n", val1, val2); accelerometer->get_x_axes(axis); printf("LIS2DW12 [acc/mg]:\t%6i, %6i, %6i\n", axis[0], axis[1], axis[2]); accelerometer_gyro->get_x_axes(axis); printf("LSM6DSO [acc/mg]:\t%6i, %6i, %6i\n", axis[0], axis[1], axis[2]); accelerometer_gyro->get_g_axes(axis); printf("LSM6DSO [gyro/mdps]:\t%6i, %6i, %6i\n", axis[0], axis[1], axis[2]); printf("\n\n.............................\n\n"); printf("\t\t\tX\tY\tZ\n"); while (1) { accelerometer_gyro->get_x_axes(axis); printf("LSM6DSO [acc/mg]:\t%-6i %-6i %-6i\r", axis[0], axis[1], axis[2]); wait_us(100000); }// end while return 0; }// end main void splash(void){ printf("\n\nikso_1 - example for EE2905\n"); printf("Using Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); return; }// end splash void enable_sensors(void){ printf("Sensors Enabled\n"); magnetometer->enable(); temp->enable(); humidity_temp->enable(); pressure_temp->enable(); accelerometer->enable_x(); accelerometer_gyro->enable_x(); accelerometer_gyro->enable_g(); return; }// end enable_sensors void sensor_id(void){ uint8_t id; printf("=======================\n"); printf("Sensor IDs:\n"); magnetometer->read_id(&id); printf("LIS2MDL magnetometer\t\t\t= 0x%X\n", id); temp->read_id(&id); printf("STTS751 temperature\t\t\t= 0x%X\n", id); humidity_temp->read_id(&id); printf("HTS221 humidity & temperature\t\t= 0x%X\n", id); pressure_temp->read_id(&id); printf("LPS22HH pressure & temperature\t\t= 0x%X\n", id); accelerometer->read_id(&id); printf("LIS2DW12 accelerometer\t\t\t= 0x%X\n", id); accelerometer_gyro->read_id(&id); printf("LSM6DSO accelerometer & gyroscope\t= 0x%X\n", id); printf("=======================\n"); return; }// end sensor_id