logo elektroda
logo elektroda
X
logo elektroda

[Solved] NodeMCU with PCF8574 crashes when starting with button pressed

canion 801 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18848980
    canion
    Level 10  
    Hello.
    I have a problem that I have been struggling with for a long time.
    I have 4 PCF8574 i2c modules hooked up under the NodeMCU.
    2 of them I use as output, another 2 as input.
    Everything works as expected when I connect the chip to USB with the buttons not pressed. The problem occurs when during power-up - connecting to USB - one of the buttons connected to the PCF input pins is pressed, i.e. shorted to GND, then the program does not respond at all.
    Input pins pulled up with 10k resistors to VCC. Status readout using an interrupt.

    I tried setting the ports as outputs first, but nothing helps.


    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #2 18849014
    khoam
    Level 42  
    canion wrote:
    I have 4 i2c modules plugged into the NodeMCU PCF8534 .
    .
    The PCF8574_ESP library used supports the PCF8574/PCF8574A/PCF8575. Typo, as the PCF8534 chip is also :) .

    How are the constructors PCF_switches and PCF_switches2 declared? How do you have the Wire set up? Check out this example:
    https://github.com/WereCatf/PCF8574_ESP/blob/.../examples/pcf8574_esp8266/pcf8574_esp8266.ino
    Add pcf8574.resetInterruptPin () in setup(), according to the example above.
  • #3 18849021
    canion
    Level 10  
    khoam wrote:
    canion wrote:
    I have 4 i2c modules plugged into the NodeMCU PCF8534 .
    .
    The PCF8574_ESP library used supports PCF8574/PCF8574A/PCF8575. Typo?

    How are the constructors PCF_switches and PCF_switches2 declared? How do you have the Wire set up? Check out this example:
    https://github.com/WereCatf/PCF8574_ESP/blob/.../examples/pcf8574_esp8266/pcf8574_esp8266.ino
    Add pcf8574.resetInterruptPin () in setup(), according to the example above.
    .

    Yes, this is a typo, already corrected:) .
    Code: C / C++
    Log in, to see the code
    .

    Added after 8 [minutes]: .

    Code after changes, problem still occurs.

    Code: C / C++
    Log in, to see the code
  • ADVERTISEMENT
  • #4 18849112
    khoam
    Level 42  
    PCF.setClock(100000L) should be after PCF.begin(D2, D1).
    Both resetInterruptPin() functions immediately after PCF_switches2.begin().
  • #5 18849114
    canion
    Level 10  
    I have noticed one thing.
    The most important thing is to connect the chip when the input ports are not shorted to GND - buttons off.
    Once the chip is powered up, I can short the pin to GND and reset the program in that state (with the RST button on the NodeMCU) and then the program works.
    Maybe this is a hardware problem? I've tried adding a capacitor to the power supply - didn't help, a delay (1000) at the very beginning of setup() so that the voltage can stabilise after connection - doesn't work either

    Added after 3 [minutes]:

    khoam wrote:
    PCF.setClock(100000L) should be after PCF.begin(D2, D1).
    Both resetInterruptPin() functions immediately after PCF_switches2.begin().


    After the changes - the problem still occurs
  • #6 18849120
    khoam
    Level 42  
    D3 is connected via a resistor to the power supply?
    I think that in attacheInterrupt() it is enough to use the FALLING parameter instead of CHANGE.
  • ADVERTISEMENT
  • #7 18849176
    canion
    Level 10  
    khoam wrote:
    D3 is connected via a resistor to the power supply?
    I think that in attacheInterrupt() it is enough to use the FALLING parameter instead of CHANGE.


    D3 obviously pulled up to VCC.
    changing the response to the falling edge also had no effect
  • Helpful post
    #8 18849181
    khoam
    Level 42  
    Try a test like this: comment out attacheInterrupt() in setup() and see if the problem occurs i.e. if the program "hangs".

    Added after 3 [minutes]: .

    EDIT:
    The cause is probably very simple. D3 if it is in a low state while the ESP is booting, the chip will not boot :)
    https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
    You need to select a different pin.
  • ADVERTISEMENT
  • #9 18849224
    canion
    Level 10  
    khoam wrote:
    Try a test like this: comment out attacheInterrupt() in setup() and see if the problem occurs i.e. if the program "hangs".

    Added after 3 [minutes]: .

    EDIT:
    The cause is probably very simple. D3 if it is in a low state while the ESP is booting, the chip will not boot :)
    https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
    You need to select a different pin.


    And I feel silly:) Thanks. Problem solved
  • #10 18849226
    canion
    Level 10  
    khoam wrote:
    Try a test like this: comment out attacheInterrupt() in setup() and see if the problem occurs i.e. if the program "hangs".

    Added after 3 [minutes]: .

    EDIT:
    The cause is probably very simple. D3 if it is in a low state while the ESP is booting, the chip will not boot :)
    https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
    You need to select a different pin.


    And I feel silly:) Thanks. Problem solved

    Added after 1 [minute]:

    Changing the INT pin from D3 to D5 solved the problem.

Topic summary

The discussion revolves around an issue with a NodeMCU setup using four PCF8574 I2C modules, where the program fails to respond if a button connected to the input pins is pressed during power-up. The user initially set up the input pins with pull-up resistors and attempted various configurations, including adjusting the interrupt handling and adding delays. The problem was identified as being related to the state of the interrupt pin (D3) during boot; when D3 is low at startup, the ESP fails to boot correctly. The solution was to change the interrupt pin from D3 to D5, which resolved the issue.
Summary generated by the language model.
ADVERTISEMENT