Skip to content
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

analog (Max 4466) Mic sometimes won't work in 13.2 #231

Closed
1 task done
ghpk opened this issue Sep 15, 2022 · 25 comments · May be fixed by #257
Closed
1 task done

analog (Max 4466) Mic sometimes won't work in 13.2 #231

ghpk opened this issue Sep 15, 2022 · 25 comments · May be fixed by #257
Labels
question Further information is requested wontfix This will not be worked on

Comments

@ghpk
Copy link

ghpk commented Sep 15, 2022

What happened?

I took a fresh ESP32 Board,
Flashed Wled suggested bootloader, then flashed the 13.2 but microphone wont respond.

I had another ESP32 and new MAXX4466 Microphone,
build up the circuit again on another PCB and it wont react to any sound, WLED static effects would work just fine.

Sound Reactive wont work No matter what gain I select,
infact I've made this earlier too and quite comfortable with tinkering settings but it won't work for sound.

To Reproduce Bug

Flash esp32 with currently available latest build and use MAXX4466 microphone it wont work, static effects would work fine though.

Expected Behavior

Wled should react to music.

Same esp32, I flashed SR WLED 0.13.1 and it works fine.
WLED 0.13.1 (build 2203150)

Install Method

Binary from WLED.me

What version of WLED?

WLED 0.13.2 (2207281)

Which microcontroller/board are you seeing the problem on?

ESP32

Relevant log/trace output

No response

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ghpk ghpk added the bug Something isn't working label Sep 15, 2022
@CnLm3d
Copy link

CnLm3d commented Sep 15, 2022

esp 32 devkit sahibiyim. max 9814 mikrafon ile ben de aynı sorunu yaşıyorum. 36 nolu pinden ölçüm yaptığımda 1,2V ile 1,4V arasında ölçümler alıyorum ancak şans eseri çalıştırsam bile açıp kapattığım anda ses efektleri çalışmıyor.

@softhack007
Copy link
Collaborator

softhack007 commented Sep 17, 2022

In general the MAX4466 does work, but it is very sensitive to voltage fluctuations so not exactly the best device to use.

Did you check that the GPIO is set correctly in sound setting?
https://github.com/atuline/WLED/wiki/Sound-Settings#analog-input-pins

Btw, please try our official release of WLED SR 0.13.2, build 2207301

https://github.com/atuline/WLED/releases/tag/v0.13.2

@softhack007 softhack007 added question Further information is requested and removed bug Something isn't working labels Sep 17, 2022
@Labersack99
Copy link

I have the same problem with 3 different Devices, all ESP32 with MAX9814 (GPIO36, Gain+VCC connected).
Tried with Gain, Squelch and AGC setting, nothing worked.
Flashed version 0.12.1-b1 and mic in all three devices is working again.

@softhack007
Copy link
Collaborator

Please check if it works when using another GPIO for the microphone input, like GPIO32.

@ghpk
Copy link
Author

ghpk commented Sep 18, 2022 via email

@softhack007
Copy link
Collaborator

I remember that some users found a "magic trick" that sometimes helps when analog mics refuse to work.
It involves installing SR13.2 via usb from here https://wled-install.github.io/ ( only usb from that site and no OTA or other method). @dosipod maybe you have some more ideas?

@Labersack99
Copy link

I tried installing via the WEB-GUI https://wled-install.github.io/ .
It's the same as installing via OTA, WLED-SR is working, but no SoundReactive effects.

@wgtp
Copy link

wgtp commented Sep 19, 2022

I too face the same problem. The highest version that I can run without any issues is 13.0 b4. Anything above seems to be inconsistent. It might work initially after firmware upgrade but after few days microphone functionality stops. This was already reported here:
#162

@softhack007 softhack007 changed the title Max 4466 Mic won't work in 13.2 analog (Max 4466) Mic won't work in 13.2 Sep 19, 2022
@softhack007
Copy link
Collaborator

softhack007 commented Sep 19, 2022

hmm 🤔 there must be something special about your ESP32...Analog Mic definitely works for many people who are using 13.2 - including myself. One difference is that SR-WLED 13.0-b4 did not use i2S drivers for analog inputs, but was based on analogRead().

💡 two things I can imagine

A) do you have analog buttons (i.e. potentiometer) configured in WLED? Analog audio input does not work when other analog devices are in use. That's due to a bug in the framework from espressif - a conflict between I2S driver and analogread driver. If you have, please disable all analog inputs, restart your esp32 and try again.
Screenshot_20220919_202357

