BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Issue with connection and NodeMCU V3

Hmm something else is going on then!

Unfortunately yes. I really wish I knew how to fix it. I am testing as many facets of the project as I can

So it’s obviously the microphone configuration.

What hardware is it?

This one:

Works fine offline with both NodeMCU and Arduino Uno

google: “node mcu v3 analogRead”

stuff like this could help:

http://www.esp8266.com/viewtopic.php?f=32&t=3905

Thank you very much! I will read up on it!

i had a few problem with ADC on ESP8266 (for smoke detectors) - so i went with a Nano as a slave board to do the ADC stuff… it could be a backup plan if you cant get your analogRead working…

Good point! The cost isn’t really an issue, just would like to save space in my final enclosure. Might be my only option though. Offline ADC is working perfectly fine, I have it player right now and it sampling everything very well just when the wifi kicks in seems to be the issue

with a Nano slave, you could get creative (like it sounds like you are) and have multiple audio inputs – music sounds different depending on where you are hearing it :wink:

Like a digital signal or multiple microphones? Also, if I use my Uno to do the ADC what is the easiest way to send the result to the NodeMCU?

Just got home and had a crack at it. Here are the logs. I have replicated the issue.
I have a feeling that the problem is with the for() loop being changed to an if() statement.

Im going to have a play around with that audio sample code in a seperate project.

[18563] Connecting to PrettyFlyForAWiFi
[23563] Connected to WiFi
[23563] IP: 192.168.1.36
[23563] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.2 on ESP-12

[23569] Free RAM: 45072
[23571] Connecting to 192.168.1.2
[23579] <[02|00|01|00] d3842c9dc33f4d4099b588c24f1695c3
[23582] >[00|00|01|00]È
[23582] Ready (ping: 1ms).
[23584] <[11|00|01|00]Fver[00]0.4.2[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]ESP-12[00]build[00]Jan 11 2017 15:40:06[00]
[23597] >[00|00|01|00]È
[33598] <[06|00|02|00|00]
[33599] >[00|00|02|00]È
[42498] >[14]mW[00|06]
[42498] >vw[00]2[00]4
4
[42498] <[14]mW[00|06]vw[00]0[00]4
[42540] <[14]mW[00|06]vw[00]1[00]4
[42541] <[14]mW[00|09]vw[00]10[00]clr
[42542] <[14]mW[00|1D]vw[00]10[00]p[00]0[00]0[00]Remember To Turn[00]
[42543] <[14]mW[00|1B]vw[00]10[00]p[00]1[00]1[00]On Manual Mode[00]
[42548] <[14]mW[00|09]vw[00]11[00]clr
[42552] <[14]mW[00|1D]vw[00]11[00]p[00]0[00]0[00]Remember To Turn[00]
[42558] <[14]mW[00|1B]vw[00]11[00]p[00]1[00]1[00]On Preset Mode[00]
[42564] <[14]mW[00|09]vw[00]12[00]clr
[42567] <[14]mW[00|1B]vw[00]12[00]p[00]1[00]0[00]Music Reactive[00]
[52499] <[06|00|03|00|00]
[52501] >[00|00|03|00]È
[53658] >[14]-Z[00|06]
[53658] >vw[00]7[00]2
RISE_ONE_COLOR
[67161] Connecting to 192.168.1.2
[72162] Connecting to 192.168.1.2
[77163] Connecting to 192.168.1.2
[82164] Connecting to 192.168.1.2

Read this and read this thanks to Dave. Might be a board issue. I changed the URL in the Arduino preferences to this:

http://arduino.esp8266.com/staging/package_esp8266com_index.json

… by the way that in that linked forum someone says this URL is buggy but with that URL when I select the mode, color, etc the audio sampling does actually work now (the strip lights react) but the NodeMCU disconnects shortly after, but the bright side is the sampling continues to work. Might be progress?

Next I am going to try to only read at certain time intervals (the link says to try 10 ms and some other guy said 3 worked for him). I am not too familiar with how sound sampling works but if I can get it to do the operation I want that will make me content

