I'm building a simple amplifier around a LM386. The circuit I'm using is this:
The input is on pin 1 of the connector and is a square wave coming from a digital pin on a NodeMCU devboard.
When I turn the circuit on, I can hear a low frequency oscilation on the speakers (not a constant tone, but as if the speaker was turned on and off a few times a second).
I tried adding a capacitor between the signal and ground as it seemed to work in this related question but I needed a fairly big capacitor (220uF) to get any result at all, and it only decreased the volume of the noise (not to mention it is filtering my input, if I understand it correctly).
What did get rid of the noise completely was adding a 1K resistor between pin 7 and ground (in parallel with the existing capacitor):
I have no idea why this works, but it gets rid of the noise completely.
So my main question is: what is this resistor in parallel with the capacitor doing and why does this remove the noise?
I'm happy to keep this solution if it makes sense, but first I need to understand why it works.