-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
analogRead forces WiFi to disconnect #1634
Comments
I am using EmonLib(Electricity monitoring using analog CT sensor) with esp8266 without problem. Can you share your sketch ? |
Have you tried using |
Here is code:
Yep, I tried using |
@renno-bih I ran a test without delay(3) at least 10 mins, no problem at all. |
This is the clue I have been looking for 😄 I observed similar issue of Wi-Fi connection being dropped after intensive analogRead(A0) when calibrating light sensor for max and min light intensity. I suspected my code doing something wired that should be tracked down before it does something worse. I have checked your code and I observe this issue every 5 – 6s using your sketch after slight modification to see seconds when the connection is lost. There are no issues at all if For testing I have been using: Arduino IDE 1.6.7 with core 2.0.0 and flash settings below: You are our hope of using core version, flash settings or something else that does not produce this issue. Could you share your settings and thoughts? BTW – I enjoy your huge number of projects with esp, nRF24, Arduino, ATtiny85, etc. Watching pictures of variety of your porotypes is fun 👍 Krzysztof |
@krzychb I use git version of esp8266/Arduino with Arduino IDE 1.6.7, 80M/4M(1M)/ESP-12. |
@chaeplin WiFi Manager library is used just for configuring SSID and Pass for the first time. It doesn't make any effect on this. I tried running the same code in AP mode and I have problems there too. |
@renno-bih I have tested again and have no reconnect. My AP : dlink 868L/dd-wrt, B/G/N, Beacon 100ms, DTIM 1
|
It doesn't make sense in my case because my smartphone is just few centimeters from ESP. |
@renno-bih Which version of IDE, esp8266 core and OS do you use ? I will try. |
IDE, 1.6.6, Thank for helping me :) |
I think wifi mode 11B is the root. tested with |
the ADC is also used from the WiFi part to measure the internal voltage to adjust output power, |
@renno-bih,
@chaeplin, Krzysztof |
@chaeplin Nice found. |
This is great we have some break through 😄 I do not like any delays and wasted time in my sketches as well 😄 Krzysztof |
I'm taking 3ms samples and then block analogRead for additional 3ms. (Using elapsedMillis library). I know that it is not the best way to detect noise level but it works reasonably good. It can detect claps :) |
Oooooo! Detecting claps with ESP8266 is on my wish list. |
Purpose of this device is not to detect claps... But to show noise level (scale 0-100). But if it can detect claps it can detect everything else if duration of sound wave is greater than 3ms. |
I did some more testing and now reading A0 every 1ms. Data transmission for display in browser is done using web sockets by Links2004 (they are working great – thanks, @Links2004 👍). Also at any moment I can trigger continuous sampling of A0 for the period up to 60ms. That produces up 720 samples. Longer sampling creates issues so I need to reconnect web sockets (Wi-Fi connection is not dropped). This application works very stable on ESP clocked at 80MHz or 160MHz but web sockets run faster at 160MHz. Another observation is that web sockets are processed faster in Internet Explorer than Google Chrome (both tested on Windows 7). FireFox on Ubuntu 14.04 LTS is almost as fast as IE. After connecting a microphone I can easy visualize 1 KHz sinusoid “on-line” in a web browser. Picture below shows taking and displaying about 110 A0 samples about every 41 ms or so. In this example sampling in ESP takes 10ms, the rest is for sending sample request from web browser to ESP, transmission back and displaying in browser. I can post this application if anybody is interested. Krzysztof |
Yes! I'm very interested in sample to learn websocket. Thanks in advance. |
Here is a short manual 😉 Prepare the following s/w components:
To make it run:
What you should see:
Have fun making it run and let me know if it works for you 😄 Krzysztof |
Great @krzychb ... Thank you for this guide. |
@renno-bih, |
Closing this per OP comment. |
@igrr I have missed your comment |
@krzychb your done well!!!!. Do you have an example like this scope for Websocket Server or embed the HTML into the ESP8266 not separate files? |
Thanks @williamesp2015 😄 |
@krzychb I would be very grateful. A websocket Client+Server could have OTA+web page+web server control, SSID&Password& sampling rate configuration, and Analog data monitor. |
This is strange, as I have developed and tested this application with PlatformIO IDE (I believe the latest IDE 1.3.0). Then I have also tested it Arduino IDE 1.6.9. Later today I will update readme.md with exact versions of IDEs and libraries used. Just to double check, have you upload the data folder / SPIFFS to your ESP module? |
@krzychb Yes, I didn't know about upload spiffs and after upload the page appears after call the IP but disconnected once I click on connect. |
Thanks for update regarding SPIFFS. I have added: Please check if you were following the same procedure and used the same s/w. Application should start automatically after opening module's IP address in a web browser, without pressing "Connect" button. Later I will verify how it works on Ubuntu 14.04 LTS. |
@krzychb Sorry, after successful connection and open the IP in the browser, disconnected immediately and if I change analogsample function to just get sample and wait 1 millisecond, after few second disconnected and noting displayed. |
No problem, this is likely some easy to fix issue.
|
@krzychb my IDE is PlatformIO and I installed ten days ago. |
The s/w releases look OK at the first glance. I have couple of questions:
Krzysztof EDIT: |
Is there a solution to this problem, I am also trying to read analog values then send this data to internet using wifi, even after putting 100ms delay it hangs after 15-20 mins. |
Hi @Nakul93, The solution is not to exceed the average sampling rate. Please see the conclusion of an analysis I made some time ago - https://github.com/krzychb/EspScopeA0/tree/master/Bravo#results |
Sorry to comment on an old and closed thread, but I still run into the same fundamental problem: running analogRead(A0) at full speed gives problems. Can't we solve this properly? For example by returning a cached value (instead of reading from the ADC again) to never sample the ADC too often. This solution is backwards compatible with existing code. |
FWIW, I encountered this issue recently using esp8266 Arduino Core 2.6.1 with Digistump Oak while reading a photocell. It took most of a workday to get my head around what was actually happening. Thankfully, enough people have had this problem that I found anecdotal help easily. In any case, I couldn't read at full loop speed (at 80MHz CPU freq) without WiFi problems but I found that a mere 2 millisecond delay between analogRead calls sufficed to solve the issue without adversely affecting performance of my main functionality. |
I have the same issue on NodeMCU with the latest core(2.6.3). Is there any solution? |
Just spent a day to find the relation between broken wifi and analog reads. I wonder what is actually required to make it work always, not just empirically find sufficiently long delays in sufficiently short intervals. Couldn't this be built into the core? I only do one analog read per loop, so plenty of opportunity for the core to step in to do the needful in the code that calls loop() without any explicit delays. |
see it this way. esp8266 is a WiFi coprocessor intended to work with a host MCU. everything else wasn't planed. |
Just ran into this problem; I couldn't work out why I couldn't see the AP provided by the ESP. Caching the result of |
I've just come across this problem too. The frequency of calling analogRead is not a problem up to 4 or so kHz, but it is the length of time from start that is the limiting factor for me. Even at a low sampling rate of less than 1kHz, the wifi drops out at the same time of about 10secs. Bodgit - what do mean by "Caching the result of analogRead() ..............."? |
@robjmort all I did was store |
OK thanks. I need to sample the ADC at a constant 2 kHz which the ESP8266 does well using the timer as an interrupt, but the wifi drops out after 10s and so far I haven't found a solution. |
just spent hours trying to figure why the wifi stopped working and thankfully found this page. A deal breaker for sound processing application I trying on Lolin NodeMCU V3 at 80MHz as I can only keep wifi if the last analogRead was >= 3ms ago. |
I eventually used a seperate ESP8266 to handle the wifi. |
I've just noticed that there is a 160MHz option for this board in the Arduino IDE but don't know whether that would help or be stable. In any case I suspect you are doing the right thing. |
I'm very very late to the party, but I just found this page whilst trying to debug my problem. Long story short you cannot do repeated successive analogReads on the esp8266. If you do it looses wifi. I have a the NTP class running in the background and I noticed it was having trouble reading the time, getting stuck on 1970 when it normally picks it up before you even see a debug message so basically that was a clue that the main loop was jamming everything up! UPDATE: Again probably everyone knows this but it turns out that the ADC is used for evaluating the WiFi signal strength - and its when you put too many reads in a row then wifi breaks and because its probably in your main loop once it breaks it doesn't tend to work again until reboot. |
Ok, this bit me too, and happy to find this page, saved me a lot of time just to know this is an issue. I did a quick and dirty fix, in my case to read a simple potentiometer value for a dimmer function. void loop() So now it reads the analog port only every 50ms. Which is plenty enough in my case. Thanks & cheers! |
Hello,
I'm trying to make sound detection with my esp8266 and this is part of code I'm using:
Every 10-20 seconds WiFi disconnects. When I use
delay(3);
afteranalogRead
it works without disconnecting WiFi but with this delay I don't get enough samples.Any idea what I'm doing wrong?
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: