🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    How to save data without SD card?

    Scheduled Pinned Locked Moved PRODUCTS
    2 Posts 2 Posters 8.8k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      m5dude
      last edited by

      What is recommended practice to save data without user having SD card? For example say you make a counter and want to save the last count. Since M5 can easily reset from a loose connection , it would be great to save the last count internally.

      In my rsearch i find it is possible to save to flash memory (?) but there are a limited amounts of read /writes. is this correct? I dont want to ruin my machine by having a counter take up all the one-time memory

      any tips?

      1 Reply Last reply Reply Quote 0
      • X Offline
        X-Dron
        last edited by

        use "Preferences" class
        #include <Preferences.h>

        Preferences preferences;

        void setup() {
        Serial.begin(115200);
        Serial.println();

        // Open Preferences with my-app namespace. Each application module, library, etc
        // has to use a namespace name to prevent key name collisions. We will open storage in
        // RW-mode (second parameter has to be false).
        // Note: Namespace name is limited to 15 chars.
        preferences.begin("my-app", false);

        // Remove all preferences under the opened namespace
        //preferences.clear();

        // Or remove the counter key only
        //preferences.remove("counter");

        // Get the counter value, if the key does not exist, return a default value of 0
        // Note: Key name is limited to 15 chars.
        unsigned int counter = preferences.getUInt("counter", 0);

        // Increase counter by 1
        counter++;

        // Print the counter to Serial Monitor
        Serial.printf("Current counter value: %u\n", counter);

        // Store the counter to the Preferences
        preferences.putUInt("counter", counter);

        // Close the Preferences
        preferences.end();

        // Wait 10 seconds
        Serial.println("Restarting in 10 seconds...");
        delay(10000);

        // Restart ESP
        ESP.restart();
        }

        void loop() {}

        1 Reply Last reply Reply Quote 3

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post