1

As my first IoT type of project, I tried to hook up a pre-amplified electret microphone to an ESP8266 NodeMCU 12E development board, then stream that audio to another computer over the internet. I tried various protocols and approaches to streaming the audio data, but my best effort still resulted in a distorted audio quality on the receiving end.

I began troubleshooting my poor signal quality by investigating the sampling rate of the analogRead(A0). I wrote the code below to show me how much time it takes to sample 1000 analog data points:

#include <ESP8266WiFi.h>

const char* ssid = "___";
const char* pass = "___";

char pay_load[1000] = {0};
int pay_load_length = sizeof(pay_load)/sizeof(pay_load[0]);

void setup()
{
  Serial.begin(115200);
  Serial.println(0);      //start
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);

}

void loop()
{

  int count = micros();
  for(int i=0; i<pay_load_length;i++){

    int analog = analogRead(A0);

  }

  Serial.println(micros()-count);
}

The serial monitor printed values of about 166000 with plus or minus about 100. Does this mean it takes about 166us to get a single value from analogRead(A0)? Which would mean as it stands now, I have a maximum analog to digital sampling rate of 6khz? And this low frequency is a major contribution to my poor signal quality? (When I increase the pay_load length, the for loop execution time increased linearly).

I just want to make sure my experiment above is not mis-leading me into thinking it is difficult for the ESP8266 to capture (and eventually transmit) stereo quality audio.

Related Note: I've been trying to figure out how to write an ISR using hardware timer, because others on stackoverflow suggested that could help me sample analog data points with greater frequency without jitter. But I feel like I'm getting lost in a maze because I have FreeRTOS, which doesn't support hardware timer, and now have to research how to get nonos sdk instead..and not sure what challenge lies after that. Just wondering if getting an arduino with an ethernet shield is just easier?

John
  • 32,403
  • 80
  • 251
  • 422

0 Answers0