# 3: I2C (Inter-Integrated Circuit)

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$

$$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$

( \newcommand{\kernel}{\mathrm{null}\,}\) $$\newcommand{\range}{\mathrm{range}\,}$$

$$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$

$$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$

$$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$

$$\newcommand{\Span}{\mathrm{span}}$$

$$\newcommand{\id}{\mathrm{id}}$$

$$\newcommand{\Span}{\mathrm{span}}$$

$$\newcommand{\kernel}{\mathrm{null}\,}$$

$$\newcommand{\range}{\mathrm{range}\,}$$

$$\newcommand{\RealPart}{\mathrm{Re}}$$

$$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$

$$\newcommand{\Argument}{\mathrm{Arg}}$$

$$\newcommand{\norm}[1]{\| #1 \|}$$

$$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$

$$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\AA}{\unicode[.8,0]{x212B}}$$

$$\newcommand{\vectorA}[1]{\vec{#1}} % arrow$$

$$\newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow$$

$$\newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vectorC}[1]{\textbf{#1}}$$

$$\newcommand{\vectorD}[1]{\overrightarrow{#1}}$$

$$\newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}}$$

$$\newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}}$$

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$

## Inter-Integrated circuit

I2C _"Eye Squared C" is a synchronous serial bus that can hold up to 128 devices on a Raspberry Pi. It is used with many common sensors like the BME680 VOC sensor. This is a synchronized protocol using a clock signal that is controlled by the master to align the master and slave. You can have infinite "Masters" and up to 1008 "slaves", although the Raspberry Pi only uses 128 "slaves".  Standard mode is 100 kbps, high speed is 3.4 Mbps.  A typical I2C device has four pins

• SDA (Serial Data Pin)
• SCL (Serial Clock Pin)
• VIN (Voltage in, 3.3 V on Pi GPIO)
• GND (Ground)

So the I2C uses one line for data transmission and one for the clocksignal, with the other lines running power to a device, and serving as ground.

## Circuit Protocols

I2C data is transferred in frames.

• Start Condition:
• Data line switches voltage (high to low) which starts clock
• 7 to 10 bit address that is unique to each sensor. This identifies sensor the controller is communicating with.
• Always follows Start
• Identifies if controller is sending data to sensor or requesting it
• High voltage means data is requested from sensor
• Low voltage means data is sent to sensor
• ACK/NACK
• If address or data frame is successfully received it is acknowledged
• Always follows an address or data frame
• ACK bit must be received before next data frame is sent
• Data frame
• 8 bit data frame

This material is adpated from Circuit Basics and you should read their writeup for a more extensive description of I2C protocols

## Enabling I2C

### Command Line

In the command line type

sudo raspi-config


Choose:

1. Interfacing Options
2. I2C
3. Yes

## Utility Commands

i2cdetect -y 1


the -y flag disable interactive mode so you do don't have to wait for confirmation.  The 1 indicates you are scanning i2c bus #1.

## Resources

This page titled 3: I2C (Inter-Integrated Circuit) is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.