Page 1 of 2

Can all pins be used when using WiFi?

Posted: Sun Jan 06, 2019 4:42 pm
by lesept
Hi
I'm experincing a weird situation, which makes me ask this question.

I have a LOLIN32 Lite board (for now, later I'll switch all to a LOLIN32, low power board). On it are connected: 1 DHT22, 1 MPU6050, 2 e-paper displays. This requires quite a lot of pins, but I managed to make it work.

But now I want to connect to my WiFi. And then, the sketch freezes at the Wifi.begin instruction. It seems that some ESP32 pins are "sensitive" when using WiFi:
The ESP32 integrates two 12-bit SAR (Successive Approximation Register) ADCs supporting a total of 18 measurement channels (analog enabled pins).

The ADC driver API supports ADC1 (8 channels, attached to GPIOs 32 - 39), and ADC2 (10 channels, attached to GPIOs 0, 2, 4, 12 - 15 and 25 - 27). However, the usage of ADC2 has some restrictions for the application:

ADC2 is used by the Wi-Fi driver. Therefore the application can only use ADC2 when the Wi-Fi driver has not started.
Some of the ADC2 pins are used as strapping pins (GPIO 0, 2, 15) thus cannot be used freely.
But I use some of these pins: 13, 14, 15 & 27 for my displays. What should I do with these pins? Can I use some of them or none? Should I avoid using strapping pins (0, 2, 12, 15)?

Thanks for your help.

Re: Can all pins be used when using WiFi?

Posted: Sun Jan 06, 2019 6:56 pm
by ESP_Sprite
The logic is different: if you want to use the ADC2 functionality of these pins, you cannot use WiFi functionality. As your display in all likelyhood does not use the ADC, this is not your issue.

Are you sure the power to your board is sufficient? Bad power supply (thin USB cables, underpowered LDOs, ..) usually give issues when starting WiFi.

Re: Can all pins be used when using WiFi?

Posted: Sun Jan 06, 2019 9:08 pm
by lesept
Not easy to tell, but I'd say yes. I had it work with Wifi with 2 OLED I2C displays before I changed them to e-papers.

I understand your logic, but I had no problem with the I2C displays, whch did not use those pins.

Re: Can all pins be used when using WiFi?

Posted: Sun Jan 06, 2019 10:14 pm
by lesept
I have changed the displays pins in order not to use the ADC2 pins. The good news is that I now can connect to the WiFi. The bad news is that the displays do not work... I need to use one of those ADC2 pins, as a digital pin.

Which one(s) should I choose?

Re: Can all pins be used when using WiFi?

Posted: Tue Jan 08, 2019 10:27 am
by ESP_Sprite
That does not make sense: as I said, usage of the pins with ADC2 functionality in digital mode should in no way preclude you from using WiFi. Do you get any messages from the serial port from the ESP32 when you do use those pins?

Re: Can all pins be used when using WiFi?

Posted: Tue Jan 08, 2019 10:42 am
by lesept
Sorry if it doesn't make sense, but it's real.
I don't get any message on the serial monitor, as I said above, the sketch seems to freeze.
I added a serial print before the WiFi init instruction, and another one after it , I only see the first one.

I'm sorry because I changed most of my pins mapping in order not to use those pins, see my previous message, so I can't reproduce the problem easily.
I'll try to use one or two of these pins tonight and will update the post with the results. From what I understand from your kind answers, I can choose any of those pins without any restrictions. Is this correct?

Re: Can all pins be used when using WiFi?

Posted: Tue Jan 08, 2019 8:59 pm
by lesept
Hi
I had it work now. You were right, thanks a lot for your help !

Here are the connexions I use, if it can help someone:

E-paper displays :

Code: Select all

/*
   Connexions
             grand   petit
      BUSY    22       4
      RES     16      16
      D/C     17      17
      CS      19       5
      SCK     18      18
      SDI     23      23
      GND     GND     GND
      3V3     3V      3V
*/
#define RST_PIN 16
#define CS_p 5
#define CS_g 19
#define BUSY_p 4
#define BUSY_g 22

GxEPD2_BW<GxEPD2_290GD, GxEPD2_290GD::HEIGHT> petit(GxEPD2_290GD(/*CS=*/ CS_p, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ BUSY_p));
GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> grand(GxEPD2_420(/*CS=*/ CS_g, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ BUSY_g));
I2C sensor accelerometer

Code: Select all

SDA 33
SCK 32
INT 34
DHT 22 sensor : not working with data pin on 35, trying 25...

Re: Can all pins be used when using WiFi?

Posted: Thu Apr 13, 2023 3:10 am
by nguardino
I just created an account just to chime in on this. I was troubleshooting some code for the last few hours trying to get my ESP32 to control a dozen solenoids based on a network trigger. Whenever I uploaded my code, I got some looping connection issues that prevented the board from getting online. I searched around quite a bit, and started deconstructing my code. Eventually I found out that the only piece of code that caused issue was my pinMode declarations. Finally, out of desperation, I asked GPT4, and it told me that the ESP uses internal pin locations to connect to wifi, and gave me a new set of 13 pins to use. I updated the pin list and immediately it ran perfectly. I am not sure which pin was the problematic one, but based on its explanation and resolution, there is definitely some validity to ESP32 pins being reserved for wifi.

Re: Can all pins be used when using WiFi?

Posted: Thu Apr 13, 2023 8:07 am
by ESP_Sprite
nguardino wrote:
Thu Apr 13, 2023 3:10 am
Finally, out of desperation, I asked GPT4, and it told me that the ESP uses internal pin locations to connect to wifi, and gave me a new set of 13 pins to use.
ChatGPT is wrong. The ESP is a single piece of silicon, as it has the WiFi embedded on it, it does not require any GPIOs to 'connect' to WiFi. Not sure why your project worked after using different pins (although it sounds like you used one of the GPIOs the flash was connected to, which can be an issue) but WiFi does not use any GPIOs that can interfere in the way described.

Re: Can all pins be used when using WiFi?

Posted: Mon Jul 24, 2023 2:11 pm
by hajotha
Hello,
I have an application with ESP32 WROVER. Since I've been using WiFi, Pin4 has been set to 0. If I switch WiFi off (WIFI_OFF), Pin4=4095. I've been looking for the error in myself for a long time! :shock: