The only difference between the circuitry there and mine is that I use a 4.7k ohm resistor in place of the potentiometer.
I am having some issues with severe audio distortion. From searching the forums, it seems I am not the only one, but I haven't located any solution that has actually worked for me.
I have checked and double checked that I am exporting my audio file through Audacity as an 8-bit unsigned PCM wav file at 88200 Hz. When I play the audio on my computer, it seems fine. However, from the arduino, it is heavily distorted. I can't shake the feeling that something is still wrong with my formatting.
A potentiometer is TWO resistors in series with the slider making the connection point of the two resistors. What are you using for the other resistor?
If you have some powered computer speakers, try them (without the LM386).
With the LM386, you do need the pot or a voltage divider, or both. It should be an "audio taper" pot.
You don't need much voltage gain and the LM386 has too much voltage gain. But you need the 386 for current/power gain (to drive a 4 or 8-Ohm speaker). I believe the chip in the MKR Zero operates at 3.3V and you should be able to get about 3.3V peak-to-peak out of the DAC. If the LM386 is powered from 5V, gain of less than 2 is enough to over-drive it into distortion.
Okay, that makes sense. I can set up a voltage divider tomorrow when I get back to the lab and test and see if it works with that change. I thought that a resistor in the line would take the same function as a potentiometer (but obviously without the variability).
I guess I need to brush up on my circuit analysis.
To avoid frustration and repetition replacing the resistor pairs. Use a potentiometer. Adjust to the level you want. Then measure the resistance from each end to the slider. That will be the values for your fixed resistances.
So, I mostly understood your comment. For background, I just graduated computer engineering, so I have some understanding of electrical hardware, but I'm far from advanced, and this is the first time I have ever done anything with audio.
I will set up a voltage divider when I get to the lab tomorrow to see if that's the issue. I don't really understand why the ground connection at the pot is important vs just having a resistor inline with the LM386, but I'd like to understand if you could point me to any resources. (It's possible I just forgot some circuit analysis basics from my classes a few years ago lol).
Also, I din't really understand what it means to over drive something into distortion. From your comment, it seems like it has something to do with setting gain so that the lm386 attempts to drive output above its power source voltage, but I don't really understand the consequences of that, or why/how it actually happens. Again, if you have any resources on why this causes distortion/what distortion actually is on a signal level, I'd love it, but totally understandable if its not really feasible for you.
Thanks for your help, I'll update tomorrow if setting up the voltage divider helps or no.
What are you using as your ground ? You could try connecting your audio output circuit to a different ground than the ground pins on the board, perhaps there is some oscillations from the Arduino clock that are interfering
The resistor "inline" also forms a voltage divider, but the "resistor to ground" is the input impedance of the LM386, which is very high. So, there is no effective reduction of the input voltage, and the amplifier input is overloaded.
Invest in a 10K pot, or salvage one out of a junked radio, music player or toy, and your life will be relieved of a great burden.
Because one resistor can never reduce voltage,it only limits current. To change the voltage you need a voltage divider.
When you drive something too hard, that is the signal exceeds the maximum and minimum that the amplifier is capable of producing you get clipping of the waveform. This appears as flat portions of the peak and trough of the waveform. See
Again the forum software did not show me the posts from @jremington and @LanGenz before I had posted my reply.