Program 24LC01B EEPROM from Aduino

I’ve been messing around with the Arduino, systematically plugging it into whatever I have around and trying to get it to work. My wife calls this “nerding-out time.” I can’t totally disagree with her. I digress…

I had some 1Kbit 24LC01B EEPROMs lying around and I couldn’t figure out how to program them. I finally busted out my scope and got it to work. I still don’t quite understand how it does work because I don’t see how the read bit ever gets set, but I’m not going to look a gift horse in the mouth.

Here’s the Arduino code in case I can save anyone else any time.

#include <Wire.h>

/* 
    Wire Hookup for 24LC01B 1 K-bit (128 byte) EEPROM
    Don't forget to read the datasheet!
    http://ww1.microchip.com/downloads/en/devicedoc/21711c.pdf
    1,2,3 are not internally connected.
    It's okay to leave them open.
    
              -----
            -|1   8|- Arduino +5V
            -|2   7|- Jumper to +5V for Write Protect
            -|3   6|- Arduino Pin Analog-5
Arduino Gnd -|4   5|- Arduino Pin Analog-4
              -----
              
    I put a 2.2K pull-up resistor between pin 5 and 8
    because the datasheet suggested it, but I'm not entirely
    sure it's necessary as I think the Wire library enables
    the Arduino's internal pull-ups.  Don't quote me on that,
    though.

    You're supposed to be able to write 8 bytes at
    a time, but I had trouble with that.  Try 4 at
    a time with a delay and then push it up until
    your results degrade.
    
    It seems like you can read as many as you like.
    
    We're going to write Hello World!
    
Data       |H|e|l|l|o| |W|o|r|l|d|!|
           |-|-|-|-|-|-|-|-|-|-|-|-|
Address    |0|1|2|3|4|5|6|7|8|9|1|1|
           | | | | | | | | | | |0|1|
*/

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
  Serial.begin(9600);
}


void loop()
{
  Serial.println("Writing...");
  
  Wire.beginTransmission(0x50); // This is the 24LC01B device address
  Wire.send(0x0);               // Start writing at address 0
  Wire.send("Hell");            // Send 4 bytes
  Wire.endTransmission();       
  delay(10);                    // Without a short delay, the EEPROM is still
                                // writing when you start to write the next block
                                // Feel free to experiment with the delay length
  
  Wire.beginTransmission(0x50);
  Wire.send(0x4);               // Write next four bytes starting at address 4
  Wire.send("o Wo");
  Wire.endTransmission();     
  delay(10);
  

  Wire.beginTransmission(0x50);
  Wire.send(0x8);               // Write last four bytes starting at address 8
  Wire.send("rld!");
  Wire.endTransmission();     
  delay(10);

  Serial.println("Reading...");

  Wire.beginTransmission(0x50); // Now we're going to read it back
  Wire.send(0x0);               // Sending address 0, so it knows where we'll want
  Wire.endTransmission();       // to read from

  Wire.requestFrom(0x50,12);    // Start new transmission and keep reading for 12 bytes
  while(Wire.available())    
  { 
    char c = Wire.receive();    // Read a byte and write it out to the Serial port
    Serial.print(c);         
  } 
  Serial.println();

  delay(5000);
}

Great! I have a couple 24LC256 and they work the same. With the arduino wire library, I can’t tel when the write cycle completes since I can’t find how to receive acknowledge bit from slave through arduino wire lib. Do you know how? Without it, I’ll have to put a long wait if I want to be safe.