logo elektroda
logo elektroda
X
logo elektroda

[Solved] Why is the button for the ESP8266 not working properly and how to fix it?

pier 681 11
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18188427
    pier
    Level 24  
    Welcome.

    A seemingly simple issue but it doesn't want to work.
    It needs a button for the esp8266. Button connected under D6, gpio12, pulled up with 10k resistor to +3.3V. The button short circuits to ground.
    I tried a few different configurations because I thought the problem was there but it's always the same, even though the button is not pressed the program responds as if it was.
    There are no short circuits on the board.

    What could be the cause of this?

    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #2 18188512
    oskar777

    Level 26  
    Have you tried simply giving
    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #3 18188542
    khoam
    Level 42  
    pier wrote:
    but it is always the same, even though the button is not pressed the program reacts as if it were.
    .
    The variable 'temp' refers to the temperature value, or the state of the button? You have this variable declared twice in the code, once globally and once in the loop().
    Code: C / C++
    Log in, to see the code
    .
    Code: C / C++
    Log in, to see the code
  • #4 18188594
    pier
    Level 24  
    oskar777 wrote:
    Tried to give simply
    Code: C / C++
    Log in, to see the code
    .


    I have tried in various ways always the same result. It also sends a zero on the serial.
    I don't know how it can see zero if it is physically pulled up with a resistor to plus.

    khoam wrote:
    .
    pier wrote:
    but it is always the same, even though the button is not pressed the program reacts as if it is.

    The variable 'temp' refers to the temperature value, or the state of the button? You have this variable declared twice in the code, once globally and once in the loop().

    Code: c [expand] [select all].


    int temp = htu.readTemperature();



    Code: c [expand] [select all].


    temp = digitalRead(SW);
    .

    Yes I know this is a configuration from some example from the web. I already knocked it out but still no change.
  • ADVERTISEMENT
  • #5 18188600
    khoam
    Level 42  
    pier wrote:
    I have already knocked that out but still no change.
    .
    Now show this code again i.e. the one where there is, according to you, a GPIO12 read error.
  • #6 18188611
    pier
    Level 24  
    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #7 18188695
    khoam
    Level 42  
    Change to:
    Code: C / C++
    Log in, to see the code
    .
    and knock out the external pull-up resistor.
  • #8 18190179
    pier
    Level 24  
    khoam wrote:
    Change to:
    Code: C / C++
    Log in, to see the code
    Replace to.
    and knock out the external pull-up resistor.
    .

    Done. No effect...
  • #9 18190197
    khoam
    Level 42  
    Just yesterday I tested the operation of GPIO12 in 'INPUT_PULLUP' mode (program below) on the ESP-07 and everything was OK.
    Either D6 on your board isn't GPIO12, or that pin is messed up, or there's something else connected to that opin.
    Code: C / C++
    Log in, to see the code
    .
  • #10 18190234
    pier
    Level 24  
    I have a suspicion that it is the SPI that may be messing with something on this pin.
  • #11 18190262
    khoam
    Level 42  
    pier wrote:
    I have a suspicion that it's the SPI that may be messing with something on that pin.
    .
    And are you using SPI on pins 12-15? If not, it's just like on an AVR - unused SPI pins can be used for another purpose, with a restriction on GPIO15, which is internally pull-down.
    https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/

    Added after 38 [minutes]:

    pier wrote:
    TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
    .
    I think you are using :) though.
  • #12 18193714
    pier
    Level 24  
    Definitely SPI. I have flipped the DC display pin from GPIO0 to GPIO12 and the display works so all is well with the pin. The button will fly to GPIO0 and it will be ok.

    I messed up myself and used the SPI pin for something else because it suited me so well on the board.

Topic summary

The discussion revolves around troubleshooting a non-functional button connected to the ESP8266, specifically GPIO12 (D6). The user reports that the button, which is pulled up to +3.3V with a 10k resistor, consistently registers as pressed (LOW) even when not activated. Various suggestions are made, including checking the pin configuration, using `pinMode(SW, INPUT_PULLUP)`, and ensuring no other components interfere with GPIO12. The user later discovers that the issue stemmed from using the SPI pins incorrectly, which conflicted with the button's functionality. The button was successfully relocated to GPIO0, resolving the problem.
Summary generated by the language model.
ADVERTISEMENT