Skip to content

A library for storing and managing strings in Arduino EEPROM memory.

License

Notifications You must be signed in to change notification settings

roncoa/StringEEPROM

Repository files navigation

StringEEPROM Library

GitHub release License: MIT GitHub stars GitHub forks

If you like StringEEPROM Library... buy me a beer donate

A library for efficiently storing and managing multiple strings in EEPROM memory for Arduino and ESP32 platforms.

Features

  • Store multiple strings in EEPROM with dynamic allocation
  • Command interface through Serial for interactive use
  • Configurable debug output
  • Configurable maximum number of strings
  • Memory efficient implementation using flash memory for strings
  • Compatible with both Arduino and ESP32 platforms

Installation

Using Arduino Library Manager (Recommended)

  1. Open Arduino IDE
  2. Go to Tools > Manage Libraries...
  3. Search for "StringEEPROM"
  4. Click Install

Manual Installation

  1. Download latest release as ZIP
  2. In Arduino IDE: Sketch > Include Library > Add .ZIP Library
  3. Select downloaded ZIP file
  4. Restart Arduino IDE

Storage Format

The library uses the following format to store strings in EEPROM:

[len1][data1][len2][data2]...[255]

where:

  • len = length byte (0-254)
  • data = string content
  • 255 = terminator marking the end of all data

Class Reference

Constructor

StringEEPROM()

Creates a new StringEEPROM instance with debug disabled and no limit on number of strings.

Configuration Methods

void setDebug(bool enable)

Enable or disable debug messages over Serial.

bool isDebugEnabled() const

Returns current debug status.

void setMaxStrings(int max)

Set maximum number of strings that can be stored. Use -1 for unlimited (default).

int getMaxStrings() const

Get current maximum strings limit.

Core Methods

void begin(uint32_t baudRate = 115200)

Initialize the library and Serial communication.

  • baudRate: Optional baud rate for Serial (default 115200)
bool writeString(uint8_t n, const char* data)

Write a string to the specified position.

  • n: Position (1-based index)
  • data: String to write
  • Returns: true if successful, false otherwise
int readString(uint8_t n, char* buffer, int maxLength)

Read a string from the specified position.

  • n: Position to read (1-based index)
  • buffer: Buffer to store the string
  • maxLength: Maximum length of the buffer
  • Returns: Length of string or -1 if not found
int check()

Check EEPROM content validity.

  • Returns: Number of strings stored, or -1 if EEPROM content is invalid
void init()

Initialize EEPROM by writing terminator at start.

Debug Methods

void debugPrint(const __FlashStringHelper* message)
void debugPrintln(const __FlashStringHelper* message)

Print debug message from flash memory, with or without newline.

void debugPrintValue(const __FlashStringHelper* message, int value)
void debugPrintlnValue(const __FlashStringHelper* message, int value)

Print debug message with integer value, with or without newline.

void debugPrintChar(const char* message)
void debugPrintlnChar(const char* message)

Print debug message from RAM, with or without newline.

Serial Interface Methods

void handleSerial()

Process Serial commands. Should be called in loop().

void showAllStrings()

Display all stored strings with their positions.

void printHelp()

Display available Serial commands.

Serial Commands

The library provides an interactive interface through Serial with the following commands:

  • N=string - Write "string" at position N (e.g., "1=Hello")
  • ? - Show all strings
  • # - Show number of strings
  • ! - Initialize EEPROM (requires confirmation)
  • h - Show help message

Example Usage

Basic usage:

#include <StringEEPROM.h>

StringEEPROM eeprom;

void setup() {
  // Optional: set maximum number of strings
  eeprom.setMaxStrings(10);
  
  // Optional: enable debug messages
  eeprom.setDebug(true);
  
  // Initialize with default baud rate (115200)
  eeprom.begin();
}

void loop() {
  // Handle Serial commands
  eeprom.handleSerial();
}

Memory Considerations

  • Each string requires length + 1 bytes of EEPROM space (length byte + string content)
  • The library uses flash memory for constant strings to save RAM
  • Maximum string length is 254 bytes due to length byte limitations
  • EEPROM space is used efficiently with dynamic allocation

Limitations

  • Maximum string length is 254 bytes
  • String positions are 1-based
  • String content cannot contain byte value 255 (used as terminator)
  • ESP32 virtual EEPROM requires commit() after changes

Platform Support

  • AVR architecture
  • ESP32 virtual EEPROM
  • Generic Arduino
  • Memory abstraction
  • Platform-specific optimizations

Contributing

  1. Fork repository
  2. Create feature branch
  3. Submit pull request

Support

  • GitHub Issues: Technical issues, bugs
  • GitHub Discussions: Questions, ideas
  • Email: [email protected]

License

MIT License - See LICENSE file

Version History

1.0.4

  • Bug fix

1.0.0

  • Initial release
  • Basic string storage
  • Serial interface
  • Debug system
  • ESP32 support

Author

[email protected]

About

A library for storing and managing strings in Arduino EEPROM memory.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published