Intro
I have built a project whose purpose is to periodically record values from a Differential Pressure Transducer to a file on a microSD card with timing provided by a RTC. Additionally, the microprocessor (ESP32 Sparkfun Thing) hosts a webpage that enables monitoring of the measurements and downloading of data files via a WiFi connection. A custom PCB has been designed to mount all of the components.
The project was tested using a breadboard prototype before the PCB was designed. PCB design was completed using KiCad including passing the design rules checks.
The KiCad schematic is below:
240119-AMDI-V2.pdf (175.2 KB)
The problem
The primary sketch reliably works as designed except for one part - connection to the WiFi. As soon WiFi.begin() is included the troubles start. If the sketch is run without WiFi connection there are no issues with the remainder of the sketch which works reliably.
As a result I have created a test sketch to see if I can isolate the issue (without success).
The test sketch is below.
I have three setups for testing:
- ESP32 Sparkfun Thing (on it own)
- Above soldered onto the PCB without any of the other componentry
- Above with all of the other componentry soldered onto the PCB.
Testing Results
Setup 1 works as expected reliably. The ESP32 connects to the WiFi network and continues through the loop indefinitely.
Setup 2 and 3 have the same issues. The following different results can occur:
- The sketch gets to the line "Connecting to WiFi network" and freezes. This occurs more than half the time.
- The sketch attempts enters the while loop 'while (WiFi.status() != WL_CONNECTED)' and freezes. This occurs irregularly.
- The sketch connects to the WiFi network but the loop freezes after a number of iterations (which can range from 1 iteration through to about 20, rarely more than that). This occurs around a quarter of the time.
I use the onboard reset button between each test to restart the ESP32.
I have the Serial monitor set to verbose and it does not report any issues when the ESP32 freezes.
I have visually checked the soldering but cannot see any issues (i.e. solder joining across two terminals).
I have been trying to fix this for quite awhile now and have drawn a blank as to what is causing it. I suspect it must be something to do with the PCB design but it seems odd that when I run the primary sketch without WiFi everything else works fine. Additionally it seems odd to me that the WiFi is onboard the ESP32 unlike the other components so what is causing it to misbehave?
Any assistance or guidance would be greatly appreciated!
//Libraries
#include <Arduino.h>
#include <WiFi.h> // For home Wifi
// Declarations
String sketchTitle = "AMDI WiFi Connection Sketch";
int loopCounter = 0;
// LED Pins
int redPin = 14;
int greenPin = 12;
int bluePin = 13;
const char * networkName = "XXXX";
const char * networkPswd = "XXXX";
void setup() {
Serial.begin(115200);
delay(1000);
Serial.print("Starting: ");
Serial.println(sketchTitle);
// Set up WIFI
Serial.println("SET UP WIFI");
// Assign network and password based on connection type
Serial.println("Connecting to WiFi network: ");
WiFi.mode(WIFI_STA);
delay(10);
WiFi.begin(networkName, networkPswd);
delay(10);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
} // end setup
void loop() {
// put your main code here, to run repeatedly:
Serial.println(loopCounter);
loopCounter = loopCounter + 1;
Serial.printf("%-32.32s", WiFi.SSID());
Serial.print(" | ");
Serial.printf("%4ld", WiFi.RSSI());
Serial.println();
Serial.println(WiFi.localIP());
delay(5000);
} // end loop