How to read and write from AT24C256B eeprom with Arduino Nano

AT24C256B_bb


#include <Wire.h>
#include "AT24C256.h"

AT24C256 g_eeprom(0x50);

void printContents() {
  int eeaddress = 0;
  byte value;

  while (true) {
    value = g_eeprom.read(eeaddress++);
    if ((value == 0xFF) || (eeaddress == 32768)) {
      Serial.println();
      break;
    }
    Serial.print((char)value);
  }
}

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

void loop() {
  while (Serial.available()) {
    int i, m;
    String data = Serial.readStringUntil('\n');

    for (i = 0, m = data.length(); i < m; ++i) {
      g_eeprom.write(i, data[i]);
      Serial.print("writing ");
      Serial.print(data[i]);
      Serial.print(" in ");
      Serial.println(i);
    }
    g_eeprom.write(i, 0xFF);
    printContents();
  }
  delay(1);
}

raspberry pi rtl8188eu


cat /proc/version
gcc --version | grep gcc
# check for compiler version
sudo apt-get install -y gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
sudo apt-get install libncurses5-dev
sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update
rpi-source
git clone https://github.com/lwfinger/rtl8188eu.git
cd rtl8188eu
make all
sudo make install