B) Could it be that you have an ESP32 "revision 0"? Revision 0 has many known hardware-bugs, which could also explain the problem you see.

You can easily check your ESP32 hardware revision with a simple Arduino sketch:

#include <Arduino.h>
#include <Esp.h>

void setup() {
  Serial.begin(115200); delay(2000); Serial.println();

  Serial.print("ESP chip model   : "); Serial.print(ESP.getChipModel());
  Serial.print(", Revision ");         Serial.println(ESP.getChipRevision());
  Serial.print("CPU Speed (Mhz)  : "); Serial.println(ESP.getCpuFreqMHz());

  Serial.print("FLASH size (kb)  : "); Serial.println(ESP.getFlashChipSize() / 1024);
  Serial.print("FLASH Speed (Mhz): "); Serial.print(ESP.getFlashChipSpeed() / 1000000);
  Serial.print(", Mode ");             Serial.println(ESP.getFlashChipMode());

  Serial.println(); Serial.flush();
}
void loop() {
    delay(2000);
}

To run this, you only need Arduino IDE and the "ESP32 Arduino" board package. Compile & upload, then open Serial Monitor and press "RST" on ESP32.

On my ESP32, I get this output:

ESP chip model   : ESP32-D0WDQ6, Revision 3
CPU Speed (Mhz)  : 240
FLASH size (kb)  : 4096
FLASH Speed (Mhz): 80, Mode 2

Please post the output you get.

@wgtp
Copy link

wgtp commented Sep 19, 2022

The buttons are disabled. I think this was suggested in #162
image

Here is my output. Looks to be revision 1.

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13160
load:0x40080400,len:3036
entry 0x400805e4

ESP chip model : ESP32-D0WDQ6, Revision 1
CPU Speed (Mhz) : 240
FLASH size (kb) : 4096
FLASH Speed (Mhz): 80, Mode 2

@softhack007
Copy link
Collaborator

softhack007 commented Sep 20, 2022

Chip info looks good.

Sorry don't have additional ideas as to what else can cause your problem. I've cross-check the source code, and everything that's related to analog input looks good.

There are some generic clues in our wki that helped others make theit analog microphones work better. Maybe you find something here: https://github.com/atuline/WLED/wiki/First-Time-Setup#noise-and-spikes

@wgtp
Copy link

wgtp commented Sep 20, 2022

Thank you for looking into this problem. I have a spare esp32 that I might start fresh and see what happens. If that doesn’t work, I will just get a digital Mic.

@nielsaust
Copy link

Hi there. Any updates on this? I am facing the similar problem. I'm using a quinled-dig-uno v3 with a max4466 mic. The leds respond in SR mode but doesn't seem to be related to the mic, because they also light up in complete silence. Unplugging the mic also still makes the light bounce, so it seems I cant fault the mic(?).

Any ideas?

@lorenz24
Copy link

lorenz24 commented Oct 14, 2022

Same problem, but if I reset the module the micro is working.
Only cold start causes the problem.
I am using a D1 mini ESP32 module.

@lokster
Copy link

lokster commented Oct 22, 2022

I can confirm the same issue happening for me as well - cheap ESP-WROOM-32 (38 pin). None of the suitable analog inputs work.
0.12.0 works fine,
v0.13.0-b4 works fine,
v0.13.0-b6 and newer - do not

@softhack007
Copy link
Collaborator

softhack007 commented Oct 22, 2022

0.13.0-b4 is the last version that uses analogread() for taking mic samples. All never version are based on I2S-ADC. This change was necessary because analogread() cannot guarantee exact timing of samples, which is necessary for frequency analysis (FFT).

There is a known bug in espressif software when using I2S-ADC together with analogread(). Please check that you have not configured any "analog button" (potentiometer) in WLED, and don't use any usermods that call analogread().

@lokster
Copy link

lokster commented Oct 22, 2022

Does that mean that after version 0.13.0-b4 it is not possible to directly send analog signal to the esp32 (for example from Line Out) and must use additional hardware?

@softhack007 softhack007 changed the title analog (Max 4466) Mic won't work in 13.2 analog (Max 4466) Mic sometimes won't work in 13.2 Oct 22, 2022
@softhack007
Copy link
Collaborator

softhack007 commented Oct 22, 2022

Does that mean that after version 0.13.0-b4 it is not possible to directly send analog signal to the esp32

The situation is not that bad. Actually there are many users who are happy with SR 0.13.2 and analog input (mic or line-in) and they never experienced any problems. This is Including myself - I still have one ESP32 here with an analog microphone, and my setup works since months.

