Update for HSU (Serial interface)

Andre Thomas 2019-02-08 21:24:20 +02:00
parent 40873fc5e6
commit 29680065a4
1 changed files with 19 additions and 20 deletions

@ -1,10 +1,10 @@
### PN532 I2C Driver for Sonoff-Tasmota
### PN532 HSU Driver for Sonoff-Tasmota
The PN532 is a highly integrated transceiver module for contactless communication at 13.56 MHz based on the 80C51 microcontroller core.
The datasheet for the PN532 chip is available here: [https://www.nxp.com/docs/en/nxp/data-sheets/PN532_C1.pdf](https://www.nxp.com/docs/en/nxp/data-sheets/PN532_C1.pdf)
Please note that although the datasheet mentions that the PN532 can be used on SPI, I2C and HSUART that only the I2C interface is implemented in the Sonoff-Tasmota driver.
Please note that although the datasheet mentions that the PN532 can be used on SPI, I2C and HSUART that only the HSU interface is implemented in the Sonoff-Tasmota driver.
### PN532 Breakout boards
@ -12,7 +12,7 @@ Since the PN532 chip itself is surface mount and requires some external componen
![PN532 Breakout Board Module](https://raw.githubusercontent.com/andrethomas/images/master/pn532/PN532_nfc_module.PNG)
Please make sure the breakout board you order has the I2C pins (SDA and SCL) broken out as it will be very difficult to add them manually - Usually they have them but for good measure just make sure.
Please make sure the breakout board you order has the HSU pins (Serial TX and RX) broken out as it will be very difficult to add them manually - Usually they have them but for good measure just make sure.
### PN532 Configuration in Sonoff-Tasmota
@ -22,21 +22,21 @@ To enable it prior to compilation you need to uncomment the following one or mor
Please note that the DATA field functionality has proven to work on some cards/tags but not all cards/tags - Please see Issue https://github.com/arendst/Sonoff-Tasmota/issues/4941 for more information about this.
`#define USE_PN532_I2C`
`#define USE_PN532_HSU`
`#define USE_PN532_DATA_FUNCTION`
`#define USE_PN532_CAUSE_EVENTS`
Please note that `USE_PN532_DATA_FUNCTIONS` are experimental - See Issue https://github.com/arendst/Sonoff-Tasmota/issues/4941 for more information as we are still researching the limitations of this usage because it seems not all cards are supported by this driver yet.
The latter is only necessary if you need to perform actions on the local device using rules. If you only plan to handle the resulting scanned information on your home automation software then you do not need to uncomment `#define USE_PN532_CAUSE_EVENTS` as it has no use if you are not going to take an action on the device itself.
Once you have compiled and uploaded your new firmware you will need to configure the usual (such as your wifi configuration and MQTT server configuration etc) and when complete proceed to enable I2C pins for SDA and SCL on your ESP8266 device.
Please note that `USE_PN532_DATA_FUNCTIONS` are experimental - See Issue https://github.com/arendst/Sonoff-Tasmota/issues/4941 for more information as we are still researching the limitations of this usage because it seems not all cards are supported by this driver and/or the PN532 module.
Once you have compiled and uploaded your new firmware you will need to configure the usual (such as your wifi configuration and MQTT server configuration etc) and when complete proceed to enable GPIO pins for PN532 Tx and PN532 Rx on your ESP8266 device.
For this example we will configure it using D1 and D2 as follows - you can follow the buttons pressed from left to right in the image below:
![PN532 - Configuring I2C pins on Sonoff-Tasmota](https://raw.githubusercontent.com/andrethomas/images/master/pn532/PN532_Configuration.PNG)
![PN532 Software Configuration](https://raw.githubusercontent.com/andrethomas/images/master/pn532/PN532_Configuration_HSU.PNG)
The module will reboot when you save this configuration.
@ -44,19 +44,18 @@ The module will reboot when you save this configuration.
First make sure that your device is powered off and that all power connections are removed.
As mentioned earlier the PN532 breakout boards usually have pins broken out for all three protocols supported by the PN532 but we are only interested in the I2C interface as that is all the driver currently supports.
As mentioned earlier the PN532 breakout boards usually have pins broken out for all three protocols supported by the PN532 but we are only interested in the HSU interface as that is all the driver currently supports.
For this reason breakout boards have either micro dip switches as shown in the image below, or they have pads on the PC board which you need to bridge out with solder to select which mode the PN532 will operate in.
![PN532 Hardware Config and Connection](https://raw.githubusercontent.com/andrethomas/images/master/pn532/pn532_nfc_i2c_config.png)
![HSU Dipswitch Setting](https://raw.githubusercontent.com/andrethomas/images/master/pn532/pn532_nfc_hsu_config.PNG)
After selecting the correct protocol mode and connecting the PN532 to the I2C pins on the ESP8266 board you can power it up and the PN532 should be detected automatically.
After selecting the correct protocol mode and connecting the HSU TX/TX pins of the PN532 to the pins you configured on your ESP8266 board you can power it up and the PN532 should be detected automatically.
To rule out any issues you may perform a `I2cScan` command from the console (web or serial) as follows to ensure that the device is detected on the I2C bus.
During start-up the following information should be visible in your console output:
```
17:14:29 CMD: i2cscan
17:14:29 MQT: stat/sonoff/RESULT = {"I2CScan":"Device(s) found at 0x24"}
00:00:00 NFC: PN532 NFC Reader detected (V1.6)
```
If the device was not found please check your wiring and configuration and confirm that everything is as it should be.
@ -77,7 +76,7 @@ The UID of the card/tag is reported and any text stored in BLOCK 1 of a Mifare C
The content of the `DATA` on BLOCK 1 of a Mifare Classic card can be set as follows
`Sensor40 S,I_LOVE_TASMOTA`
`Sensor40 S,ILOVETASMOTA`
Once executed the very next card/tag that is presented to the reader will be programmed accordingly and the data will be retained on the card/tag until either changed or erased.
@ -96,7 +95,7 @@ When a card is presented to the PN532 under normal operating conditions up to 3
The first is the immediate telemetry generated which looks as follows
```
18:31:39 MQT: tele/sonoff/SENSOR = {"Time":"2019-01-10T18:31:39","PN532":{"UID":"94D8FC5F", "DATA":"I_LOVE_TASMOTA"}}
18:31:39 MQT: tele/sonoff/SENSOR = {"Time":"2019-01-10T18:31:39","PN532":{"UID":"94D8FC5F", "DATA":"ILOVETASMOTA"}}
```
Since this is an immediate telemetry generation as opposed to the sensor data you would normally be expected to be presented when the telemetry period occurs, this telemetry data is not directly usable on the device itself. It is generated and immediately transmitted over MQTT and the purpose of this is so that immediate action may be taken by any home automation software you are using with the data obtained from the card/tag as opposed to waiting for the telemetry period to expire and be sent with normal telemetry data.
@ -109,7 +108,7 @@ Example rule for responding to a specific UID on the device when a card/tag matc
Example output/result:
```
18:39:20 MQT: tele/sonoff/SENSOR = {"Time":"2019-01-10T18:39:20","PN532":{"UID":"94D8FC5F", "DATA":"I_LOVE_TASMOTA"}}
18:39:20 MQT: tele/sonoff/SENSOR = {"Time":"2019-01-10T18:39:20","PN532":{"UID":"94D8FC5F", "DATA":"ILOVETASMOTA"}}
18:39:20 MQT: stat/sonoff/RESULT = {"Event":"Done"}
18:39:20 RUL: EVENT#PN532_UID=94D8FC5F performs "power on"
18:39:20 MQT: stat/sonoff/RESULT = {"POWER":"ON"}
@ -119,13 +118,13 @@ Example output/result:
Example rule for responding to a specific DATA content that was previously programmed to one or more cards using the `Sensor40 S,xxxx` command
`on EVENT#PN532_DATA=I_LOVE_TASMOTA do power on endon`
`on EVENT#PN532_DATA=ILOVETASMOTA do power on endon`
```
18:41:12 MQT: tele/sonoff/SENSOR = {"Time":"2019-01-10T18:41:12","PN532":{"UID":"94D8FC5F", "DATA":"I_LOVE_TASMOTA"}}
18:41:12 MQT: tele/sonoff/SENSOR = {"Time":"2019-01-10T18:41:12","PN532":{"UID":"94D8FC5F", "DATA":"ILOVETASMOTA"}}
18:41:13 MQT: stat/sonoff/RESULT = {"Event":"Done"}
18:41:13 MQT: stat/sonoff/RESULT = {"Event":"Done"}
18:41:13 RUL: EVENT#PN532_DATA=I_LOVE_TASMOTA performs "power on"
18:41:13 RUL: EVENT#PN532_DATA=ILOVETASMOTA performs "power on"
18:41:13 MQT: stat/sonoff/RESULT = {"POWER":"ON"}
18:41:13 MQT: stat/sonoff/POWER = ON
```