IKS01A1 Demo
Dependencies: X_NUCLEO_IKS01A1
Revision 11:c613d631c1e9, committed 2019-09-11
- Comitter:
- noutram
- Date:
- Wed Sep 11 09:58:59 2019 +0000
- Parent:
- 10:211cd9c27d5e
- Child:
- 12:504236c45846
- Commit message:
- For ROCO module
Changed in this revision
--- a/main.cpp Fri Mar 24 10:14:11 2017 +0000
+++ b/main.cpp Wed Sep 11 09:58:59 2019 +0000
@@ -40,6 +40,8 @@
#include "mbed.h"
#include "x_nucleo_iks01a1.h"
+Ticker t;
+
/* Instantiate the expansion board */
static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15);
@@ -86,49 +88,62 @@
return str;
}
+DigitalIn sw1(USER_BUTTON);
+int32_t m_axes[3];
+int32_t a_axes[3];
+int32_t g_axes[3];
+
+void doSample()
+{
+}
/* 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");
+ Serial pc(USBTX, USBRX);
+ pc.baud(926100);
+
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));
+ pc.printf("Press the blue button to start\n\r");
+ unsigned long tt = 0;
+ while (sw1 == 0);
+ wait_ms(250.0);
+ while (sw1 == 1);
+ wait_ms(250.0);
+
+ pc.printf("time[ms],x[mag/mgauss],y[mag/mgauss],z[mag/mgauss],x[acc/mg],y[acc/mg],z[acc/mg],x[gyro/mdps],y[gyro/mdps],z[gyro/mdps]\n\r");
+
+ const unsigned Fs = 100;
+ const double T = 1.0 / (double)Fs;
+ const unsigned Tms = (unsigned)(T*1000.0);
+ t.attach(doSample, T);
+
+ while(sw1 == 1) {
- 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]);
+ sleep();
+
+ magnetometer->get_m_axes(m_axes);
+ accelerometer->get_x_axes(a_axes);
+ gyroscope->get_g_axes(g_axes);
+
+ pc.printf("%lu,",tt); tt+=Tms;
+ pc.printf("%d,%d,%d,", m_axes[0], m_axes[1], m_axes[2]);
+ pc.printf("%d,%d,%d,", a_axes[0], a_axes[1], a_axes[2]);
+ pc.printf("%d,%d,%d\r\n", g_axes[0], g_axes[1], g_axes[2]);
- accelerometer->get_x_axes(axes);
- printf("LSM6DS0 [acc/mg]: %7ld, %7ld, %7ld\r\n", axes[0], axes[1], axes[2]);
+ }
+
+ pc.printf("Press Reset Button to Restart\n\r");
+ while(1);
+}
- gyroscope->get_g_axes(axes);
- printf("LSM6DS0 [gyro/mdps]: %7ld, %7ld, %7ld\r\n", axes[0], axes[1], axes[2]);
- wait(1.5);
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Wed Sep 11 09:58:59 2019 +0000 @@ -0,0 +1,1 @@ +https://github.com/armmbed/mbed-os/#73f096399b4cda1f780b140c87afad9446047432
--- a/mbed.bld Fri Mar 24 10:14:11 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://mbed.org/users/mbed_official/code/mbed/builds/093f2bd7b9eb \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json Wed Sep 11 09:58:59 2019 +0000
@@ -0,0 +1,3 @@
+{
+ "requires": ["bare-metal"]
+}
\ No newline at end of file