{"id":28394944,"url":"https://github.com/alexiii/eevar","last_synced_at":"2025-06-27T01:31:21.550Z","repository":{"id":123487531,"uuid":"224163631","full_name":"AlexIII/EEvar","owner":"AlexIII","description":"EEPROM Arduino library","archived":false,"fork":false,"pushed_at":"2024-07-02T18:59:15.000Z","size":24,"stargazers_count":16,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T06:31:44.758Z","etag":null,"topics":["arduino","arduino-library","avr","eeprom"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexIII.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-11-26T10:24:37.000Z","updated_at":"2025-04-09T10:15:05.000Z","dependencies_parsed_at":"2023-10-20T16:34:58.789Z","dependency_job_id":null,"html_url":"https://github.com/AlexIII/EEvar","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/AlexIII/EEvar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIII%2FEEvar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIII%2FEEvar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIII%2FEEvar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIII%2FEEvar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexIII","download_url":"https://codeload.github.com/AlexIII/EEvar/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIII%2FEEvar/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262172377,"owners_count":23269996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","arduino-library","avr","eeprom"],"created_at":"2025-05-31T19:09:19.268Z","updated_at":"2025-06-27T01:31:21.539Z","avatar_url":"https://github.com/AlexIII.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EEvar - EEPROM Arduino library\n\nSimple and lightweight Arduino library that allows you to save variables in the EEPROM memory. \n\nNo need to keep track of the address, offset or size of the data you want to store in the EEPROM.\nAfter saving the variable to the EEPROM its value gets restored on the power-up or CPU reset.\n\nWorks with any POD (`bool`, `int`, `float`, custom structs, etc.) and `String`. \n\n## Usage\n\n### Example\n\n#### Simple types and `String`\n\n```c++\n#include \"EEvar.h\"\n\nconst EEstore\u003cfloat\u003e eeFloat(25.8);       //allocate EEPROM for storing float \n                                          //and save value 25.8 to it on the first start\n\nconst EEstore\u003cint\u003e eeInt(-3685);          //for storing int\n\nconst EEstring eeString(20, \"initial\");   //for storing String (20 chars max)\n\nvoid setup() {\n  Serial.begin(115200);\n\n  //check if it's CPU first start\n  Serial.println(\n      EEPROMallocator::isFirstStart()\n          ? F(\"First start\") \n          : F(\"Not first start\")\n  );\n\n  //float\n  float v1;\n  eeFloat \u003e\u003e v1;      //load from eeprom to v1\n  Serial.println(v1);\n  //Serial.println(eeFloat.get()); //same as above\n  v1 = 99.2;\n  eeFloat \u003c\u003c v1;      //save v1 to eeprom\n\n  //int\n  Serial.println(eeInt.get());\n  eeInt \u003c\u003c 56;\n\n  //String\n  String v4;\n  eeString \u003e\u003e v4;\n  Serial.println(v4);\n  v4 = \"long string, not gonna fit\";\n  eeString \u003c\u003c v4;\n  \n}\n\nvoid loop() {\n}\n\n```\n\n#### Structures\n\n```c++\n#include \"EEvar.h\"\n\nstruct Config {\t\t\t\t//structure that we want to store\n  bool isOn = false;\n  char str[10] = \"abc\";\n};\n\nconst EEstore\u003cConfig\u003e eeStruct((Config())); //store without buffering\n\nEEvar\u003cConfig\u003e configVar((Config())); //store with buffering\n\nvoid setup() {\n  Serial.begin(115200);\n\n  //without buffering\n  Config conf;\n  eeStruct \u003e\u003e conf;\t\t\t//load from EEPROM to conf\n  Serial.print(conf.isOn);\n  Serial.print(\" \");\n  Serial.println(conf.str);\n  conf.isOn = true;\t\t\t//modify conf\n  strncpy(conf.str, \"hello\", sizeof(v3.str));\n  eeStruct \u003c\u003c conf;\t\t\t//save conf to EEPROM\n\n  //with buffering\n  Serial.println();\n  Serial.print(configVar-\u003eisOn);\n  Serial.print(\" \");\n  Serial.println(configVar-\u003estr);\n  configVar-\u003eisOn = true;\t\t\t//modify configVar\n  strncpy(configVar-\u003estr, \"hello\", sizeof(Config::str));\n  configVar.save();\t\t\t\t\t//save configVar to EEPROM\n  \n}\n\nvoid loop() {\n}\n\n```\n\n#### Simulate first start\n\nIf you want to reset all the saved variables in the EEPROM to their default values\non the next CPU reset (right after you flash the sketch), \nre-define `EE_TEST_VAL` to some different value __before__ including the library.\n\n```c++\n#define EE_TEST_VAL 0x315A    // library default is 0x3159\n#include \"EEvar.h\"\n\n```\n\nTry to choose \"more random\" values, never use something like `0xFFFF`, `0`, `1`, etc. or the first start detection may fail.\n`EEPROMallocator::isFirstStart()` will also return `true` after `EE_TEST_VAL` is re-defined.\n\n\n\n### Important notes\n\n- All `EEstore\u003cT\u003e`, `EEstring`, `EEvar\u003cT\u003e` must be global or static (or in another way ensure a stable order of instantiations).\n- Changing order of created EEPROM variables or adding new ones not at the end will corrupt the saved data.\n- Type `T` can only be POD (`bool`, `int`, `float`, custom structs, etc.). `T` cannot be `String` and cannot have `String` as its member. Use `EEstring` for storing a `String`.\n- On ESP8266 the library will allocate 512 additional bytes for the flash page buffer. Using `EEvar\u003cT\u003e` will actually store your data __twice__ in the RAM.\n- Don't forget about EEPROM/FLASH wear-out! This library does NOT mitigate this problem.\n\n### API\n\nThere's three types available in the library: \n\n- `EEstore\u003cT\u003e` - does not create buffer of your type `T`. Use for:\n  - simple types like `bool`, `int`, `float`;\n  - large structures, that you don't need to have in the RAM all the time.\n- `EEvar\u003cT\u003e` - creates buffer of your type `T`. Use for:\n  - values that you read frequently;\n  - complex structures.\n-  `EEstring` - use for storing `String` type. Does not buffer your string. Preserves string length, but no more than maxLen (first constructor argument).\n\nComparison table:\n\n|                                     | `EEstore\u003cT\u003e` | `EEvar\u003cT\u003e`    | `EEstring`         |\n| ----------------------------------- | ------------ | ------------- | -------------------------- |\n| Can store                           | POD          | POD           | String of length \u003c= maxLen |\n| Buffered                            | no           | yes           | no                         |\n| Easy struct-field access (via `-\u003e`) | no           | yes           | -                          |\n| Size in RAM, bytes                  | 2            | 2 + sizeof(T) | 2                          |\n\n\n\nAll available classes and their methods:\n\n```c++\nclass EEPROMallocator {\n  static void* alloc(const uint16_t sz);    //allocate EEPROM bytes (used by the library, don't call it directly)\n  static uint16_t busy();                   //counter of busy EEPROM, bytes\n  static uint16_t free();                   //counter of free EEPROM, bytes\n  static bool isFirstStart();               //check if it's CPU's first start\n};\n\ntemplate\u003ctypename T\u003e\nclass EEstore {\n  EEstore();\n  EEstore(const T\u0026 initial);\n  const EEstore\u0026 operator\u003c\u003c(const T\u0026 val) const;  //save val to EEPROM\n  const EEstore\u0026 operator\u003e\u003e(T\u0026 val) const;        //load to val from EEPROM\n  const T get() const;                            //read from EEPROM\n};\n\nclass EEstring {\n  EEstring(const uint16_t maxLen, const char* initial = \"\");\n  const EEstring\u0026 operator\u003c\u003c(const char* val) const;      //save char string to EEPROM\n  const EEstring\u0026 operator\u003c\u003c(const String\u0026 val) const;    //save String to EEPROM\n  const EEstring\u0026 operator\u003e\u003e(String\u0026 val) const;          //load to String val from EEPROM\n  const String get() const;                               //read from EEPROM\n};\n\ntemplate\u003ctypename T\u003e\nclass EEvar {\n  EEvar(const T\u0026 initial);\n  T\u0026 operator*();               //access struct\n  const T\u0026 operator*();         //access struct\n  T* operator-\u003e();              //access struct\n  const T* operator-\u003e() const;  //access struct\n  void save() const;            //save to EEPROM\n  void load();                  //load from EEPROM\n};\n```\n\n\n\n## Supported architectures\n\n- AVR-based Arduino: Uno, Nano, Mini Pro, 2560, etc.\n- ESP8266\n- Teensy 4.x\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexiii%2Feevar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexiii%2Feevar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexiii%2Feevar/lists"}