/* http://www.bristolwatch.com/arduino/arduino_24lc08.htm Arduino with a 24LC08 Serial EEPROM Lewis Loflin lewis@bvu.net This code comes with no warranty. */ #include // specify use of Wire.h library. #define SW0 12 // digital pin for switch connected to ground. // address in 24LC08. values from 000 hex to 3FF hex. int position_pointer = 0x3f0; void setup() { pinMode(SW0, INPUT); digitalWrite(SW0, HIGH); // turn on internal pull up Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // setup serial for output // send test message "Arduino" Wire.beginTransmission(0x50); // connect to 24LC08 device address Wire.write(position_pointer); // beginning address within EEPROM Wire.write("Arduino"); Wire.endTransmission(); } void loop() { while (digitalRead(SW0) == 1) { } // wait here until switch is pushed. Wire.beginTransmission(0x50); // link to 24LC08 Wire.write(position_pointer); // must act as a position pointer Wire.endTransmission(); Wire.requestFrom(0x50, 7); // request 7 bytes from slave device 24LC08 // below will loop until 7 bytes are received. while (Wire.available()) // slave may send less than requested { byte c = Wire.read(); // receive a byte as character Serial.print(c); // print the character } Serial.print("\n"); // next line delay(1000); // wait one second. }