logo elektroda
logo elektroda
X
logo elektroda

ESP32 Devkit 1 - Random interrupts when wire is connected to GPIO with survival

marrog 177 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21284894
    marrog
    Level 22  
    Hello

    I have an assembled circuit based on ESP32 devkit 1, hooked up to a 4x20 LCD display via i2c, with ds18b20 sensors and thermocouple, and ssr relay (omron). A web server set up where I display the sensor data.
    I have a button connected to the gpio32 (other end to ground) I use a software pullup.
    The button handles the interrupt. Generally everything works, but I noticed that sometimes a random interruption occurs, first when I plug the ds18 sensor into the bus, then when I connect the power supply (250VAC) from the relay, (it feeds the phase through the relay, while the N is shorted to the N of the receiver), (plug into the socket on the wall).
    I don't know if this is a software fault or rather interference from the mains, I use a charger from motorola to power the ESP32.


    
    #define sw1 32   
    
     pinMode(sw1, INPUT_PULLUP);
     attachInterrupt(digitalPinToInterrupt(sw1), sw1_ISR, RISING);
    
    /******************************************************
    bool przerwanie = false;
      void IRAM_ATTR sw1_ISR(){
        swCzas = millis();
        if (swCzas - popswCzas > 250){
          przerwanie = true;
          popswCzas = swCzas;
        }
      }
      
    /******************************************************
     if (przerwanie){
          swCzas = biezacyCzas;
          praca = (EEPROM.read(1)); //wczytaj ON/OFF z EEPROM
          if (praca == "1"){
            EEPROM.write(1, 0);
            EEPROM.commit();
            praca = "false";
            inputPraca2 = "false";
          } 
          if (praca == "0"){
            EEPROM.write(1, 1);
            EEPROM.commit();
            praca = "checked";
            inputPraca2 = "true";
            swCzas = biezacyCzas;
          }
          while (biezacyCzas - swCzas <= 2000UL){ /*pusta petla*/}
    
    .

    Based on the value from the eeprom it executes the program, but that's another issue, it works fine.
    The only problem, is that sometimes (during a random interrupt) it writes the opposite state to the eeprom than it was, as if I used the.... button
    (it writes to the eeprom, because from the web page I can also change the state of the output - the inputPraca2 variable is used for that)
    greetings

    Small update. I am powering the esp32 from the powerbank and now when plugging in the 250VAC plug there is no random interrupt. So interference is to blame.
  • ADVERTISEMENT
  • #2 21286096
    marrog
    Level 22  
    I have done some reading on the web and it appears that the problem is quite complex. It mainly occurs when switching on AC powered devices near the ESP. It seems as if the noise generated triggers the logic from interrupts.
    In my case, even when unplugging the power supply and plugging in the powerbank, this also happens.... Although to a lesser degree, but still.
    The best thing is, just plug the cable to the gpio where the interrupt is and it starts catching noise....
    When the cable is unplugged, there is no problem...
  • ADVERTISEMENT
  • #3 21286124
    tomekptk
    Level 19  
    I have a startup chip on an ESP32 connected, apart from USB from the computer, via contact boards to the power supply and I have noticed that any problems with the cables and contacts strongly affect the stability of the processor. Unexpected reboots and other disturbances occur when such problems occur. Therefore, in a potential target circuit, the power supply will certainly be carefully designed for any interference. Certainly using a charger as a power supply is not an option. Equally important will be the issue of disconnecting any sensors.
  • ADVERTISEMENT
  • #4 21286166
    marrog
    Level 22  
    I currently power mine from a powerbank,so in theory the ESP is separated from the mains. The only common point is the omron 5VDC control on one side and the AC output on the other (but i.e. optically separated).
    Plugging the wire itself (one wire) under the GPIO under which the interrupt is set acts as an antenna to pick up any noise....
    All it takes is for the device next to it to switch on the relay, or switch off with a regular flask button.... And immediately there is an interrupt call. On the other hand, when the cable is unplugged, and the goldpin itself is sticking out, there is no such problem....
    I think I will have to resign from the interrupt and do it with a simple button status call, but i.e. you have to hit the code point.... And the interrupt, it is known, works from a button shot....
    Alternatively, maybe extending the time after the interrupt is triggered so that the code does what you want, i.e. give it a longer delay.... Maybe this will help....
  • #5 21286243
    tomekptk
    Level 19  
    marrog wrote:
    Plugging the wire itself (one wire) under the GPIO under which the interrupt is set acts as an antenna to pick up any noise...
    .
    Where do you have this interrupt plugged in? Generally, no processor input should "hang" in the air. The rule of thumb here is RC filters at the input, which are just to suppress interference, e.g. from contacts. For example, a 0.1uF capacitor to ground and a 1k resistor to the contact. Of course, if the input is to measure an analogue value over a longer distance, this also needs to be thought about in terms of interference.
  • #6 21286305
    marrog
    Level 22  
    I connect the interrupt to the mono switch. Pins between GPIO and ground. I connect, there is an interrupt.

    I was thinking of a resistor and a capacitor. Something like here...
    ESP32 Devkit 1 - Random interrupts when wire is connected to GPIO with survival .
  • ADVERTISEMENT
  • Helpful post
    #7 21286315
    tomekptk
    Level 19  
    This is how it should look according to the rules of the art. Sometimes inductances are added in more sophisticated solutions, but in this case this solution should cut off any interference to the interruption line.
  • #8 21286453
    marrog
    Level 22  
    I'll see after the weekend. I'll let you know mate.

Topic summary

An ESP32 Devkit 1 circuit interfaced with a 4x20 LCD via I2C, DS18B20 temperature sensors, a thermocouple, and an Omron SSR relay experiences random interrupts on GPIO32 configured with a software pull-up and interrupt on RISING edge. The interrupts occur primarily when connecting the DS18B20 sensor or switching the AC-powered relay load (250VAC), suggesting electromagnetic interference (EMI) from mains switching. Powering the ESP32 from a Motorola charger or a powerbank does not fully eliminate noise-induced interrupts, as the GPIO input wire acts as an antenna picking up interference. Recommendations include implementing RC filtering at the interrupt input (e.g., 1kΩ resistor and 0.1µF capacitor to ground) to suppress noise, ensuring no floating inputs, and reconsidering the use of interrupts for the button by polling its status instead. Proper power supply design and sensor disconnection strategies are also advised to improve system stability.
Summary generated by the language model.
ADVERTISEMENT