Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed X_NUCLEO_IKS01A2
Diff: main.cpp
- Revision:
- 18:04cf351e841f
- Parent:
- 13:fc873da5b445
- Child:
- 19:c276649e8e4a
--- a/main.cpp Wed Sep 27 15:48:21 2017 +0000
+++ b/main.cpp Tue Dec 22 23:56:27 2020 +0000
@@ -39,16 +39,17 @@
/* Includes */
#include "mbed.h"
#include "XNucleoIKS01A2.h"
+#include <stdio.h>
+#include <time.h>
/* Instantiate the expansion board */
static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
/* Retrieve the composing elements of the expansion board */
-static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
+//static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
-static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
-static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
+
/* Helper function for printing floats & doubles */
static char *print_double(char* str, double v, int decimalDigits=2)
@@ -88,57 +89,48 @@
/* Simple main function */
int main() {
+ float F;
uint8_t id;
+ int offset = 5; //in order to calibrate the temp sensor
float value1, value2;
- char buffer1[32], buffer2[32];
- int32_t axes[3];
+ //char buffer1[32], buffer2[32];
+ //int32_t axes[3];
/* Enable all sensors */
hum_temp->enable();
press_temp->enable();
- magnetometer->enable();
- accelerometer->enable();
- acc_gyro->enable_x();
- acc_gyro->enable_g();
+
+
+
printf("\r\n--- Starting new run ---\r\n");
-
+
+ /* Time */
+ //Timer t;
+ set_time(1608670310);
+
+
hum_temp->read_id(&id);
- printf("HTS221 humidity & temperature = 0x%X\r\n", id);
+
press_temp->read_id(&id);
- printf("LPS22HB pressure & temperature = 0x%X\r\n", id);
- magnetometer->read_id(&id);
- printf("LSM303AGR magnetometer = 0x%X\r\n", id);
- accelerometer->read_id(&id);
- printf("LSM303AGR accelerometer = 0x%X\r\n", id);
- acc_gyro->read_id(&id);
- printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id);
+
+
while(1) {
printf("\r\n");
-
+ // t.start();
hum_temp->get_temperature(&value1);
- hum_temp->get_humidity(&value2);
- printf("HTS221: [temp] %7s C, [hum] %s%%\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
+ time_t seconds = time(NULL);
- press_temp->get_temperature(&value1);
- press_temp->get_pressure(&value2);
- printf("LPS22HB: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
-
- printf("---\r\n");
+ F = ((value1 * 9.0) / 5.0 + 32) - offset;
+
- magnetometer->get_m_axes(axes);
- printf("LSM303AGR [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+ printf("%u, ", (unsigned int)seconds);
+ //printf("%f, ", t.read());
+ printf(" %7s", print_double(buffer1, F));
+ //printf(" %s", buffer);
- accelerometer->get_x_axes(axes);
- printf("LSM303AGR [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
-
- acc_gyro->get_x_axes(axes);
- printf("LSM6DSL [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
-
- acc_gyro->get_g_axes(axes);
- printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
-
- wait(1.5);
+ wait(1);
+ // wait(1200);
}
}