Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: EEPROMex not saving past byte 151

  1. #1

    EEPROMex not saving past byte 151

    Hi all,
    I'm currently working on a project that will save a lot of variables. I'm using a teensy 3.6. It took me awhile to find where the issue was coming from, but it looks like when saving it wont save after byte 151. I made a simple version of the code that can reproduce the error.
    Code:
    #include <Bounce.h>
    #include <EEPROMex.h>
    
    float  float1;
    float  float2;
    bool  bool3;
    float  float4;
    float  float5;
    float  float6;
    float  float7;
    float  float8;
    float  float9;
    float  float10;
    float  float11;
    float  float12;
    float  float13;
    float  float14;
    float  float15;
    float  float16;
    float  float17;
    float  float18;
    float  float19;
    float  float20;
    float  float21;
    int  int22;
    int  int23;
    int  int24;
    float  float25;
    float  float26;
    float  float27;
    float  float28;
    float  float29;
    float  float30;
    float  float31;
    float float32;
    float  float33;
    float  float34;
    float  float35;
    float  float36;
    float  float37;
    float  float38;
    int  int39;
    int  int40;
    float  float41;
    float  float42;
    float  float43;
    float  float44;
    bool  bool45;
    
    float MODquantizerLEFT;
    const int shiftPin = 28;
    Bounce SHIFTbutton = Bounce(shiftPin, 100);  // 10 ms debounce
    const int ratioPin = 27;
    Bounce RATIObutton = Bounce(ratioPin, 100);  // 10 ms debounce
    
    
    void setup() {
      EEPROM.setMaxAllowedWrites(80);
      // put your setup code here, to run once:
      Serial.begin(9600);
    
      pinMode(shiftPin, INPUT_PULLUP);
      pinMode(ratioPin, INPUT_PULLUP);
    
    
      
      EEPROM.setMemPool(0, EEPROMSizeTeensy3);
      float1 = EEPROM.readFloat(5);
      float2 = EEPROM.readFloat(1);
      bool3 = EEPROM.readByte(1);
      float4 = EEPROM.readFloat(9);
      float5 = EEPROM.readFloat(13);
      float6 = EEPROM.readFloat(17);
      float7 = EEPROM.readFloat(21);
      float8 = EEPROM.readFloat(25);
      float9 = EEPROM.readFloat(29);
      float10 = EEPROM.readFloat(33);
      float11 = EEPROM.readFloat(37);
      float12 = EEPROM.readFloat(41);
      float13 = EEPROM.readFloat(45);
      float14 = EEPROM.readFloat(49);
      float15 = EEPROM.readFloat(53);
      float16 = EEPROM.readFloat(57);
      float17 = EEPROM.readFloat(61);
      float18 = EEPROM.readFloat(65);
      float19 = EEPROM.readFloat(69);
      float20 = EEPROM.readFloat(73);
      float21 = EEPROM.readFloat(77);
      int22 = EEPROM.readInt(81);
      int23 = EEPROM.readInt(83);
      int24 = EEPROM.readInt(85);
      float25 = EEPROM.readFloat(87);
      float26 = EEPROM.readFloat(91);
      float27 = EEPROM.readFloat(95);
      float28 = EEPROM.readFloat(99);
      float29 = EEPROM.readFloat(103);
      float30 = EEPROM.readFloat(107);
      float31 = EEPROM.readFloat(111);
      float32 = EEPROM.readFloat(115);
      float33 = EEPROM.readFloat(119);
      float34 = EEPROM.readFloat(123);
      float35 = EEPROM.readFloat(127);
      float36 = EEPROM.readFloat(131);
      float37 = EEPROM.readFloat(135);
      float38 = EEPROM.readFloat(139);
      int39 = EEPROM.readInt(143);
      int40 = EEPROM.readInt(145);
      float41 = EEPROM.readFloat(147);
      float42 = EEPROM.readFloat(151);
      float43 = EEPROM.readFloat(155);
      float44 = EEPROM.readFloat(159);
      bool45 = EEPROM.readByte(163);
    
    }  
    
    
    
    void loop() { //START VOID LOOP
    
    //SAVE START//////////////////////////////////////////////////////
    if(RATIObutton.update()){
      if (RATIObutton.fallingEdge()){
        Serial.println("saved");
    
        //EEPROM.updateFloat(147, float41);
        EEPROM.updateFloat(5,float1);
        EEPROM.updateFloat(1,float2);
        EEPROM.updateByte(1,bool3);
        EEPROM.updateFloat(13,float4);
        EEPROM.updateFloat(9,float5);
        EEPROM.updateFloat(17,float6);
        EEPROM.updateFloat(21,float7);
        EEPROM.updateFloat(25,float8);
        EEPROM.updateFloat(29,float9);
        EEPROM.updateFloat(33,float10);
        EEPROM.updateFloat(37,float11);
        EEPROM.updateFloat(41,float12);
        EEPROM.updateFloat(45,float13);
        EEPROM.updateFloat(49,float14);
        EEPROM.updateFloat(53,float15);    
        EEPROM.updateFloat(57,float16);
        EEPROM.updateFloat(61,float17);
        EEPROM.updateFloat(65,float18);
        EEPROM.updateFloat(69,float19);
        EEPROM.updateFloat(73,float20);
        EEPROM.updateFloat(77,float21);
        EEPROM.updateInt(81,int22);
        EEPROM.updateInt(83,int23);
        EEPROM.updateInt(85,int24);
        EEPROM.updateFloat(87,float25);
        EEPROM.updateFloat(91,float26);
        EEPROM.updateFloat(95,float27);
        EEPROM.updateFloat(99,float28);
        EEPROM.updateFloat(103,float29);
        EEPROM.updateFloat(107,float30);
        EEPROM.updateFloat(111,float31);
        EEPROM.updateFloat(115,float32);
        EEPROM.updateFloat(119,float33);
        EEPROM.updateFloat(123,float34);
        EEPROM.updateFloat(127,float35);
        EEPROM.updateFloat(131,float36);
        EEPROM.updateFloat(135,float37);
        EEPROM.updateFloat(139,float38);
        EEPROM.updateInt(143,int39);
        EEPROM.updateInt(145,int40);
        EEPROM.updateFloat(147,float41);   //  <-- THIS WORKS
        EEPROM.updateFloat(151,float42);   //  <-- NOTHING FROM HERE FORWARD WORKS
        EEPROM.updateFloat(154,float43);
        EEPROM.updateFloat(159,float44);
        EEPROM.updateByte(163,bool45);
    
        
        float41 = EEPROM.readFloat(147);
        Serial.println("float 41");
        Serial.println(float41);
        
        float42 = EEPROM.readFloat(151);
        Serial.println("float 42");
        Serial.println(float42);
        
      }
    }
    
    //SAVE END////////////////////////////////////////////////////////
    
    if(SHIFTbutton.update()){
      if (SHIFTbutton.fallingEdge()){
    
        float42 = .5000;
        float41 = .5000;
        Serial.println("float 41");
        Serial.println(float41);
        Serial.println("float 42");
        Serial.println(float42);
        }
      }
    }
    Here's what the serial monitor shows after pressing the shift button then the ratio(save) button.
    Code:
    float 41
    0.50
    float 42
    0.50
    saved
    float 41
    0.50
    float 42
    ovf
    Here's the library in question..
    https://playground.arduino.cc/Code/EEPROMex
    https://github.com/thijse/Arduino-EEPROMEx

    Any help would be greatly appreciated.

    *edit*
    changing
    EEPROM.setMaxAllowedWrites(80);
    to
    EEPROM.setMaxAllowedWrites(100);
    Doesnt change anything... still get the error with float42 and beyond.
    Last edited by cfredisded; 03-05-2019 at 01:39 AM. Reason: Clarification

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,019
    Teensy 3.6 has 4K Bytes of EEPROM, the library code is limiting you to 2048 as written - but that shouldn't be an issue if all the math and numbers work out.

    Also not [perhaps directly] the issue … In the list of Read and write - it looks like 'int' is assumed 16 bits - and it is 32 bits on Teensy 3.x if these are byte offsets:
    Code:
      float19 = EEPROM.readFloat(69);
      float20 = EEPROM.readFloat(73);
      float21 = EEPROM.readFloat(77);
      int22 = EEPROM.readInt(81);
      int23 = EEPROM.readInt(83);
      int24 = EEPROM.readInt(85);
      float25 = EEPROM.readFloat(87);
      float26 = EEPROM.readFloat(91);
    Also - not to the problem - but other than having the different types interwoven - this would be so much easier and cleaner using arrays.

    If this is the right reading of the output it shows float42 holding the value of 'overflow'? Perhaps a valid value was never placed in that location so reading it back cannot return a valid value? If that was printed in setup() after the ' float42 = EEPROM.readFloat(151);' that is either failing or returning the 'ovf' value there.

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Location
    -
    Posts
    9,756
    If never seen this EEPROMex - knowing that the native teensy library works, i'd say it is the problem.

    This: EEPROM.setMaxAllowedWrites(80); looks suspicious, too.

    Perhaps try without that library?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,398
    I believe this line is the problem.

    Code:
        EEPROM.updateFloat(154,float43);
    It should probably be 155, not 154. You're clobbering the last byte of the float42 you wrote at 151 when you write float43. That's why float42 always reads back incorrectly.

  5. #5
    You're clobbering the last byte of the float42 you wrote at 151 when you write float43
    Dangit... thanks Paul. You're right I was clobbering that float. Can't believe I kept missing something so simple.

    knowing that the native teensy library works, i'd say it is the problem.
    Thanks I was just using this library cause it has a couple things that in my mind made that library seem easier to use like limiting the max writes.

    it looks like 'int' is assumed 16 bits - and it is 32 bits on Teensy 3.x if these are byte offsets
    Could you carilfy that a bit more? The code was recalling integers back properly.

    - this would be so much easier and cleaner using arrays
    In my actual code all these variables have different names like 'lastShapeState' or 'AMPmodAMOUNTcontrol' and not just "float' with an increasing number. would arrays still make it cleaner? I'm kinda of new to arrays.

    Thanks everyone for the help.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,019
    I saw the int's miscounted and stopped tracking the indexes … but that is what I meant to look for when I posted this :
    … if all the math and numbers work out.

    Also not [perhaps directly] the issue … In the list of Read and write - it looks like 'int' is assumed 16 bits - and it is 32 bits on Teensy 3.x …
    Those int's will be poorly stored and over lap following items if ever written individually.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,398
    Quote Originally Posted by cfredisded View Post
    Could you carilfy that a bit more? The code was recalling integers back properly.
    The EEPROMex library appears to handle it as 16 bits. The code is somewhat sloppy with signed numbers, so if you want this code to work the same way on AVR chips, I'd recommend using only 0 to 32767.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •