B4R Code Snippet EEPROM Clear

SubName: Set all EEPROM bytes to zero.
Description: This example illustrates how to set of all of the bytes to zero (0), initialising them to hold new information, using the EEPROM.WriteBytes function.

Please take note that the EEPROM apparently has a 100,000 Read/Write life cycle, give or take.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
   
    Public EEP As EEPROM
    Public LEDPin As Pin
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
   
    Delay(2000)
    Log("AppStart")
   
    Log("Size: ", EEP.Size, " bytes")
    For i = 0 To EEP.Size
        EEP.WriteBytes(Array As Byte(0), i)
        Log(i)
    Next
   
    LEDPin.Initialize(2, LEDPin.MODE_OUTPUT) '2 for WeMos, 13 for Arduino
    LEDPin.DigitalWrite(False)
End Sub

Tags: EEPROM, Clear, Memory
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Hey, oops, I thought that I had pasted the correct code. I had 5 or 6 different versions of it but the Delay(1500) should have made me double check it, the code I actually use has Delay(2000).

Anyway, I had so many version (while testing) as I was trying to figure out why writing to EEPROM causes the 'Log Screen' to miss the first few lines of code including Log("AppStart"). Without Delay(2000) before it. I'm just presuming that somehow it slows down how long the IDE 'Logs Screen' takes to connect to Serial1.stream before it displays the Logs @Erel.

All the code still executes and works perfect on the devices, but it appears that the B4R 'Log Screen' does takes longer to connect, thus missing the first few Log(blah blah blah...) in my code, adding Delay gives the 'Log Screen' and Serial1.stream time to do their thing.
 
Last edited:
Top