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

Crackling sound in ESP8266 cores 2.5.1 and higher #2

Closed
UksusoFF opened this issue Oct 2, 2019 · 10 comments
Closed

Crackling sound in ESP8266 cores 2.5.1 and higher #2

UksusoFF opened this issue Oct 2, 2019 · 10 comments

Comments

@UksusoFF
Copy link

UksusoFF commented Oct 2, 2019

Hi @maxint-rd
Thanks for useful library.

After some years of stable work I updated Arduino IDE and their libraries (and https://github.com/esp8266/Arduino too). Nothing changed in my code but now music not play as expected. It's just creak from speaker.

I see this commit and paste this code into my sketch but nothing changed.

My code example placed here: https://github.com/UksusoFF/wemos-doorbell/blob/master/wemos-doorbell.ino

Can you help me found solution?

@maxint-rd
Copy link
Owner

Hello Kirill, thank you for reporting your issue. That timer issue I encountered didn't result in crackling sound, but caused the delay function to not wait long enough. I haven't tested with the latest versions for some time now. Can you tell me which versions of the Arduino IDE and of the ESP8266 core you are using? Perhaps I can find some time later this week to look into it.
(BTW: I have installed multiple portable versions on my harddisk, which help me to use a previous version when newer ones don't work. Just create a folder named portable in the Arduino folder to do that)

@UksusoFF
Copy link
Author

UksusoFF commented Oct 2, 2019

@maxint-rd
Arduino IDE 1.8.10
ESP8266 2.5.2

Thanks for advice about portable usage. But now I can't find working combination Arduino IDE / Modules :(

@maxint-rd
Copy link
Owner

maxint-rd commented Oct 2, 2019

Hi Kirill, thanks for the swift reply.

So first I tried to reproduce your issue. These are the steps I took:

  • download Arduino IDE from https://www.arduino.cc/en/Main/Software
    (Windows ZIP file for non admin install, version 1.8.10)
  • unzip file, create directory "Portable" in the folder that has arduino.exe
  • run arduino.exe
  • set board url https://arduino.esp8266.com/stable/package_esp8266com_index.jso in Preferences
  • install ESP8266 in Board Manager (version 2.5.2)
  • select board "Generic ESP8266 module". Test ESP-12E module with standard blink sketch
  • download and install MmlMusic and MmlMusicPWM libraries using Sketch->Add ZIP library
  • connect simple buzzer directly between pin 14 and GND
  • compile and test the MmlMusicPWMBlink example

Result: crackling noise! The good news is that I was able to reproduce your issue. Good news because now I can analyse the issue!

  • First I used my DSO112 to look at the signal. I saw high frequency squarewaves (e.g. 32KHz). Not good!
  • Then I tried the older versions that I used last time (Arduino 1.6.10, ESP core 2.5.0). That one worked fine (nice tune and then beeps, although with failing delay function).
  • So then I installed older versions of the ESP8266 core in the newest Arduino 1.8.10 IDE. Results:
    • ESP8266 core 2.5.0 does work (sound frequencies 100-400 Hz, with failing delay),
    • ESP8266 core 2.5.1 also fails (but the delay now seems fixed).
      Apparently something critical was changed between version 2.5.0 and 2.5.1, Most likely it's a change in how timers are used.

So for now I can only recommend you to try the 2.5.0 core. Can you please try to see if that version works for you too? (Along with my delay() workaround).
When time permits I will look deeper into the changes of the different cores and hopefully I can fix this in my library. To be continued...

@maxint-rd maxint-rd changed the title ESP8266 issues Crackling sound in ESP8266 cores 2.5.1 and higher Oct 2, 2019
@maxint-rd
Copy link
Owner

maxint-rd commented Oct 2, 2019

Found the problem. Main cause was PROGMEM float alignment issue introduced in core 2.5.1.
Have updated MmlMusic and MmlMusicPWM to work better with newer cores.
Note: update both libraries. (Perhaps in a future version these libraries will be combined...)

@UksusoFF
Copy link
Author

UksusoFF commented Oct 2, 2019

Thanks @maxint-rd !
Tested both workarounds and it's worked!

@maxint-rd
Copy link
Owner

Hi Kirill, thank you for reporting this issue and for your testing. This library got better thanks to your help!

@tablatronix
Copy link

I just spent 6 hours thinking I had a circuit problem using plain old analogwrite, then updated my projects that use this to test, and behold clicky broken! man what a waste of time.

@maxint-rd
Copy link
Owner

Hi @tablatronix , if it's any consolation: I also spent multiple hours on this. I found that it was due to a problem in the newer cores and I submitted an issue to have it fixed in the core.
For now I updated my libraries with a temporary fix. While at it I replaced the use in MmlMusicPWM of analogWrite by tone, which also worked better with the newer cores. (Somehow analogWrite() also gave me problems in the newer cores).

@tablatronix
Copy link

tablatronix commented Oct 5, 2019

I think it is fixed in staging now (platform io was not updating the platform!), I saw the tone no tone additions and that null fix, thanks!

I am not sure i know what the ::tone is, new to me. I was checking the commits to figure out what you did there.

@maxint-rd
Copy link
Owner

The double colon in the ::tone() call makes sure that it doen't call the tone() method that is defined in the parent class, but rather the tone function defined at the global level, i.e. the one in the Arduino library. The reason I also have an implementation in the MmlMusic library is that if I remember well once (in a time far far away), the tone function wasn't available/working in the ESP core. Another reason was (or might have been, I not quite sure...) that for some environments the MmlMusic library is using the timer interrupt that would be used by the tone function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants