The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


RPi::EEPROM::AT24C32 - Read and write to the AT24C32 based EEPROM ICs


Read and write data to the AT24C32-based EEPROM Integrated Circuits.

Currently, only the actual AT24C32 that has 4096 8-bit address locations (0-4095).

It'll work for the AT24C64 unit as well, but only half of the address space will be available. I'll update this after I get one of these units.


    use RPi::EEPROM::AT24C32;

    my $eeprom = RPi::EEPROM::AT24C32->new(
        device  => '/dev/i2c-1', # optional, default
        address => 0x57,         # optional, default
        delay   => 1             # optional, default

    # write to, and read from a block of EEPROM addresses in a loop

    my $value = 1;

    for my $memory_address (200..225){
        $eeprom->write($memory_address, $value);
        print $eeprom->read($memory_address) . "\n";



Instantiates a new RPi::EEPROM::AT24C32 object, initializes the i2c bus, and returns the object.


All parameters are sent in as a hash.

    device => '/dev/i2c-1'

Optional, String. The name of the i2c bus device to use. Defaults to /dev/i2c-1.

    address => 0x57

Optional, Integer. The i2c address of the EEPROM device. Defaults to 0x57.

    delay => 1

Optional, Integer. Due to issues on the Raspberry Pi's i2c ability to "clock stretch" the bus, with some devices a slight delay (milliseconds) must be used between write cycles. This parameter is the multiplier for said write cycle timer.

If you're frequently getting write or I/O errors when performing multiple write/reads in succession, bump this number up.

Defaults to 1.


Performs a single-byte read of the EEPROM storage from the specified memory location.



Mandatory, Integer. Valid values are 0-4095.

Return: The byte value located within the specified EEPROM memory register.

write($addr, $byte)

Writes a single 8-bit byte of data to the EEPROM memory address specified.



Mandatory, Integer. Valid values are 0-4095.


Mandatory, Integer. Valid values are 0-255.

Return: 0 on success, -1 on failure.


These are methods that aren't normally required for the use of this software, but may be handy for troubleshooting or future purposes.


Sets/gets the file descriptor that our i2c initialization routine assigned to us.



Optional, Integer: This is set internally, and it would be very unwise to set it manually at any other time.

Return: The file descriptor (integer) that the ioctl() initialization routine assigned us.



Ensures that the EEPROM memory register address supplied as a parameter is within limits.


For write calls, ensures that the data byte supplied is within valid limits.


Steve Bertrand, <steveb at>


Copyright 2019 Steve Bertrand.

GPL version 2+ (due to using modified GPL'd code).

1; # End of RPi::EEPROM::AT24C32