I'm having major voltage drop/brownout issues with an esp32 devboard when I initialise the onboard WiFi. As a result I'm setting up a switchable 5V power bus for my peripheral devices using a P-channel MOSFET so I can power these up after the WiFi is connected.
The switch works perfectly when running from usb power, but when I power everything from an external 5V/3A power adapter plugged into the breadboard rail, the circuit fails and the LED in continually ON. If I remove the switch pin from the breadboard the LED switches off. Can someone please advise what would be causing this behaviour and how I might troubleshoot or rectify?
Bodgey Sketch below as well as photo of my very simple circuit. I can make a fritzing diagram if better, but it's a very simple layout.
Many Thanks.
/*
Testing barebone Network connectivity using LED as indicator.
Switchable 5V supply controlled by MOSPIN
*/
#include "esp_wifi.h"
#include <WiFi.h>
// ===== Network credentials and Config =====
const char* localHostname = "nodeboxin" ;
const char* ssid = "XXXXX" ;
const char* password = "XXXXXXXXX" ;
const int LEDPIN = 2;
const int MOSPIN = 4;
void setup() {
Serial.begin(9600);
delay(50);
pinMode(MOSPIN, OUTPUT);
digitalWrite(MOSPIN, HIGH);
pinMode(LEDPIN, OUTPUT);
// flash onboard LED 5 times to show stable running
Serial.print("Running in setup");
for ( int i = 0; i < 5; i++) {
digitalWrite(LEDPIN, HIGH);
delay(250);
digitalWrite(LEDPIN, LOW);
delay(200);
}
// initiate network
esp_wifi_set_max_tx_power(20); // Set WiFi TX power low
WiFi.setHostname(localHostname) ; // set hostname
WiFi.begin(ssid, password) ; // connect to WiFi
while (WiFi.status() != WL_CONNECTED) {
delay(500) ;
Serial.print("not connected");
}
// if connected, flash led 3 times fast then 3 times slow
if (WiFi.status() == WL_CONNECTED) {
for (int i = 0 ; i < 3 ; i++) {
digitalWrite(LEDPIN, HIGH);
delay(200);
digitalWrite(LEDPIN, LOW);
delay(100);
}
for (int n = 0 ; n < 3 ; n++) {
digitalWrite(LEDPIN, HIGH);
delay(500);
digitalWrite(LEDPIN, LOW);
delay(200);
}
}
Serial.print("End setup");
Serial.print(WiFi.localIP()) ;
}
void loop() {
Serial.println("In loop");
Serial.println(WiFi.localIP()) ;
delay(1000);
for (int p = 0; p < 30; p++) {
digitalWrite(LEDPIN, HIGH);
delay(250);
digitalWrite(LEDPIN, LOW);
delay(100);
}
digitalWrite(MOSPIN, LOW);
Serial.println("Turning on FET");
delay(5000);
digitalWrite(MOSPIN, HIGH);
Serial.println("Fet off");
}