PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
Moderators: grovkillen, Stuntteam, TD-er
PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
All, I finally got around to test some relays with ESP. I found a hardware setup that works (its able to drive at least two relay modules), but now I have a new issue. But I'm only using ESPEasy for a week now so maybe I'm missing something.
The PCF8574 input I use seems to blank every other bit whenever I pull another high.
pcfgpio,1,1
pcfgpio,2,1
Works, except that pin 1 is off again after the second command. I learned a bit about when to need devices/tasks config (ie. for MQTT), and I control it from Home Assistant. But I cannot find any previous issue on the output register behaviour, or anyone else that wanted multiple PCFGPIO turned on.. maybe I'm missing something. It seems to me it only needs to shift in a bit, at the current value for the 8bit output register, and then write that back. But it writes a blank byte with selected PCFGPIO 1 bit every time it looks like.
This can not be the way to use an 8bit IO expander to control a 2, 4 or 8 relay module?
The PCF8574 input I use seems to blank every other bit whenever I pull another high.
pcfgpio,1,1
pcfgpio,2,1
Works, except that pin 1 is off again after the second command. I learned a bit about when to need devices/tasks config (ie. for MQTT), and I control it from Home Assistant. But I cannot find any previous issue on the output register behaviour, or anyone else that wanted multiple PCFGPIO turned on.. maybe I'm missing something. It seems to me it only needs to shift in a bit, at the current value for the 8bit output register, and then write that back. But it writes a blank byte with selected PCFGPIO 1 bit every time it looks like.
This can not be the way to use an 8bit IO expander to control a 2, 4 or 8 relay module?
Last edited by berend on 17 Feb 2018, 06:08, edited 2 times in total.
Re: ESPEasy and multiple Switch inputs (pcf8574 8bit IO expander)
I've a similiar device running with two PCF8574, using one as 8 buttons input, the other as a driver for 8 LEDs.
It works nicely using an older ESPMega-dev12.
Sure your PCF's run on different I²C-addresses?
It works nicely using an older ESPMega-dev12.
Sure your PCF's run on different I²C-addresses?
Regards
Shardan
Shardan
Re: ESPEasy and multiple Switch inputs (pcf8574 8bit IO expander)
I'm talking about only one PCF8574. And it works okay just at the first address (or port as the letscontrolit config calls it)
Im a bit confused about the "Switch Input" part of the config, because I want to use the IO expander as output. I guess its supposed to be a feedback device for an actual physical switch. But its the best match from the list. (R120 firmware otoh)
But in any case I don't need to configure a device to call the PCFGPIO commands. Just the I2C setup.
@Shardan so you can lit several LED as expected? Can you tell me which firmware version to use?
I tried the latest v2.0 pre-release yesterday but while creating this PCF8574 setup it weirdly stopped responding and I had to reflash to get that module online again. So I've stuck with R120 link I found via a github issue.
Updates:
I wish I had a MCP23017 to test with. But 16bit is way too much anyway.
I removed the ULN2803 and put a LED bar in in place. Same behaviour, previous LED is turned of. I thought maybe the PCF got reset.. But can't imagine this is a power issue.
Im a bit confused about the "Switch Input" part of the config, because I want to use the IO expander as output. I guess its supposed to be a feedback device for an actual physical switch. But its the best match from the list. (R120 firmware otoh)
But in any case I don't need to configure a device to call the PCFGPIO commands. Just the I2C setup.
@Shardan so you can lit several LED as expected? Can you tell me which firmware version to use?
I tried the latest v2.0 pre-release yesterday but while creating this PCF8574 setup it weirdly stopped responding and I had to reflash to get that module online again. So I've stuck with R120 link I found via a github issue.
Updates:
I wish I had a MCP23017 to test with. But 16bit is way too much anyway.
I removed the ULN2803 and put a LED bar in in place. Same behaviour, previous LED is turned of. I thought maybe the PCF got reset.. But can't imagine this is a power issue.
- budman1758
- Normal user
- Posts: 301
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: ESPEasy and multiple Switch inputs (pcf8574 8bit IO expander)
To use the PCF8574 as an output device it is not necessary to configure a task. It will "just work" without having to configure it at all. The only time you need to configure a task is when you are using it as an input. I was under the impression that you had to configure at least 1 pin as an input just to "enable" the chip but I recently found that was not necessary. As long as the ESP module can "see" it in the I2C scan page it should work.
There is also an issue with the PCF8574 that when mixing inputs and outputs on the same chip. When an output is triggered the inputs will stop functioning correctly. See this issue on Github.
https://github.com/letscontrolit/ESPEasy/issues/702
Also keep in mind that when attempting to drive LEDs or relays you must use a low signal because the PCF8574 limits the high output to a very low strength signal. Less than 1ma. See this link for a datasheet.
http://www.ti.com/lit/ds/symlink/pcf8574.pdf
Hope this helps.
There is also an issue with the PCF8574 that when mixing inputs and outputs on the same chip. When an output is triggered the inputs will stop functioning correctly. See this issue on Github.
https://github.com/letscontrolit/ESPEasy/issues/702
Also keep in mind that when attempting to drive LEDs or relays you must use a low signal because the PCF8574 limits the high output to a very low strength signal. Less than 1ma. See this link for a datasheet.
http://www.ti.com/lit/ds/symlink/pcf8574.pdf
Hope this helps.
"The glass is twice as big as it needs to be".
Re: ESPEasy and multiple Switch inputs (pcf8574 8bit IO expander)
Thanks. Its late now but I will review the power setup better. I have this feeling maybe the problem is there.
You're correct about the tasks. I still confused it a bit, but that's also because I *do* need them for the MQTT pub/sub mechanism. Just not to turn the PCFGPIO on or off, that just works with r120 at least.
You're correct about the tasks. I still confused it a bit, but that's also because I *do* need them for the MQTT pub/sub mechanism. Just not to turn the PCFGPIO on or off, that just works with r120 at least.
Re: PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
Hooked up an arduino clone, there's nothing wrong with the circuit or chips. Can set any of the 256 8bit combinations with the wire library.
Also looked up the sourcecode and it seems okay to me. I give up. I cannot get it to work with any firmware. I can use one expander IC per relay, and still enjoy I2C and multiple devices on an ESP-01 but its not what I was aiming for.
Code: Select all
#include <Wire.h>
uint8_t address = 0x20;
byte portval = 1;
int _error;
void setup() {
Serial.begin(115200);
Serial.println("\nTEST PCF8574\n");
Wire.begin();
}
void loop() {
if (Serial.available() > 0) {
String newb = Serial.readString();
portval = newb.toInt();
Wire.beginTransmission(address);
Wire.write(portval);
_error = Wire.endTransmission();
Serial.print("Ret:");
Serial.print(_error);
Serial.print(" ");
Serial.println(portval, HEX);
}
}
Re: PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
I think I have seen this behaviour, but not 100% certain I remember right. Two questions :
Did you by any chance leave the address bits floating( meaning not pulled to gnd/vcc but nc)?
Are you exceeding the current specs of the pcf?
Did you by any chance leave the address bits floating( meaning not pulled to gnd/vcc but nc)?
Are you exceeding the current specs of the pcf?
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
- budman1758
- Normal user
- Posts: 301
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
There is currently a pull request with a fix for this issue.
https://github.com/letscontrolit/ESPEasy/pull/897
https://github.com/letscontrolit/ESPEasy/pull/897
"The glass is twice as big as it needs to be".
Re: PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
Simply grounded the address pins for address 0x20 iirc. And as for the spec exceeding, I tested with a few LEDs and using arduino Wire so I think that eliminates hardware problems.
I see about the PR. Very nice. I'll wait out a bit, maybe try a custom build later bc I see there's a Travis build too.
NB. I know the PCF8574 cannot drive much, it'll struggle to drive one transistor/opto circuit on the relay boards. I'm going to try to use ULN2803 in between.
I see about the PR. Very nice. I'll wait out a bit, maybe try a custom build later bc I see there's a Travis build too.
NB. I know the PCF8574 cannot drive much, it'll struggle to drive one transistor/opto circuit on the relay boards. I'm going to try to use ULN2803 in between.
- budman1758
- Normal user
- Posts: 301
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
The pull request has been merged into the Mega builds. You can use it right now.
The chip can sink up to 50ma per pin. Plenty for most relays I would think.
That is of course if the relay triggers on with a ground signal.
The chip can sink up to 50ma per pin. Plenty for most relays I would think.
That is of course if the relay triggers on with a ground signal.
"The glass is twice as big as it needs to be".
Re: PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
Thats great!
50mA sounds like a lot, 8 pins makes that 400mA. I have to doubt that. I'm gleaning -1mA high and 20mA low typical, -4/100 max.
Tried controlling a typical sino Songle dual-relay directly from a PCF (SMT) a long time ago and it didn't want to really.
50mA sounds like a lot, 8 pins makes that 400mA. I have to doubt that. I'm gleaning -1mA high and 20mA low typical, -4/100 max.
Tried controlling a typical sino Songle dual-relay directly from a PCF (SMT) a long time ago and it didn't want to really.
Re: PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
Due to the datasheet of the PCF8574 the max. current of one IO pin is 25 mA.
The maximum Vss/Vdd current of the chip is 100 mA.
So the summarized current of all IO pins should not exceed 100 mA.
Regards
Shardan
The maximum Vss/Vdd current of the chip is 100 mA.
So the summarized current of all IO pins should not exceed 100 mA.
Regards
Shardan
Regards
Shardan
Shardan
Re: PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
Can someone tell me the difference between dev/test/normal? Its not in the release notes.
https://github.com/letscontrolit/ESPEasy/releases
Edit: well, looks like I need to dig a little deeper.
Tested yesterdays' v2.0-20180221 (normal) (on an ESP-12E this time) and still the same behaviour, it holds only one LED on. Tried three different PCF8574 chips.
Edit2: or not, seems v2.0 doesn't have the PR 897 changes yet.
https://github.com/letscontrolit/ESPEasy/pull/897/files
https://github.com/letscontrolit/ESPEas ... CF8574.ino
https://github.com/letscontrolit/ESPEas ... CF8574.ino
https://github.com/letscontrolit/ESPEasy/releases
Edit: well, looks like I need to dig a little deeper.
Tested yesterdays' v2.0-20180221 (normal) (on an ESP-12E this time) and still the same behaviour, it holds only one LED on. Tried three different PCF8574 chips.
Edit2: or not, seems v2.0 doesn't have the PR 897 changes yet.
https://github.com/letscontrolit/ESPEasy/pull/897/files
https://github.com/letscontrolit/ESPEas ... CF8574.ino
https://github.com/letscontrolit/ESPEas ... CF8574.ino
Re: PCFGPIO command resets every other pin (pcf8574 8bit IO expander)
The changes are not on v2.0 yet, but I tried my own mega build and it was fine. Thanks!
Going to have a look-see now if the 512k build still goes too.
Going to have a look-see now if the 512k build still goes too.
Who is online
Users browsing this forum: Ahrefs [Bot] and 97 guests