EEPROM Data 27)(28 EEPROM Clock
I2C pins in BCM mode are: 2, 3
I2C pins in WiringPi are: 8, 9
- I2C - Inter Integrated Circuit -
The Raspberry Pi's I2C pins are an extremely useful way to talk to many different types of external peripheral; from the MCP23017 digital IO expander, to a connected ATmega.
The I2C pins include a fixed 1.8 kohms pull-up resistor to 3.3v. This means they are not suitable for use as general purpose IO where a pull-up is not required.
You can verify the address of connected I2C peripherals with a simple one-liner:
sudo apt-get install i2c-tools
sudo i2cdetect -y 1
You can then access I2C from Python using the smbus library:
DEVICE_BUS = 1
DEVICE_ADDR = 0x15
bus = smbus.SMBus(DEVICE_BUS)
bus.write_byte_data(DEVICE_ADDR, 0x00, 0x01)
Pins 27 and 28 (ID_SD (EEPROM SDA2) and ID_SC (EEPROM SCL2)) are also I2C. There are used by the Pi for internal functions, and also some HAT boards.
- RevEng communication -
This communication is similar to the SPI, but it uses only two wire for communication – SDA/SCL. Each device is accessed by using their internal i2c address. Here we will use an I2C EEPROM as an example and see how we can read and write to the memory. i2ctools comes as a part of the Linux package, so no need to install anything.
To find the address of your i2c slave device.
i2cdetect -y 1
Now use a tool called as eeprog to read and write to the EEPROM.
tar -xvf eeprog-0.7.6-tear5.tar.gz eeprog-0.7.6-tear12/
sudo make install
To write data to it:
echo “hello” | ./eeprog -f -16 -w 0 -t 5 /dev/i2c-1 0x50
-w is the offset
-t is write delay
To read data from it
./eeprog -x /dev/i2c-1 0x50 -16 -r 0x00:0x10