[SOLVED]8 red flashes using Flashee Eeprom library

Hi everyone,

I have created this simple code that writes to the flash memory through a spark.function. I can then read what has been written through a Spark.variable. it seems to work fine but after calling the function about ten or twelve times, the core starts flashing red with 8 flashes between the sos. I believe that means “out of heap memory”. I’m not quite sure how to go about solving this?

#include "flashee-eeprom/flashee-eeprom.h"
using namespace Flashee;
FlashDevice* flash;

char buf1[20];
char bufr[20];

void setup() {
    Spark.variable("memdata", &bufr, STRING);
    Spark.function("timeset", memupdate);
    varset();
    /*Serial.begin(9600);
    while(!Serial.available()) SPARK_WLAN_Loop();
    Serial.println("hello!!!");*/
}

void loop() {
}

int memupdate(String newtriger)
{
    FlashDevice* flash = Devices::createAddressErase();
    newtriger.toCharArray(buf1, 16);
    flash->writeString(buf1, 0); 
    varset();
    return 10;
}

void varset()
{
    FlashDevice* flash = Devices::createAddressErase();
    flash->read(bufr, 0, 15);
    Serial.println(bufr);
}

Thanks for your help.


I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy

First you need to drop the ampersand & in the above line. Since you dropped the [] it already is an address.

Thanks for the suggestion, but i dropped the & and the issue still occurs.

The next thing that pops to mind is, that on one hand you’ve got a global flash variable, but then you always create a new instance with each call to varset() and memupdate().

I’d rather stick with using the global instance.

void setup() {
    Spark.variable("memdata", bufr, STRING);
    Spark.function("timeset", memupdate);

    flash = Devices::createAddressErase();

    varset();
}

And comment out the respective lines in the other functions.

3 Likes

Thanks a lot, that did the trick! :slight_smile:

1 Like

I was going to write the same but you were quicker on the draw! :slight_smile:

1 Like