How Do I Use The 1 MB of Flash on Particle P1?

I want to store data arrays on the P1’s 1MB of extra built-in flash.

Is the Flashee library the recommended library for accessing this extra 1MB of flash?

Will the data stored in this Flash survive a Firmware update?

Any advice on this is appreciated :slight_smile:

Yes, I recommend using flashee to store data in the P1 extra SPI flash (MX25L8006E). The library handles the stuff that’s a pain like being able to read and write at the byte level (like the built-in EEPROM library) and wear-leveling.

The data survives both user and system firmware updates.


I’m racking my brain trying to figure out the best way to log some variables over time like Voltage, Power IN/OUT in Watts, Current, Temp, ect… over time so I can graph them out using an LCD graphing library I found on Youtube.

I want to create 1,3,6,12, and 24-hour data history graphs and I need to save the data with a timestamp so I can properly draw the data on the graphs in their correct locations.

I’ve thought over using Arrays & FIFO Circular Buffers but the only thing that makes the most sense is timestamped data since my device can sleep and will not be logging while sleeping.

I plan on using the P1 for this and know I can use the Flashee library to log data to the 1MB of flash but after searching the form I have not run across any kind of examples or applications where anybody was using Flashee for logging timestamped data like I can find code where people are logging to SD Cards.

I basically need to log a variable + Timestamp.

Then I need to use the graphing code to display variable data only for the last 1,3,6,12, or 24 hours using the Time-stamped data.

I’m kinda needing help figuring out the most efficient way to do this.

I see the Flashee library shows you how to write .txt files but I do not think that’s the file format I should be using.

Any advice on this is much appreciated :slight_smile:

I am looking for similar information on this library. In my case i have a struct of long values that i need to write to the library. A simple example that initializes the library, then shows how to assign address followed by a simple write and read would be most helpful.

Everyone does this differently So you need to use what works best for you.
In a design of mine I formatted a comma separated string with the values in it.
Timestamp, Volts, Amps, temp.
Amps = 2.7
Temp = 74.3

The result = “(your timestamp format),13.4,2.7,74.3”

Once you format your data separated by comas (or anything else) you will know their positions in the sting when you read it back. When you read it back, just parse to find the location of the comas, and then you can pull the data out in between and convert it back to a number with atoi or atof.

I’m using the Flashee Library to persist project specific structs{} that happen to contain 1KHz burst samples of pertinent data for references and baselines. The struct uses a collection of data of disparate types from integer arrays to JSON text, floats, etc., and simply reads/writes into the static memory references that I persist to the flash chip.

Works very well and I’ve integrated a complete fault tracking mechanism into some status variable that I have instantiated per device.

would it be possible to show an example?

1 Like

Same here. I would like to see how to read and write to an Array stored on the external P1 flash.

This code is the Flashee example I tweaked to point at a struct instance. It could easily be any other object (array) instance as well… Pretty straightforward… your struct or object can be whatever your project requires:

    case 'r':   // read struct file
        Serial.println("cmd: read struct file front.dat");
        ((fr=f_open(&fil, "front.dat", FA_READ|FA_OPEN_EXISTING))==FR_OK) &&
        ((fr=f_read(&fil,  &myStruct, sizeof(myStruct), &dw))==FR_OK) &&
        printResult(Serial, fr, "File Read OK", "Unable to read struct file");
    case 's':  // save struct file
        Serial.println("cmd: save struct file");
        ((fr=f_open(&fil, "front.dat", FA_WRITE|FA_CREATE_NEW))==FR_OK) &&
        ((fr=f_write(&fil, &myStruct, sizeof(myStruct), &dw))==FR_OK) &&
        printResult(Serial, fr, "Created struct file", "Unable to create struct file");