@Jamin, I do not believe the for loop being changed to an if is the issue (feel free to state why if you think I am wrong) but it works offline just like the Adafruit code and also with that new URL it works then the wifi disconnects so I think it is the ADC. I think my adjustments “simulate” the Adafruit code.

Interesting… I kinda want to proove that thread wrong! As I have been doing loads of similar projects using ADC in the loop without problems.

I would be very happy if you did :joy: I go back in 5 days and thought the code for this tab would take me a few hours lol.

My guess would be it has something to do with the high volume of reads. Most projects I am guessing (temperature, humidity, etc) only need to be updated every few hours/minutes/seconds not this crazy amount per second

Edit: woops sorry! I found the URL in a second link found on the link i sent you to. I would suggest reading this also

1 Like

Now I am reading this. How can I set it to sample say 2,000 per second? And is this fast enough for audio?

Haven’t tested absolutely everything but I think for my purposes I have it working!!! (… maybe… hopefully… please work… )

What I did was inside of the sampling window, if the difference between the time (in ms) of the last time through the loop and the current time (also in ms) is greater than or equal to 1 ms (hopefully equal to…) then sample by calling audioRead and proceeding with the ADC! In theory this should give be a rate of about 1,000 samples per second which, correct me if I am wrong, is plenty for audio level change detection.

This is thanks to findings from this article.

New Function Code:

void rise_one_color()
{
  if( initAudioListen == true )
  {
   startMillis = millis();  // Start of sample window
   peakToPeak = 0;   // peak-to-peak level
 
   signalMax = 0;
   signalMin = 1024;
  }
 
  tempMillis = ( millis() - sampleMillis ); // compute the difference between current time and last    time through the loop that tempMillis >= 1
  

  if( millis() - startMillis < sampleWindow ) // if we are still within the 50 ms sample window...
  {
    initAudioListen = false;  // don't need to re-initialize variables

    if( tempMillis >= 1 ) // in theory should limit to 1k samples per second? 1kHz?
    {
      sampleMillis = millis();  // reset the time
      
      sample = analogRead( A0 );  // read the signal on A0

      if( sample < 1024 )  // toss out spurious readings
      {
         if( sample > signalMax )
         {
            signalMax = sample;  // save just the max levels
         }
         else if( sample < signalMin )
         {
            signalMin = sample;  // save just the min levels
         }
      }   // end of checking levels
    }   
  } // end of checking sampleWindow threshold
  else
  {
    initAudioListen = true; // done with sample, initialize again
  }


   if( initAudioListen == true )
   {
       peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
  
       double volts = (peakToPeak * 3.3) / 1024;  // convert to volts
  
  
       if( volts >= .125 ) // if over threshold, brighten the leds
       {          
            tempMusicRedVal = (musicRedVal * 3);
            tempMusicGrnVal = (musicGrnVal * 3);
            tempMusicBluVal = (musicBluVal * 3);
        
           analogWrite( redPin, tempMusicRedVal );  // LEDs get brighter if threshold is met
           analogWrite( grnPin, tempMusicGrnVal );
           analogWrite( bluPin, tempMusicBluVal );        
       }
       else // if not above the threshold go dim
       { 
           analogWrite( redPin, musicRedVal );  // LEDs stay dim
           analogWrite( grnPin, musicGrnVal );
           analogWrite( bluPin, musicBluVal );
       } // end of volts check
   }      
} // end of rise_one_color()

if you cant change the colour @ 1000 Hz why do you need to sample it at 1000Hz?

and i think there are only 1024 steps, not 1025 as you have in your sketch…

(zero is a number)

https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage

Are you recommending optimization? If so how would you change it?

I was just trying to get it to work at all!

Also as far as the 1024 goes that came from this code but I can change it

Edit: i don’t think that is an error? It checks for values less than, not less than or equal to, 1024 which would 0-1023 and only 1024 steps?

ok, sure, my mistake! it’s just a thing to be aware of in coding… that the range is 0-1023… sorry to side track you :slight_smile: