Updated MCP23008 MCP23017 (markdown)

andrethomas 2018-08-11 22:46:12 +02:00
parent 07b8b380d0
commit 372d4a3911
1 changed files with 23 additions and 8 deletions

@ -16,12 +16,23 @@ You will need to pick an I2C address in either of the above scenario's but the d
![MCP23008 / MCP23017 I2C Address Map](https://github.com/andrethomas/images/blob/master/mcp230xx/i2c_address_map.png) ![MCP23008 / MCP23017 I2C Address Map](https://github.com/andrethomas/images/blob/master/mcp230xx/i2c_address_map.png)
Although the MCP230xx chips allow for both INPUT and OUTPUT, only INPUT is supported by the driver as the main intention is not to extend output but to provide additional inputs, more specifically - inputs which are 5V tolerant. The MCP23008/MCP23017 chips allow for both INPUT and OUTPUT - Most of the functionality of the driver is focused on INPUT mode - especially since they allow interrupt reporting and are 5V tolerant.
The driver is disabled by default in the Tasmota firmware but can be enabled by uncommenting the #define USE_MCP230xx line in the user_config.h file, or added to the user_config_override.h file if you are using that option. OUTPUT functionality is however available as pinmode 5 (Documented later in this Wiki) as an additional option for those who want to use the OUTPUT functionality using the sensor29 command at the expense of ~1Kbyte of flash.
The driver is disabled by default in the Tasmota firmware so the only way to gain its use would be to perform a manual compilation of your own firmware.
There are three different levels in which functionality may be enabled, in the following order, by uncommenting the relevant lines in the user_config.h file (or added to the user_config_override.h file if you are using that option.)
```
#define USE_MCP230xx // Enable INPUT mode (pinmode 1 through 4)
#define USE_MCP230xx_OUTPUT // Enable OUTPUT mode (pinmode 5)
#define USE_MCP230xx_DISPLAYOUTPUT // Display state of OUTPUT pins on main Tasmota web interface
```
The ESP8266 will automatically detect whether you have connected an MCP23008 (8 input) or MCP23017 (16 input) and will provide telemetry data in accordance with how the device was configured from within the Tasmota firmware. The ESP8266 will automatically detect whether you have connected an MCP23008 (8 input) or MCP23017 (16 input) and will provide telemetry data in accordance with how the device was configured from within the Tasmota firmware.
If OUTPUT is enabled, telemetry data for the current state of OUTPUT pins will also be provided by telemetry.
### Usage of the driver ### Usage of the driver
The MCP230xx chip (or breakout board) must be connected to the ESP8266 and the I2C pins must be configured for the module similar to the following: The MCP230xx chip (or breakout board) must be connected to the ESP8266 and the I2C pins must be configured for the module similar to the following:
@ -32,20 +43,18 @@ One that is complete you may want to confirm that the Tasmota firmware is findin
``I2Cscan`` ``I2Cscan``
You should see a response giving you an address within the range of the MCP23008/MCP23017 chip (0x20 through 0x27) which may look as follows You should see a response giving you an address within the range of the MCP23008/MCP23017 chip (0x20 through 0x27) which may look as follows
`MQT: stat/sonoff/RESULT = {"I2CScan":"Device(s) found at 0x20"}` `MQT: stat/sonoff/RESULT = {"I2CScan":"Device(s) found at 0x20"}`
If you do not find it, check your wiring and pin configuration. If you do not find it, check your wiring and pin configuration.
Configuration of MCP23008/MCP23017 by using sensor29 commands via serial, web console or MQTT messages The configuration of MCP23008/MCP23017 by using sensor29 commands via serial, web console or MQTT messages
This option only requires the main define to be uncommented prior to compilation This option only requires the main define to be uncommented prior to compilation
`#define USE_MCP230xx` `#define USE_MCP230xx`
The behaviour of all pins on the MCP23008/MCP23017 can be reset to a specific setting/mode globally to simplify the initial configuration as follows The behaviour of all pins on the MCP23008/MCP23017 can be reset to a specific setting/mode globally to simplify the initial configuration as follows
``` ```
@ -54,6 +63,7 @@ sensor29 reset1 // Reset all pins INPUT, no interrupt, no pull-up by default
sensor29 reset2 // Reset all pins INT on CHANGE, with pull-up enabled by default sensor29 reset2 // Reset all pins INT on CHANGE, with pull-up enabled by default
sensor29 reset3 // Reset all pins INT on LOW, with pull-up enabled by default sensor29 reset3 // Reset all pins INT on LOW, with pull-up enabled by default
sensor29 reset4 // Reset all pins INT on HIGH, with pull-up enabled by default sensor29 reset4 // Reset all pins INT on HIGH, with pull-up enabled by default
sensor29 reset5 // Reset all pins to OUTPUT mode (if enabled by #define USE_MCP230xx_OUTPUT)
``` ```
The command will respond with confirmation as follows: The command will respond with confirmation as follows:
@ -94,7 +104,7 @@ Where:
**pinmode** = The operational mode of the pin as follows: **pinmode** = The operational mode of the pin as follows:
**0** = Disabled **0** = Disabled (Deprecated, but will be default for previously unconfigured devices)
**1** = INPUT (Floating - only telemetry data will be sent according to Tasmota firmware configuration intervals **1** = INPUT (Floating - only telemetry data will be sent according to Tasmota firmware configuration intervals
@ -104,12 +114,16 @@ Where:
**4** = INPUT with INTERRUPT on CHANGE to **HIGH** (Will send an MQTT output on state change **only** from LOW to HIGH) **4** = INPUT with INTERRUPT on CHANGE to **HIGH** (Will send an MQTT output on state change **only** from LOW to HIGH)
**pinmode** = The operational mode of the pin as follows: **5** = OUTPUT (if enabled with #define USE_MCP230xx_OUTPUT)
**pullup** = The operational mode of the pin as follows:
**0** = Weak internal pull-up **DISABLED** **0** = Weak internal pull-up **DISABLED**
**1** = Weak internal pull-up **ENABLED** **1** = Weak internal pull-up **ENABLED**
Weak interal pull-up resistors are only enabled for pinmode 1 through 4 (being INPUT of nature) but the same parameter may also be used to set the default state of an OUTPUT pin on reset/power-up. If your device is configured to SAVE_STATE (setoption0 = 1) then this will be ignored during power-up/reset and the last known state of the pin will be applied during power-up/reset.
### IMPORTANT NOTICE ON USE OF INTERRUPTS ### IMPORTANT NOTICE ON USE OF INTERRUPTS
**_Only use interrupts on pins which are either explicitly pulled down GND or up to VCC externally as floating pins may cause unintended MQTT responses for pins which are floating. So unless your connected wire/device explicitly pulls the pin to GND or VCC only when conditions of an interrupt would be met it is recommended that you either do not set a pin for an interrupt mode or at least enable pull-up resistors for the unused pins with pullup = 1 when you perform your sensor29 pin,pinmode,pullup command._** **_Only use interrupts on pins which are either explicitly pulled down GND or up to VCC externally as floating pins may cause unintended MQTT responses for pins which are floating. So unless your connected wire/device explicitly pulls the pin to GND or VCC only when conditions of an interrupt would be met it is recommended that you either do not set a pin for an interrupt mode or at least enable pull-up resistors for the unused pins with pullup = 1 when you perform your sensor29 pin,pinmode,pullup command._**
@ -135,6 +149,7 @@ Each pin can be in the following modes:
* (2) Input (Int on Change) - Will respond with immediate telemetry, log and mqtt for the specific pin which has changed either from 0 to 1 or from 1 to 0 (Low to High or High to Low) * (2) Input (Int on Change) - Will respond with immediate telemetry, log and mqtt for the specific pin which has changed either from 0 to 1 or from 1 to 0 (Low to High or High to Low)
* (3) Input (Int on Low) - Will only respond with immediate telemetry, log and mqtt for the specific pin if the said pin was pulled down to ground (0, or Low) * (3) Input (Int on Low) - Will only respond with immediate telemetry, log and mqtt for the specific pin if the said pin was pulled down to ground (0, or Low)
* (4) Input (Int on High) - Will only respond with immediate telemetry, log and mqtt for the specific pin if the said pin was pulled high to VCC (3.3V or 5V), that would be 1 or High in binary for the specific pin. * (4) Input (Int on High) - Will only respond with immediate telemetry, log and mqtt for the specific pin if the said pin was pulled high to VCC (3.3V or 5V), that would be 1 or High in binary for the specific pin.
* (5) OUTPUT - State may be controlled with sensor29 commands as documented at the bottom of this Wiki
Default telemetry logging will occur for all pins as per the configured logging interval of the ESP8266 as configured in the Tasmota firmware options. The telemetry logging will push out to log and mqtt a JSON as follows: Default telemetry logging will occur for all pins as per the configured logging interval of the ESP8266 as configured in the Tasmota firmware options. The telemetry logging will push out to log and mqtt a JSON as follows:
``` ```
@ -204,4 +219,4 @@ sensor29 0,OFF // Turn pin 0 OFF/LOW/0
sensor29 0,T // Toggle the current state of pin 0 from HIGH to LOW or LOW to HIGH sensor29 0,T // Toggle the current state of pin 0 from HIGH to LOW or LOW to HIGH
``` ```
_Output support is marked to be included in the correct sections of the Wiki further up as soon as I find the time to do so_ Remember to adhere to the current limitations of OUTPUT pins when using the device for switching external devices such as LED's - Relay's will need additional circuitry as the MCP23008/MCP23017 cannot drive relays directly - That being said most readily available relay pc boards available from vendors are optically isolated from the input so these will work perfectly.