How to use eeprom on arduino nano

I am using Arduino 2.2.1 to program arduino nano IOT33 board.
I want to write / read / update work on bytes, using EEPROM.

My offending code line is:
#include <eeprom.h>
Here is the compile error message: eeprom.h: No such file or directory

So , I have copied EEPROM.h files from an internet source into an EEPROM Folder contained within a libraries folder .
However, a new error <avr/eeprom.h> has occurred.

Any thoughts? This has to be something simple I have missed but I have looked almost everywhere.

The code you have is likely for the classic Nano which uses an atmega328p processor (AVR).

You have an arduino nano IOT33 board. it’s a different architecture and there is no eeprom but you can simulate it using the flash memory

I believe this applies to a Nano iot33

2 Likes

Thank you very much for replying. CMaglie's program helped me to compile IOT33 successfully. I will try to test it on school-days.

I have new trouble.
I adapt cmaglie's library. First, it do well.
However, after I wrote program several times, Icould not write, and iot33 was found from ArduinoIDE.
Please tell me why not.

#include <FlashAsEEPROM.h>

void setup() {
  Serial.begin(9600);
}

void loop() {
  char key;

  if (Serial.available()) {
    key = Serial.read();
    Serial.write("trigger: ");
    Serial.write(key);

    if (key == 'w') {
      // EEPROM write
      Serial.println(" EEPROM write :");

      unsigned int i = 0;

      for (int num = 0; num <= 1022; num++) {

        Serial.println();
        Serial.print(" write num = ");
        Serial.println(num);
        unsigned int num0 = int(num / 255);
        unsigned int num1 = num % 255;

        EEPROM.write(i, num0);
        EEPROM.write(i + 1, num1);

        // ==== debug ====
        uint8_t value0 = EEPROM.read(i);
        uint8_t value1 = EEPROM.read(i + 1);

        unsigned int value = value0 * 255 + value1;

        // read data print out
        Serial.print(" debug i = ");
        Serial.println(i);
        Serial.println(value0);
        Serial.println(value1);
        Serial.print(" debug value = ");
        Serial.println(value);
        // ==== debug ====

        i += 2; // Increment i for the next pair of values
      }

      EEPROM.commit();
      Serial.println("write complete!");
    } else if (key == 'r') {
      // EEPROM read
      Serial.println("EEPROM read:");

      unsigned int i = 0;
      for (int num = 0; num <= 1022; num++) {
        uint8_t value0 = EEPROM.read(i);
        uint8_t value1 = EEPROM.read(i + 1);

        unsigned int value = value0 * 255 + value1;

        Serial.println();
        // print out
        Serial.print(" i = ");
        Serial.println(i);
        Serial.println(value0);
        Serial.println(value1);
        Serial.println(value);

        i += 2; // Increment i for the next pair of values
      }
    } else {
      Serial.println("command! 'w' = writem, 'r' = read ");
    }

    // buffer read
    while (Serial.available()) {
      Serial.read();
    }
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.