<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Store and reopen IMU data on SD card]]></title><description><![CDATA[<p dir="auto">Hello everyone,<br />
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.<br />
Can someone tell me how I can only access the saved and reopened values of my SD card?<br />
Here is my code:<br />
&lt;<br />
//© by Jan-Soeren Henning<br />
#define M5STACK_MPU6886<br />
#include &lt;M5Stack.h&gt;<br />
#include "FS.h"<br />
#include "SD.h"<br />
#include "SPI.h"<br />
#include "time.h"<br />
#include "math.h"</p>
<p dir="auto">float accX = 0.0F;<br />
float accY = 0.0F;<br />
float accZ = 0.0F;<br />
float zeit = 0.0F;<br />
float testX = 0.0F;<br />
char msg[100];<br />
unsigned long zeit_start = 0.0;<br />
unsigned long zeit_end = 0.0;<br />
boolean button_a = false;<br />
boolean measurement = false;<br />
boolean start = true;</p>
<p dir="auto">void writeFile(fs::FS &amp;fs, const char * path, const char * message){<br />
Serial.printf("Writing file: %s\n", path);</p>
<pre><code>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();
</code></pre>
<p dir="auto">}<br />
void appendFile(fs::FS &amp;fs, const char * path, const char * message){<br />
Serial.printf("Appending to file: %s\n", path);</p>
<pre><code>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();
</code></pre>
<p dir="auto">}<br />
void readFile(fs::FS &amp;fs, const char * path){<br />
Serial.printf("Reading file: %s\n", path);<br />
File file = fs.open(path);<br />
if(!file){<br />
Serial.println("Failed to open file for reading");<br />
return;<br />
}<br />
Serial.print("Read from file:\n ");<br />
while(file.available()){<br />
Serial.write(file.read());<br />
testX = testX + (abs(accX));<br />
}<br />
file.close();<br />
}<br />
void setup() {<br />
M5.begin();<br />
M5.Power.begin();<br />
M5.IMU.Init();<br />
M5.Lcd.println("Press button A to\nstart measurement");</p>
<p dir="auto">Serial.begin(115200);<br />
if(!SD.begin()){<br />
Serial.println("Card Mount Failed");<br />
return;<br />
}<br />
uint8_t cardType = SD.cardType();</p>
<pre><code>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(&amp;accX,&amp;accY,&amp;accZ);

          snprintf(msg, 100, "\r\n  %5.2lf   %5.2lf     %5.2lf     %5.2lf",zeit, accX, accY, accZ);    // =&gt; 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);
             }
      }
  }
</code></pre>
<p dir="auto">}<br />
}</p>
<blockquote></blockquote>
]]></description><link>https://community.m5stack.com/topic/2459/store-and-reopen-imu-data-on-sd-card</link><generator>RSS for Node</generator><lastBuildDate>Tue, 05 May 2026 13:06:24 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2459.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Nov 2020 12:13:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Store and reopen IMU data on SD card on Fri, 13 Nov 2020 10:09:44 GMT]]></title><description><![CDATA[<p dir="auto">Hallo <a class="plugin-mentions-user plugin-mentions-a" href="/user/felmue" aria-label="Profile: felmue">@<bdi>felmue</bdi></a></p>
<p dir="auto">I have tried it and it works, thanks for the quick help!!!<br />
I am glad that I can finally continue working on my program :)</p>
]]></description><link>https://community.m5stack.com/post/10729</link><guid isPermaLink="true">https://community.m5stack.com/post/10729</guid><dc:creator><![CDATA[jsh]]></dc:creator><pubDate>Fri, 13 Nov 2020 10:09:44 GMT</pubDate></item><item><title><![CDATA[Reply to Store and reopen IMU data on SD card on Thu, 12 Nov 2020 18:25:11 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/jsh" aria-label="Profile: jsh">@<bdi>jsh</bdi></a></p>
<p dir="auto">in your <code>readFile()</code> function try something like this to sum up <code>accX</code> into <code>testX</code>:</p>
<pre><code>  testX = 0.0;
  while(file.available())
  {
    // read zeit - skip over
    file.parseFloat();
    // read accX - sum up
    testX = testX + file.parseFloat();
    // read accY - skip over
    file.parseFloat();
    // read accZ - skip over
    file.parseFloat();
  }
</code></pre>
<p dir="auto">instead of</p>
<pre><code>  while(file.available())
  {
    Serial.write(file.read());
    testX = testX + (abs(accX));
  }
</code></pre>
<p dir="auto">Good luck!</p>
<p dir="auto">Cheers<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/10722</link><guid isPermaLink="true">https://community.m5stack.com/post/10722</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Thu, 12 Nov 2020 18:25:11 GMT</pubDate></item></channel></rss>