Updated MCP23008 MCP23017 (markdown)

andrethomas 2018-08-18 16:26:03 +02:00
parent 01bab009bc
commit 616bf1d6d3
1 changed files with 55 additions and 17 deletions

@ -76,18 +76,28 @@ sensor29 reset5 // Reset all pins to OUTPUT mode (if enabled by #define USE_MC
The command will respond with confirmation as follows:
`MQT: stat/sonoff/RESULT = {"Sensor29-D99":{"MODE":pinmode,"PULL-UP":pullup,"STATE":99}}`
`MQT: stat/sonoff/RESULT = {"Sensor29_D99":{"MODE":1,"PULL_UP":"OFF","INT_MODE":"DISABLED","STATE":""}}`
Pin and State is reported as 99 because it was implemented accross all pins.
Mode should correspond with the reset pinmode option used.
Internal pull-up resistors on the MCP23008/MCP23017 is disabled by default for pin mode 0 whilst enabled by default for pin modes 2 through 4.
Internal pull-up resistors on the MCP23008/MCP23017 is disabled by default for pin mode 1 whilst enabled by default for pin modes 2 through 4 (because they are interrupt enabled pins and we do not want them bouncing up and down - you may disable the internal pull-up on these pins using the sensor29 commands described below if you are biasing them externally)
INT_MODE is disabled for pin mode 1 and pinmodes 5 and 6 (OUTPUT modes) since interrupts are not available for these pin modes.
If specific pins require specific configuration after this command has been issued the pins may individually be configured using:
`sensor29 pin,pinmode,pullup`
For pinmode's 2 through 4 you may also pass an additional optional parameter to set the required behaviour of interrupts on a particular pin, for example:
`sensor29 pin,pinmode,pullup,intmode`
Where intmode can be 0 through 3
If no parameter value for intmode is passed, it will default to intmode 0.
The usage of the above is described in more detail further in this page.
The configuration of a specific pin may be queried using command:
@ -96,16 +106,22 @@ The configuration of a specific pin may be queried using command:
Will report as follows:
`MQT: stat/sonoff/RESULT = {"Sensor29-D0":{"MODE":1,"PULL-UP":0,"STATE":0}}`
`MQT: stat/sonoff/RESULT = {"Sensor29_D0":{"MODE":1,"PULL_UP":"OFF","INT_MODE":"DISABLED","STATE":"ON"}}`
Confirming that the pin is in pinmode 1 and that the pull-up resistor is not enabled.
The current STATE of the pin 0(LOW) or 1(HIGH) as at the time the command is issued is also reported.
INT_MODE indicates the interrupt mode for pins which are interrupt enabled (pinmode 2 through 4) - In the example above it is disabled for pin mode 1 (INPUT without INTERRUPT)
The current STATE of the pin as ON or OFF is reported as at the time the command is issued is also reported.
The format for sending configuration messages for individual pins via serial, web console or MQTT messages are as follows:
`sensor29 pin,pinmode,pullup`
Or optionally specifying the desired interrupt mode for pin modes 2 through 4 using:
`sensor29 pin,pinmode,pullup,intmode`
Where:
**pin** = The digital IO pin on the MCP230xx chip as a numeric e.g. 0 through 7 for MCP23008 and 0 through 15 for the MCP23017
@ -130,6 +146,14 @@ Where:
**1** = Weak internal pull-up **ENABLED**
**intmode** = Optionally specify the interrupt reporting mode as follows - defaults to 0 if not specified
**0** = Immediate interrupt report using TELEMETRY and EVENT
**1** = Immediate EVENT only (no telemetry reported)
**2** = Immediate TELEMETRY only (no EVENT caused)
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
@ -150,22 +174,15 @@ Examples of some pin configuration options:
Pull-up resistor support is valid for all modes from 1 through 4
Each pin can be in the following modes:
* (0) Disabled - Will not report anything in telemetry, log or to mqtt
* (1) Input - Will report to telemetry, log or mqtt based on telemetry interval settings in Tasmota
* (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)
* (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:
```
tele/sonoff/SENSOR = {"Time":"2018-06-30T18:31:49","MCP230XX":{"D0":0, "D1":0, "D2":0, "D3":0, "D4":0, "D5":0, "D6":0, "D7":0 }}
tele/sonoff/SENSOR = {"Time":"2018-08-18T16:13:47","MCP230XX": "D0":0,"D1":0,"D2":1,"D3":0,"D4":0,"D5":0,"D6":0,"D7":1}}
```
Again, this will depend on whether an MCP23008 or MCP23017 is used insofar that the number of pins/bits reported will be 8 (0 to 7) or 16 (0 to 15) respectively.
### INTERRUPT MODES AND USAGE
Interrupts will report for individual pins as and when the conditions which were configured are met and will look something like this:
Interrupt message on HIGH for input pin 0
@ -201,6 +218,14 @@ In the example above the rule would respond to an interrupt of HIGH on pin 0 of
See the Wiki on [Using Rules](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules) for more information on how this can be helpful to your requirements.
If you require only one of the two reporting methods you may use the sensor29 command to configure the interrupt behaviour according to your requirements using command:
`sensor29 pin,pinmode,pullup,intmode`
The intmode parameter is optional for pin modes 2 through 4 (those that support interrupts) and may be configured according to the table below depending on your requirements:
![MCP23008 / MCP23017 Interrupt Modes](https://github.com/andrethomas/images/blob/master/mcp230xx/interrupt_modes_v1.PNG)
_Finally, keep in mind that the MCP23008/MCP23017 chip will only store the last interrupt registered in the interrupt register and capture register - Because the interrupt register is only checked every 50 milliseconds by the Tasmota firmware you may experience missed interrupts if your incoming signals fluctuate/change faster than 20 times per second._
@ -211,13 +236,22 @@ Enable OUTPUT support by uncommenting the following compiler directive to your u
`#define USE_MCP230xx_OUTPUT`
This will extend the sensor29 command enabling pinmode 5 for output, for example:
This will extend the sensor29 command enabling pinmode 5 and 6 (inverted) for output, for example:
```
sensor29 0,5,0 // Configure pin 0 as OUTPUT and default to LOW(0) on reset/power-up
sensor29 0,5,1 // Configure pin 0 as OUTPUT and default to HIGH(1) on reset/power-up
sensor29 0,5,0 // Configure pin 0 as OUTPUT and default to OFF on reset/power-up
sensor29 0,5,1 // Configure pin 0 as OUTPUT and default to ON on reset/power-up
sensor29 0,6,0 // Configure pin 0 as INVERTED OUTPUT and default to OFF on reset/power-up
sensor29 0,6,1 // Configure pin 0 as INVERTED OUTPUT and default to ON on reset/power-up
```
Confirmation will be sent using MQT, for example:
```
MQT: stat/sonoff/RESULT = {"Sensor29_D2":{"MODE":5,"PULL_UP":"OFF","INT_MODE":"DISABLED","STATE":"OFF"}}
```
The only difference between pinmode 5 and pinmode 6 is that pinmode 5 will result in normal output state, i.e. pin will be LOW when OFF whereas pinmode 6 will cause the pin to be HIGH when OFF. This is useful when using relays which have inverted inputs.
If SAVE_STATE / setoption0 is enabled in your firmware configuration then the last known state of the pin will be used on power-up/reset thereby ignoring the pull-up parameter in the commands above.
To change the state of an output pin you may use:
@ -227,4 +261,8 @@ 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
```
Telemetry data is provided for pins which are enabled for output. For example, if pin 0 was enabled for OUTPUT the following additional telemetry message will be sent by MQTT at the same time as the normal telemetry interval occurs which reports the current states of pins.
`MQT: tele/sonoff/SENSOR = {"Time":"2018-08-18T16:24:50","MCP230_OUT": {"OUT_D2":"OFF","END":1}}`
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.