Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to write/read a string (variable length) to persistent storage on Nano 33 IOT #55

Closed
sdetweil opened this issue Apr 10, 2023 · 3 comments

Comments

@sdetweil
Copy link

sdetweil commented Apr 10, 2023

i am trying to the the eeprom emulation (I guess?)
https://github.com/cmaglie/FlashStorage/blob/master/examples/EmulateEEPROM/EmulateEEPROM.ino

EEProm.read/write/isValid()

compiles ok, just always reports isValid = false

is this the right function to use?

I REALLY don't CARE HOW its done... name, address, location,, whatever
flash, eeprom, stones in a cup.

the example doesn't say it wont work on this board.. and the lib says it supports samd21 and 51

String fileName="something";
          int i=0;
          for(;i<fileName.length();i++){
            EEPROM.write(i, fileName.charAt(i));  // write out 1 char of data at a time
          }
          EEPROM.write(i,'\0');  // add on a string terminator
          EEPROM.commit();   // flush 

this is a json string with variable length elements, I can imagine a max length..

@sdetweil
Copy link
Author

sdetweil commented Apr 16, 2023

well, part 1, DOAH, READ ... it uses flash and flash is wiped on firmware upload.. ...

now.. part 2, I'm not getting out what I put in..

do I have to commit after each write?,
example says no

my read code

char xx[]="some string of dummy data";
if(EEPROM.isValid()){
    Serial.println("config present");
    Serial.println("using stored data");
    //  create a buffer
    char x[sizeof(xx)+10];
    // clear it, expect we will read less data than buffer size, most of the time.
    memset(x,0,sizeof(x));
    // loop thru the eeprom (whatever it is) 
    for (int i=0; i<sizeof(xx)+10; i++) {
        Serial.print(" ");
        // get a character
        unsigned char y = EEPROM.read(i);
        // if its not a null terminator (c stringish)
        if( y != 0){
          // save it in the buffer  
          x[i]=y;
        }
        // done with the read loop
        else
          break;
    }
}

@sdetweil
Copy link
Author

only 25 chars of my 110 chars are retrievable from flash on my Nano 33 IOT
i write ascii chars and then '\0', and then commit()
I read til I see the '\0'

@sdetweil
Copy link
Author

ok, don't know why, but it thinks there is a '\0' embedded in the data, but not..

anyhow, now write 1 byte length, rest of data
read 1 byte length, rest of data..

all ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant