Skip to main content
Chemistry LibreTexts

13.4: I2C

  • Page ID
    471388
  • \( \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.

    clipboard_e3b6c388721a4a4ac926db9a134444b67.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

     

    • Start Condition:
      • Data line switches voltage (high to low) which starts clock
    • Address:
      • 7 to 10 bit address that is unique to each sensor. This identifies sensor the controller is communicating with.
      • Always follows Start
    • Read/Write
      • Always follows address
      • 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

     

     

    clipboard_e41f2d055b16227e8a668b632348f414e.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

     

    Raspberry Pi Configuration

     

    clipboard_ec2df7dbb858f24a5acd779ad6f6de01c.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

     

     

     

    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. 

    clipboard_eee061d8fef751cc4051cbc4e72c3cebc.pngFigure \(\PageIndex{1}\): The addresses are base 16 (hexadecimal), and so 5a is registry 90 in decimal. (Belford, cc0.0)

     

     

    Resources

     

     

     


    This page titled 13.4: I2C is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?