Then, there are cases like yours, where the same software does not work reliably with the same analog input devices. We never understood the difference. Maybe something deep inside the hardware drivers that we cannot change. Or bootloader, or power supply, or flash wear-out, or different ROM version, or something completely different.

The known bug from espressif is relevant when you have analog audio (mic or line-in) and another analog signal, for example potentiometer. In this setup, I2S and analogread() drivers seem to get into conflict, and they both stop working.

Due to another known problem of ESP32 hardware, changing analog mic config always requires a hardware reset (power off/on)

The best solution is actually to use I2S for sound input, for example attach IMNP441 which is well-tested. I2S digital audio has far superior quality than any directly attached analog signal.

One idea - however just my educated guess - would be to set "disable wifi sleep" in wifi settings. It might make a difference, because it also prevents ADC units from going into sleep mode.

@phonec
Copy link

phonec commented Nov 1, 2022

Due to another known problem of ESP32 hardware, changing analog mic config always requires a hardware reset (power off/on)

This problem seems to be that the I2S peripheral needs time to disable before resetting it so that its registers do not end up in an indeterminate state. This can be easily seen if you make several cold restarts in a row from the WLED menu "Config/Security & Updates/Save & Reboot", after that I2S-ADC goes into an indeterminate state and the analog microphone does not work and only a hardware reset is needed.

This is solved by setting a small guard interval before resetting the I2S peripheral in usermod.cpp:

 // Reset I2S peripheral for good measure
  i2s_driver_uninstall(I2S_NUM_0);
  delay(100); // Give that peripheral some time to disable.
  periph_module_reset(PERIPH_I2S0_MODULE);

This should also solve the problem of needing a hardware reset when changing microphone pins.

Frank, if you have the opportunity to test this and make changes to the code, I would be very happy about it.

@softhack007
Copy link
Collaborator

softhack007 commented Nov 1, 2022

This is solved by setting a small guard interval before resetting the I2S peripheral in usermod.cpp:

 // Reset I2S peripheral for good measure
  i2s_driver_uninstall(I2S_NUM_0);
  delay(100); // Give that peripheral some time to disable.
  periph_module_reset(PERIPH_I2S0_MODULE);

Frank, if you have the opportunity to test this and make changes to the code, I would be very happy about it.

The code you suggest ist already there since some time. I could add a short delay, but I don't belief it will change much. Espressif have confirmed that only a "hardware reset (power-on) can disconnect ADC from the I2S unit". Feel free to tell them what you think about that (follow the link above to espressif problem report).

WLED/wled00/usermod.cpp

Lines 27 to 31 in 086b516

// Reset I2S peripheral for good measure
i2s_driver_uninstall(I2S_NUM_0);
periph_module_reset(PERIPH_I2S0_MODULE);
delay(100); // Give that poor microphone some time to setup.

@softhack007
Copy link
Collaborator

Edit: Does the extra delay(100); solve it for you? If yes, please make a PR and i'll merge it into dev.

@phonec
Copy link

phonec commented Nov 1, 2022

that's right, the delay that already exists after periph_module_reset() is also necessary for proper initialization.

I'm just doing an additional guard delay of 100ms between i2s_driver_uninstall and periph_module_reset, as this solves the problem of falling off the analog microphone during a soft reset and changing the pin as I wrote, please check, for me it solved the problem, I tested the soft reset all day and every time the microphone remained active.

@softhack007
Copy link
Collaborator

OK, that's good enough. Actually, timing is not critical in that part of the code.
Please make a PR and i'll merge it.

softhack007 added a commit that referenced this issue Nov 1, 2022
Additional guard delay after i2s_driver_uninstall
May help in case that an ADC analog microphone is not responding after software reset.

Related to #231
@softhack007 softhack007 linked a pull request Dec 4, 2022 that will close this issue
@softhack007
Copy link
Collaborator

In case that analogread() seems to work but WLED animations still don't react, the reson might be that the analog input signal is not centered around 1.8V (analogread would return 0 in silence, while it should be around d 2048 if the signal is well centered).
See discussions here MoonModules#10

@softhack007 softhack007 added the wontfix This will not be worked on label Jun 25, 2023
@softhack007
Copy link
Collaborator

Situation might improve with the last beta 0.13.4

If still not working, then -sorry- you might have a broken max4466. It works for many other users, including myself.

Any way the MAX4466 is very bad quality, if you need to use analog go for max9814. Even better try out an I2S microphone like the INMP441.

Closing as "cannot reproduce"

@softhack007 softhack007 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants