-
Fri 2020.02.21
While I normally don't respond to non-officially supported boards posts @Drumline18, this one intrigued me as I recently played with similar code snippets, but with non ESP8266 boards.
In my case, using a logic analyzer, the duration to produce a 1KHz signal using similar sample snippets as in post #1, would occur in one cycle or in this case ~1msec.
'There is quite a long delay before it does anything'
But in L9 it is stated 'instant' - so which is it?
As all the code is not present, it is difficult to determine, but the one and a half second delay could be in another part of the code block. Post all the code.
Without the datasheet for the specified pins, and their ability to drive the speaker, I'd have to guess here. Again, post the link to the specific device datasheet.
How is the speaker connected? Is there a decoupling capacitor used? Does that have polarity? If so, it's possible the delay is caused as that cap is charging. Again, post a picture or better describe.
re L3 '// action : activate buzzer at 1000 freq'
reference to 'speaker' in text and 'buzzer' in codeIs it an actual 4 ohm or 8 ohm speaker, or is it a passive/active buzzer as the keyword defined implies?
I suppose there may be an internal issue. Clicking on the Right facing arrow adjacent to the analogWrite() function heading might lead to some clues.
Click on Right Facing arrow takes one to it's source:
https://github.com/espruino/Espruino/blob/master/src/jswrap_io.c#L167
Divisor for frequency perhaps? Not likely as 1000 base10 is not easily divided by a nice value such as 1024 or 2^10 base2
What are the results of attempting a dozen other frequency values and another group of multiples of ten? a test to see if division by ten is causal
Is memory being cleared between each new frequency test? That example 2 nesting of an analogWrite() within an interval might be problematic. The previous write to that pin might not be cleared before the intended frequency is desired. I found out something similar when the logic analyzer displayed more pulses (higher frequency) than what I thought I was attempting to output.
I'm trying to add a speaker to a project, following the Making Music page using an ESP8266 board (NodeMCU v3).
The example is using analogWrite() to create sound on the speaker and it works.
When the speaker is emmiting sound, I can enter new analogWrites with different frequencies to change the pitch and that works instantly.
The problem is when the speaker is going from silent to emmiting sound. There is quite a long delay before it does anything (~1700ms). Is that normal behavior with the ESP8266 ?
The final desired product chimes when a door is opened and 1700ms delay makes it weird.
Example:
So, copy-pasting the whole example code results in no sounds as there are no notes lasting over 1700ms.
Example 2:
I can also observe the same effect visually with the following snippet (breathing LED) :
And then at any point sending
analogWrite(D2,0)
ordigitalWrite(D2,0)
(or 1) will pause the effect for roughly 1700ms again. Actually, sending analogWrite between 0 and 1 (exclusively) to any pin that is not already been "activated" by another analogWrite will pause the effect on the unrelated D2 pin!What I have tried :
Bonus info:
In the breathing LED effect snippet, I am dividing the sin of time by 2.01 instead of 2 which would allow the numbers to include 0 and 1. If I don't do so, the LED becomes unpredictable when going low, it can flash at full brightness for a very small amount of time, Im assuming when it reaches an actual 0 or 1, but the flash does not last 1700ms.