Hallo @felmue
I have tried it and it works, thanks for the quick help!!!
I am glad that I can finally continue working on my program :)
Hallo @felmue
I have tried it and it works, thanks for the quick help!!!
I am glad that I can finally continue working on my program :)
Hello everyone,
I am programming a M5Stack in the Arduino IDE. I want to read the acceleration data of the installed IMU, save it on the SD card, open it again and edit it. Using the example sketches of Arduino I can do all this. But my problem is that I can't edit the data further. I would like to sum up all recorded accX, accY and accZ values one by one. I have tested this for the accX values, but nothing comes out right. My goal is to integrate the data to get a total value for the speed of one-dimensional linear movements.
Can someone tell me how I can only access the saved and reopened values of my SD card?
Here is my code:
<
//© by Jan-Soeren Henning
#define M5STACK_MPU6886
#include <M5Stack.h>
#include "FS.h"
#include "SD.h"
#include "SPI.h"
#include "time.h"
#include "math.h"
float accX = 0.0F;
float accY = 0.0F;
float accZ = 0.0F;
float zeit = 0.0F;
float testX = 0.0F;
char msg[100];
unsigned long zeit_start = 0.0;
unsigned long zeit_end = 0.0;
boolean button_a = false;
boolean measurement = false;
boolean start = true;
void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Writing file: %s\n", path);
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("Failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("File written");
} else {
Serial.println("Write failed");
}
file.close();
}
void appendFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Appending to file: %s\n", path);
File file = fs.open(path, FILE_APPEND);
if(!file){
Serial.println("Failed to open file for appending");
return;
}
if(file.print(message)){
Serial.println("Message appended");
} else {
Serial.println("Append failed");
}
file.close();
}
void readFile(fs::FS &fs, const char * path){
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if(!file){
Serial.println("Failed to open file for reading");
return;
}
Serial.print("Read from file:\n ");
while(file.available()){
Serial.write(file.read());
testX = testX + (abs(accX));
}
file.close();
}
void setup() {
M5.begin();
M5.Power.begin();
M5.IMU.Init();
M5.Lcd.println("Press button A to\nstart measurement");
Serial.begin(115200);
if(!SD.begin()){
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if(cardType == CARD_MMC){
Serial.println("MMC");
} else if(cardType == CARD_SD){
Serial.println("SDSC");
} else if(cardType == CARD_SDHC){
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
writeFile(SD, "/acceleration.txt", " Time aX aY aZ");
while (start){
zeit_start = millis();
if (M5.BtnA.wasReleasefor(70))
{
button_a = (!(button_a));
measurement = (!(measurement));
}
if (button_a)
{
while (measurement)
{
zeit_end = millis()-zeit_start;
M5.IMU.getAccelData(&accX,&accY,&accZ);
snprintf(msg, 100, "\r\n %5.2lf %5.2lf %5.2lf %5.2lf",zeit, accX, accY, accZ); // => Daten lesen mit sscanf?????
appendFile(SD, "/acceleration.txt", msg);
if (M5.BtnA.wasReleasefor(70))
{
button_a = (!(button_a));
measurement = (!(measurement));
M5.Lcd.println("Press button A to\nstart measurement");
readFile(SD, "/acceleration.txt");
Serial.println(" ");
Serial.println(testX);
}
}
}
}
}
Hello!
Does anyone have any experience with the built-in IMU of the M5Stack? I would like to record the data from the IMU and then store it on an SD card to be able to call it up again later (on the M5Stack) for further processing (integration to get speed and distance).
I tried the examples, "IMU" and "SD(esp32)". The IMU example works. The SD example does not work.
So far I haven't found a way to save the data (using the command M5.IMU.getAccelData(&accX,&accY,&accZ);) to an SD card. Do I have to convert my data into a string to save it in a txt file or can I save the data directly as float variables?
I also wanted to know if there is a command to display the acceleration data directly as a graph on the M5Stack display (and not just the value)?
@m5stack
Thank you for the answer!
The example for the IMU works.
The SD(esp32) example does not work on my M5Stack. So far I haven't found a way to save the data (using the command M5.IMU.getAccelData(&accX,&accY,&accZ);) to an SD card. Do I have to convert my data into a string to save it in a txt file or can I save the data directly as float variables?
I also wanted to know if there is a command to display the acceleration data directly as a graph on the M5Stack display (and not just the value)?
Hallo!
Hat jemand bereits Erfahrung im Umgang mit dem verbauten IMU des M5Stacks? Ich würde gerne die Daten des IMU aufnehmen und dann auf einer SD-Karte abspeichern, um später erneut diese aufzurufen zu können, um sie weiter zu bearbeiten.
Über eine Antwort würde ich mich freuen!
Gruß Jan