From 03b98dc320b0dbbeed7b5441000d991b5808c3f0 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Sun, 1 Nov 2020 11:56:29 +1300 Subject: [PATCH] Update PN532 docs to add I2C (#798) --- components/binary_sensor/pn532.rst | 33 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/components/binary_sensor/pn532.rst b/components/binary_sensor/pn532.rst index 51e9667c7..5dd40eb61 100644 --- a/components/binary_sensor/pn532.rst +++ b/components/binary_sensor/pn532.rst @@ -13,7 +13,7 @@ Component/Hub The ``pn532`` component allows you to use PN532 NFC/RFID controllers (`datasheet `__, `Adafruit `__) -with ESPHome. This component is a global hub that establishes the connection to the PN532 via :ref:`SPI ` and +with ESPHome. This component is a global hub that establishes the connection to the PN532 via :ref:`SPI ` or :ref:`I^2C ` and outputs its data. Using the :ref:`PN532 binary sensors ` you can then create individual binary sensors that track if an NFC/RFID tag is currently detected by the PN532. @@ -23,22 +23,22 @@ create individual binary sensors that track if an NFC/RFID tag is currently dete See :ref:`pn532-setting_up_tags` for information on how to setup individual binary sensors for this component. -As the communication with the PN532 is done using SPI for this integration, you need to set the two switches on -the board to the SPI mode (usually by setting the first one to OFF and the second one to ON). Additionally, you need -to have an :ref:`SPI bus ` in your configuration with both the **miso_pin** and **mosi_pin** set. +The PN532 can be configured to use either the SPI **or** I^2C protocol for data communication. +You will need to switch the dip switches located on the module according to the table printed on the board. +SPI is usually switch 1 OFF and switch 2 ON and I^2C is usually switch 1 ON and switch 2 OFF. +You will need to have the :ref:`SPI Bus ` or the :ref:`I^2C Bus ` configured depending on your choice. .. code-block:: yaml - # Example configuration entry - spi: - clk_pin: D0 - miso_pin: D1 - mosi_pin: D2 - - pn532: + # Example configuration for SPI (choose which one!) + pn532_spi: cs_pin: D3 update_interval: 1s + # Example configuration for I2C (choose which one!) + pn532_i2c: + update_interval: 1s + binary_sensor: - platform: pn532 uid: 74-10-37-94 @@ -47,7 +47,7 @@ to have an :ref:`SPI bus ` in your configuration with both the **miso_pin** Configuration variables: ************************ -- **cs_pin** (**Required**, :ref:`Pin Schema `): The pin on the ESP that the chip select line +- **cs_pin** (**Required for SPI**, :ref:`Pin Schema `): The pin on the ESP that the chip select line is connected to. - **update_interval** (*Optional*, :ref:`config-time`): The duration of each scan on the PN532. This affects the duration that the individual binary sensors stay active when they're found. @@ -56,6 +56,8 @@ Configuration variables: when a tag is read. See :ref:`pn532-on_tag`. - **spi_id** (*Optional*, :ref:`config-id`): Manually specify the ID of the :ref:`SPI Component ` if you want to use multiple SPI buses. +- **i2c_id** (*Optional*, :ref:`config-id`): Manually specify the ID of the :ref:`I^2C Component ` if you want + to use multiple I^2C buses. - **id** (*Optional*, :ref:`config-id`): Manually specify the ID for this component. .. figure:: images/pn532-spi.jpg @@ -69,9 +71,8 @@ Configuration variables: ``on_tag`` ---------- -This automation will be triggered when the PN532 module responds with a tag. Please note that this -can be called quite often (with an interval of ``update_interval``) as it's triggered repeatedly -if the tag is re-read many times. +This automation will be triggered when the PN532 module responds with a tag. This will only be triggered +if the tag is changed or goes away for one cycle of ``update_interval``. The parameter ``x`` this trigger provides is of type ``std::string`` and is the tag UID in the format ``74-10-37-94``. The configuration below will for example publish the tag ID on the MQTT topic ``pn532/tag``. @@ -113,7 +114,7 @@ unique id (``uid``) is currently being detected by the PN532 or not. miso_pin: D1 mosi_pin: D2 - pn532: + pn532_spi: cs_pin: D3 update_interval: 1s