2018-06-01 18:10:00 +02:00
|
|
|
.. _i2c:
|
|
|
|
|
2018-05-13 11:37:02 +02:00
|
|
|
I²C Bus
|
|
|
|
=======
|
|
|
|
|
2018-11-14 22:12:27 +01:00
|
|
|
.. seo::
|
2019-02-24 12:26:26 +01:00
|
|
|
:description: Instructions for setting up the I²C bus to communicate with 2-wire devices in ESPHome
|
2018-11-19 18:32:16 +01:00
|
|
|
:image: i2c.png
|
2018-11-14 22:12:27 +01:00
|
|
|
:keywords: i2c, iic, bus
|
|
|
|
|
2019-02-24 12:26:26 +01:00
|
|
|
This component sets up the I²C bus for your ESP32 or ESP8266. In order for those components
|
|
|
|
to work correctly, you need to define the I²C bus in your configuration. Please note the ESP
|
2019-01-09 14:43:18 +01:00
|
|
|
will enable its internal 10kΩ pullup resistors for these pins, so you usually don't need to
|
|
|
|
put on external ones.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
.. code-block:: yaml
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
# Example configuration entry
|
|
|
|
i2c:
|
|
|
|
sda: 21
|
|
|
|
scl: 22
|
2019-02-27 09:32:13 +01:00
|
|
|
scan: True
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
Configuration variables:
|
2018-08-24 22:44:01 +02:00
|
|
|
------------------------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
2019-02-24 12:26:26 +01:00
|
|
|
- **sda** (*Optional*, :ref:`config-pin`): The pin for the data line of the I²C bus.
|
2018-06-01 18:10:00 +02:00
|
|
|
Defaults to the default of your board (usually GPIO21 for ESP32 and GPIO4 for ESP8266).
|
2019-02-24 12:26:26 +01:00
|
|
|
- **scl** (*Optional*, :ref:`config-pin`): The pin for the clock line of the I²C bus.
|
2018-06-01 18:10:00 +02:00
|
|
|
Defaults to the default of your board (usually GPIO22 for ESP32 and
|
|
|
|
GPIO5 for ESP8266).
|
2019-02-24 12:26:26 +01:00
|
|
|
- **scan** (*Optional*, boolean): If ESPHome should do a search of the I²C address space on startup.
|
2019-02-27 09:32:13 +01:00
|
|
|
Defaults to ``False``.
|
2019-02-24 12:26:26 +01:00
|
|
|
- **frequency** (*Optional*, float): Set the frequency the I²C bus should operate on.
|
|
|
|
Defaults to ``50kHz``. Values are ``50kHz``, ``100kHz``, ``200kHz``, ... ``800kHz``
|
2018-05-14 21:15:49 +02:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2019-02-24 12:26:26 +01:00
|
|
|
If you're using the ESP32 and I²C frequently is showing errors in the logs, try with the latest
|
2019-02-16 23:25:23 +01:00
|
|
|
version of the Arduino framework. See :ref:`esphome-arduino_version` for information on how to do this.
|
2018-06-01 18:10:00 +02:00
|
|
|
|
|
|
|
See Also
|
|
|
|
--------
|
|
|
|
|
2019-02-07 13:54:45 +01:00
|
|
|
- :apiref:`i2c_component.h`
|
|
|
|
- :ghedit:`Edit`
|
2018-10-12 16:33:22 +02:00
|
|
|
|
|
|
|
.. disqus::
|