B4R Tutorial EEPROM Utility

Discussion in 'B4R Tutorials' started by Bangdido, Apr 25, 2018.

  1. Bangdido

    Bangdido Member Licensed User

    Excuse my English, it's not my native language
    I am not an arduino expert, I want to contribute with this code.

    one of the main problems is to save information, one of this is in the EEPROM memory,
    I made this little code that simplifies the way to save or read the information in the native data of B4R
    Since the EEPROM memory has a lifetime of writings (100,000 times, I'm not sure), so this code validates if the stored data is the same, and avoids writing, otherwise write the new data.

    this works like arrays accesed by index, This needs rEEPROM and rRandomAccess libraries.

    This simple code shows the main advantages
    Private Sub AppStart

    Log("EEPROM Test")
    Log("EEPROM Memory Size:", uEEPROM.Size)  ' This shows the amount of EEPROM memory
        Log("Is Configured:", uEEPROM.IsConfigured)  ' This is to test if something was stored in the EEPROM
        uEEPROM.ShowOptimalSettings  ' This shows the optimal size of MaxElements supported by the memory
    End Sub
    we will explain by parts
    what does this mean?
    you can make changes to the uEEPROM.bas file to use the memory according to your device, for example runnign in Arduino MEGA 2560:

    --- Optimal Settings ---
    EEPROM.Size =4096 bytes, StringSize=35 (34+1 byte of length) at Line #4
    MaxElements must be 113 at Line #3
    Using this configuration would occupy 4068 of 4096 bytes

    This mean, you can store 113 elements of Boolean, Int, UInt, Long, uLong, Double and Strings (with 35 bytes of Lengtht)

    #3 Public const MaxElements As Int = 113
    #4 Public const StringSize As Int = 35

    To write you need use something like
    uEEPROM.Write{TYPE}( Index, Value)

    Write Example:
    for i = 0 to 4
    False)           ' Boolean
     uEEPROM.WriteInt(i, -32768 + i)       ' Integer
     uEEPROM.WriteUInt(i, i)               ' Uint
     uEEPROM.WriteLong(i, -2147483648 + i) ' Long
     uEEPROM.WriteULong(i, i)              ' ULong
     uEEPROM.WriteDouble(i, -i-0.5)        ' Double
     uEEPROM.WriteString(i, JoinStrings(Array As String("Some String Here", i)))
    Read Example:
    Log("Boolean at Index 2: ",uEEPROM.ReadBool(2))
    Log("String at Index 10:", uEEPROM.ReadString(10))
    I hope you find it useful

    This is the version 1.2 with a fix for String Offset in uEEPROM.bas

    Attached Files:

    Last edited: Apr 26, 2018
    XorAndOr and Erel like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice