> ## Documentation Index
> Fetch the complete documentation index at: https://docs.t3gemstone.org/llms.txt
> Use this file to discover all available pages before exploring further.

# I2C

> Inter-Integrated Circuit

The [I2C (Inter-Integrated Circuit)](https://kureansiklopedi.com/en/detay/i2c-inter-integrated-circuit-afd6a)
protocol is a widely used communication protocol for data transmission between microcontrollers and other integrated
circuits. It is preferred in applications requiring low-speed data transmission, especially for communication
with sensors, memory modules, and other peripheral devices.

The Gemstone development board has one I2C (I2C1) output on its 40-pin header. External I2C devices can be
connected via these pins. Additionally, the Gemstone includes an ICM-20948 9-axis MEMS sensor and an HDC2010
temperature and humidity sensor, both communicating via I2C.

<Frame caption="I2C Pins">
  <img className="rounded-lg" src="https://mintcdn.com/t3gemstone-754bcb96/xXa-dgH9QsK0Txx6/images/o1-board/37-i2c.png?fit=max&auto=format&n=xXa-dgH9QsK0Txx6&q=85&s=89f6c8824f2f73cb71e7ea3a383ff5c4" width="1221" height="750" data-path="images/o1-board/37-i2c.png" />
</Frame>

### Using I2C

After connecting to the Gemstone operating system, install the `i2c-tools` package to write and read data
from I2C addresses.

```bash theme={"system"}
sudo apt install i2c-tools
```

To view the available I2C buses, run the `ls /dev/i2c-*` command.

<SnippetI2CDevices />

To view the addresses of devices connected to the `i2c-2` bus, run the following command:

```bash theme={"system"}
gemstone@t3-gem-o1:~$ sudo i2cdetect -y -r 2
#      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
# 00:                         -- -- -- -- -- -- -- -- 
# 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
# 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
# 30: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
# 40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
# 50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
# 60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
# 70: -- -- -- -- -- -- -- -- 
```

<Note>
  In the output above, `UU` indicates that an I2C device is present at that address and is being used by
  the system. `40` indicates that a device is present at that address. For example, while reading and writing
  operations cannot be performed at address 0x30, they can be performed at address 0x40.
</Note>

To read data from address `0x00` of the device connected to address `0x40` on the `i2c-2` bus,
run the following command:

```bash theme={"system"}
sudo i2cget -y 2 0x40 0x00
```

To write the value `0x80` to address `0x07` of the device connected to address `0x40` on the `i2c-2` bus, run
the following command:

```bash theme={"system"}
sudo i2cset -y 2 0x40 0x07 0x80
```

<Warning>
  The I2C addresses used in the examples (such as 0x40, 0x00, and 0x07) are for demonstration purposes only. The
  addresses of I2C devices in your applications may vary. It is important to consult the documentation of the
  devices you are using to determine the correct addresses.
</Warning>
