I am using the code below to test the wifi connection. I use Visual Studio Code, the code runs and connects only if the serial monitor in VSC is open. If you close it and press reset on the ESP32 the code does not connect. If you open the serial monitor again and press reset it then connects. As you can see from the code it does not use Serial at all. Likewise if you plug the ESP into a wall psu it does not connect. The problem is not the psu. When you plug a USB device into a computer a discussion is held between the computer and device. This problem must be something to do with a lack of discussion however it needs someone who understands what goes on. There are quite a number of similar reports but none (that I can find) offer a solution that works. Is there anyone out there who understands what is going on.
Thanks for the comments. Quite a few things tried but very inconsistent results, mostly not working and then randomly working for no good reason. It had the feeling of a hardware problem which is what it turned out to be. The version of ESP32-WROOM32 (Nodemcu) that I have appears not have a pullup resistor fitted to the enable input (pin 3). I pulled the enable pin (3) up to +3.3V with a 10K resistor and lo and behold it all works ok and importantly, consistently. I have wasted so many hours on this, I should have thought laterally a bit sooner.
Here is the pinout from the Espressif ESP-WROOM-32 Datasheet. On the Nodemcu ESP32-WROOM32 module the enable pin is the top pin in the left hand side with the USB at the bottom.
i'm confused, your soldered a wire directly to pin 3 (EN) pad on the board, not a pin on periphery of the board that could be plugged into a solderless breadboard?
As in my last reply I am using a Nodemcu ESP32-WROOM32 module which has 15 pins on the left and right sides of the module. From a top view with the module USB facing downwards the enable pin (EN) appears as the top pin on the left hand side. I hope this clarifies things. I put the ESP32-WRROM-32 pin down so that those not using a Nodemcu module could work out where it appears on their module.
Hmm, well the data sheet doesn't have any fine detail, the image shows all the info there is. Although it says it is active high it doesn't say whether it has an internal pullup or its high impedance and just floating around. If its high impedance it could have 50/60Hz hum on it which could cause who knows what. The board could/should have a pullup fitted. For me connecting the pullup fixed the problem immediately. What I did find was that you need to connect the pullup and then press reset on the board.
I would have expected that the pullup would be on the module, I guess that it is possible that my module has a faulty track/missing resistor. There are however plenty of problems out there similar to those that I experienced. I need to order another module as the only one I have is now in service so I will check the new one when it comes.