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.
Diff: main.cpp
- Revision:
- 18:91a38b13d21d
- Parent:
- 13:fc873da5b445
- Child:
- 19:c765e311adbd
--- a/main.cpp Wed Sep 27 15:48:21 2017 +0000
+++ b/main.cpp Thu Oct 14 12:50:50 2021 +0000
@@ -39,6 +39,14 @@
/* Includes */
#include "mbed.h"
#include "XNucleoIKS01A2.h"
+#include "SDFileSystem.h"
+#include "FATFileSystem.h"
+#include "iostream"
+
+Serial pc(USBTX, USBRX);
+// SDFileSystem sd(PA_7, PA_6, PA_5, PB_6, "sd"); // MOSI, MISO, SCK, CS
+SDFileSystem sd(D11, D12, D13, D10, "sd");// the pinout on the mbed Cool Components workshop board
+FILE *fp;
/* Instantiate the expansion board */
static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
@@ -113,32 +121,69 @@
printf("LSM303AGR accelerometer = 0x%X\r\n", id);
acc_gyro->read_id(&id);
printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id);
+
+ pc.printf("Check SD\r\n");
+ mkdir("/sd/ISK01A2", 0777);
+ fp = fopen("/sd/ISK01A2/test.txt", "r");
+ if (fp != NULL) {
+ fclose(fp);
+ remove("/sd/test.txt");
+ pc.printf("Remove an existing file with the same name\r\n");
+ }
+
+ fp = fopen("/sd/ISK01A2/test.txt", "w");
+ if (fp == NULL) {
+ error("Unable to write the file\r\n");
+ } /*else {
+ fprintf(fp, "mbed SDCard application!");
+ fclose(fp);
+ pc.printf("File successfully written!\r\n");
+ }*/
+ int n=0;
+ printf("SD ok, we can start");
+ fprintf(fp, " DATA of STM32F401RE with ISK01A2\r\n");
+ printf("\r\n");
- while(1) {
+ while(n<60) {
+
+
+ printf("\r\n Number of cycle: %d \r\n", n);
printf("\r\n");
-
+ fprintf(fp, "\r\n Number of cycle: %d \r\n", n);
+ fprintf(fp, "\r\n");
+
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));
+ printf("Temperature & Humidity: [temp] %7s C, [hum] %s%%\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
+ fprintf(fp, "Temperature & Humidity: [temp] %7s C, [hum] %s%%\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
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("Temperature & Pressure: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
+ fprintf(fp, "Temperature & Pressure: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
printf("---\r\n");
+ fprintf(fp, "---\r\n");
magnetometer->get_m_axes(axes);
- printf("LSM303AGR [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+ printf("Magnetometer [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+ fprintf(fp,"Magnetometer [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
accelerometer->get_x_axes(axes);
- printf("LSM303AGR [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+ printf("Accelerometer [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+ fprintf(fp, "Accelerometer [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]);
+ printf("Accelerometer & Gyroscope x [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+ fprintf(fp, "Accelerometer & Gyroscope x [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);
+ printf("Accelerometer & Gyroscope g [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+ fprintf(fp, "Accelerometer & Gyroscope g [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+
+ n+=1;
+ wait(1);
}
+ fclose(fp);
+ pc.printf("File successfully written!\r\n");
}