Problems using wifi with analog
Posted: Mon May 02, 2022 7:14 am
Hi,
I am using ESP32-WROOM-32D.
So i've been trying to do some data collection with my Microphone and send it over the MQTT.
I noticed that when I enter the specific function (code below) I get alot of noises (Used a scope to check ).
So i connected the scope to the analog I(GPIO 39).
I found out, that when I comment the "setup_wifi()" (Line 30) function, the noises stop. when i uncomment it, i get alot of noises from the GPIO39.
the thing is, that the noises are very high peaks that change the whole values of the fft (+-10dB, instead of +-0.5dB) so i really need to fix it.
I attached a photo of the noises that I measure with the O-Scope
I would really appreciate your help on how to reduce the noises and make my sampling more accurate.
I am using ESP32-WROOM-32D.
So i've been trying to do some data collection with my Microphone and send it over the MQTT.
I noticed that when I enter the specific function (code below) I get alot of noises (Used a scope to check ).
So i connected the scope to the analog I(GPIO 39).
I found out, that when I comment the "setup_wifi()" (Line 30) function, the noises stop. when i uncomment it, i get alot of noises from the GPIO39.
the thing is, that the noises are very high peaks that change the whole values of the fft (+-10dB, instead of +-0.5dB) so i really need to fix it.
I attached a photo of the noises that I measure with the O-Scope
I would really appreciate your help on how to reduce the noises and make my sampling more accurate.
- #include <WiFi.h>
- #include <Wire.h>
- #include "arduinoFFT.h"
- #include "Math.h"
- const uint16_t samples = 4096; //This value MUST ALWAYS be a power of 2
- unsigned int sampling_period_us;
- const double samplingFrequency = 2500;
- double vReal[4096];
- double vImag[4096];
- arduinoFFT FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
- int newTime;
- char machine[] = "FVT-PCB-001";
- char TFS_TOPIC[50] ; char Voice_TOPIC[50]; char Request_TOPIC[50];
- const char* ssid = "ABCD";
- const char* password = "12345678";
- WiFiClient espClient;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- setup_wifi();
- //pinMode(4, OUTPUT);
- pinMode(36, INPUT);
- digitalWrite(4, HIGH);
- sampling_period_us = round(100000*(1.0/samplingFrequency));
- }
- void loop() {
- double dB[samples/2];
- int x;
- // put your main code here, to run repeatedly
- for (int i=1;i<samples;i++)
- {
- newTime = micros();
- vReal[i] = analogRead(39)*3.3/4095;
- vImag[i] = 0;
- while(micros() < (newTime + sampling_period_us));
- }
- //for (int i = 1;i<samples;i++)
- //{
- // Serial.println(vReal[i]);
- //}
- FFT.DCRemoval();
- FFT.Windowing(FFT_WIN_TYP_HANN, FFT_FORWARD);
- FFT.Compute(FFT_FORWARD); /* Compute FFT */
- FFT.ComplexToMagnitude(); /* Compute magnitudes */
- delay(100);
- for (int i = 232 ;i<235;i++) // 1KHz
- {
- //dB[i] = 20*log10((vReal[i]*Cal_Val)/(EEPROM.read(Sensor)*0.001));
- dB[i] = 20*log10((vReal[i]*500)/(50*0.01));
- x = int(i*1000/234);
- Serial.println();
- Serial.print("Freq: ");
- Serial.println(x);
- Serial.print("dB: ");
- Serial.println(dB[i]);
- //doc["value"][String(x)] = dB[i];
- }
- delay(1000);
- }
- void setup_wifi()
- {
- delay(10);
- // We start by connecting to a WiFi network
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.println("Problem in wifi");
- }
- }