Hauptinhalt

Connect to I2C Device Using Arduino Explorer App

R2026b

I2C (Inter-Integrated Circuit) is a two-wire serial communication protocol that uses a serial data line (SDA) and a serial clock line (SCL) to exchange data between a controller and one or more peripheral devices. I2C is commonly used to communicate with sensors, EEPROMs, displays, and other peripherals that support addressable register-based communication.

Use the Arduino Explorer app to configure an I2C communication interface and read and write data to I2C devices connected to your Arduino hardware. Before you begin, ensure that your Arduino board is connected and detected in the app. If the board is not already connected, see Set Up and Connect to Arduino and Arduino-compatible Boards Using Arduino Explorer.

Set Up I2C Device

To configure an I2C communication interface on your Arduino board:

  1. Click the I2C icon in the Configure section of the app toolstrip. The Set Up I2C Device window opens.

  2. Select the I2C Bus if your board supports more than one bus.

  3. Specify the I2C Address of the peripheral device you want to communicate with. If you do not know the address of your device, click Scan I2C to scan the I2C bus and detect all available device addresses.

  4. Set the Bit Rate (bits/s) to match the communication speed supported by your device.

  5. Click OK to apply the settings.

Set Up I2C Device dialog box showing I2C bus selection, SDA and SCL pin assignments, I2C address, Scan I2C button, and bit rate settings

After you configure the I2C device, the Pin Explorer displays a row for the I2C communication interface, showing the assigned SDA and SCL pins.

Pin Explorer showing I2C pins SCL1 and SDA1 grouped in a single row with the Pin Configuration panel displaying Read and Write tabs

Configure Read and Write for I2C

Use the Pin Configuration panel corresponding to the I2C interface to perform one of these operations.

  • Read or write

    Pin configuration set to read and write

  • Register read or write

    Pin configuration set to read and write register

    The value you specify in the Precision parameter must match the size of the device register.

    Once you set the parameter values (in the read and register read operations), click Read. The Read Value column corresponding to the I2C row in the Pin Explorer pane displays the value as read by the SDA pin or the register address.

    Once you set the parameter values (in the write and register write operations), edit the corresponding cell in the Write Value column and enter the value to be written to the SDA pin or the register address.

  • Perform continuous reading of data.

    Select the Read Continuously option and then click Start Reading to continuously read data from the I2C device. The value displayed in Read Value column changes continuously based on the data being read. Click Stop Reading to stop reading the data from the I2C device.

Read data continuously

For more information on recording and visualizing data, see Visualize and Record Data from Arduino Pins Using Arduino Explorer App.

See Also

Topics