OLED display (0.96in, 2 colors, waveshare) via Adafruit_SSD1306 (I2C)
I added some resistors and capacitors as noise filter.
Values were calculated as I understood from the PAM8302A datasheet.
The sound is nice (above 150Hz), just the short noise when the display updates is distracting.
Also a potentiometer for volume control.
I attached the source code used to run the ESP8266 here.
It tries to login to my local WLAN (credentials changed) and connects to jazz.streamr.ru with a status text on the display and Seriel monitor. public.cpp (4.5 KB)
I have the suspicion, that the Reset signal to the OLED creates a voltage drop inside the ESP8266 which is transfered to the RX pin. Then I might need an external audio module.
Things I tried to fix the noise were
to use external speakers,
use another power-supply for the amplifier,
use an transistor instead of directly the audio signal from the RX pin,
use 80k Resistors instead of 20k,
a coil in line and capacity to GND to the OLED reset pin
Do you see a cause for the distortion?
Should I use an additional/different module to avoid this noise?
I read about the DFPlaer, but it seems to not play streams from seriel.
The PAM audio chip has 50dB power supply ripple rejection. Is there only one 4.7µF for the 3.3V ? You could add a few more capacitors with different values, but I assume that you have a module for the audio chip and there are probably capacitors on that module.
A OLED display causes troubles, but noise from the OLED should not get near the audio signals.
Is the RESET signal really needed ?
Do you know how the I2C bus is implemented on the ESP8266 ?
This seems to be the current low level implementation for the I2C bus: https://github.com/esp8266/Arduino/blob/master/cores/esp8266/core_esp8266_si2c.cpp.
It is a combination of pin-toggle and interrupts.
Those interrupts might interfere with the audio processing.
If the OLED is the only thing on the I2C bus, then you could try a software I2C bus to get rid of the interrupts.
I think you need pullup resistors for SDA and SCL.
I do not see any high frequency bypass capacitors, Pull ups on the I2C lines. The SD line is floating, not a good thing. From the data sheet: " PAM8302 is a high performance, high speed class D amplifier, and it requires a 1 F, X7R ceramic decouple capacitor (C1) placed very close between VDD & GND pins to ensure the total harmonic distortion plus noise (THD+N) performance is as designed. This is also very important for efficiency and lowering noise floor. Another 100 F to 1000 F main decouple capacitor (C2) should be placed close to supply pin for low frequency Decoupling" The data sheet is at: http://www.datenblatt-pdf.com/pinout/606846/PAM8302-schematic.html I hope this helps.
Thanks for the great information! I will try your suggestions and report if they fixed the problem.
Sorry about the missing information about the Pam8302A board.
I use a board from adafruit which can be bought here https://www.adafruit.com/product/2130
Since the board looked like it already contained R and C I also tried using the audio signal without the 20kOhm+100nF but it soundless significant worse.
What I tried to realize was the "typical application circuit" with R=20k and according to C=1/(2π R f(=80 Hz) ), Ci=100 nF.
@gilshultz
Thank you for pointing me to the required components of the datasheet. However, it seems the PAM8302 datasheed differs a lot from the one of PAM8302A.
Also, I don't think it is a problem of harmonic distortion or noise floor, since this is a sudden periodic noise synced to the OLED communication.
I use a bypass capacitor, maybe a bit hard to see in the diagram, left next to the PAM8302A block (4.7µF) connecting 3.3V to GND.
To prevent misunderstanding regarding the noise, I made a short recording close to the speaker:
The noise is probably coming from the source, the WeMOS D1 Mini, since its supply will be very noisy being a digital logic chip. Try adding 1000uF 6.3V decoupling cap (or more) to its supply. Note that this can be problematic for USB powered devices as USB is not designed to drive large capacitive loads.
4.7uF is doing very little at audio frequencies, its impedance is pretty large at lower audio frequencies.
Thanks for the audio. Those are really bad pulses in the audio.
It seems to be a DC offset pulse. When looking at the pulses as a single pulse and ignoring the ringing after that, then a positive pulse is accompanied by a negative pulse about 104 or 108 ms later.
Thank you for trying everything, such as a software I2C.
It is not a interrupt problem, but I'm not 100% sure that it is not a software conflict.
@MarkT
Thanks for the suggestion! I have to order 1000 µF capacitors first until I can try it. I still have two 470 µF elkos here, though....
Would it help if I use a 50 ΅Ω resistor in line to limit current to below 100 mA at 5 V for the 1000 µF to work using USB?
If I use a LIPO with a charger board (03962A with TC4056A) will that also be a problem?
Do I need to modify the input power line, or would it work to decouple the output 5V with output-GND?
@Koepel
Thanks for the input!
I thought the capacitors in line to the amplifier board would remove the DC component... Would a different size there help?
I'm afraid the way the ESP8266Audio library creates the audio signal interferes with the I2C/SPI communication somehow on the chip.
I read it would work on a ESP32 or with ESP8266, but using a mp3 decoder board, like the VS1053. A decoder board seems a bit pricey (~25€) for the current project to me, though...
The ESP8266 or the OLED or the PAM module could suddenly draw more current, and if your grounding is not correct, then the amplifier gets the pulse in its differential inputs.
Even with good grounding, a pulse of 100mV in the GND is not extraordinary.
Audiophiles are very keen on using differential audio signals, but it has to be done right.
Suppose we call the GND pin of the ESP module the "real" ground. Then that is your reference for the real silent GND. If you connect a wire of 10cm to that, then you have no longer a real ground.
Pin 4 of the PAM module goes to 100nF and 20k and that is connected somewhere to GND. Can you try other GND points ?
A single PCB board has a ground plane. That solves most of these problems, unless very high frequencies are involved, because then the currents are more sensitive for inductive and capacitive coupling with other PCB traces.
The grounding does not have to be the cause of the audio clicks, but it could explain it.
I added two parallel 470 µF caps in series to a 90 Ω resistor to the 5 V and 3 V power output, but I could not hear any effect....
I tried shortening all connections, especially on the PAM. This should now all below 5 cm.
On the photo I use 200 nF for decoupling the PAM inputs since it sounded better (and connects better in the breadboard). Does not have an influence on the knocking sound, though.
You need to have separate power+ground wiring for the OLED and the PAM8302 module. The decoupling capacitors go next to the PAM8302 module.
The way you've wired it the noise source is closer to the PAM8302 than the decoupling caps, which is wrong, although I'm finding it hard to see some of the wires to be sure.
You may find this is not enough if the regulation of the supply is weak - there's a limit to how much work decoupling capacitors can do at the lower audio frequencies.
One approach commonly used is to have separate voltage regulators for the sensitive components and the noisy components - this breaks the link between them.
However you have 3 components - the OLED will generate noise as its updated due to the current it uses changing significantly with screen updates (its a bunch of LEDs basically).
The processor itself will generate switching noise (though probably much less as the currents involved are small).
The PAM module is sensitive to noise both on its inputs and the supply rail.
And I should also mention the USB supply itself can have significant noise to start with, although here its clear the OLED commands are the main source.
Or in short mixing digital and analog hardware is always tricky to do well, some experimentation is normal to figure out how best to reduce noise ingress.
Thanks for the suggestions!
Yes, this seems a bit tricky, but the little project offers a lot to learn and improve from (aside from "use higher quality parts ) .
I moved the 1 mF capacitor directly in front of the PAM module. I also connected an 03961A + LiPo, so the circuit runs from battery. This did not change the pulsed noise, just like you presumed.
Then I put the OLED GND and +3V pin to another 3V battery, also connecting the battery-GND to the "common" GND. However, the pulsed noise does not decrease. Also tried that on the PAM, but same result.
Then I used a voltage regulator (only have stepup-converters here, mt3608 MT3608 DC-DC Netzteil Adapter Step up Modul – AZ-Delivery , set to +4V) for the OLED, but no change.
Also set the stepup to the PAM, but still pulsed noise at the same volume.
Setting the ESP8266 or/and the OLED behind the stepup and only the PAM directly to the battery gives pulsed noise.
At this point, I think it might actually be the processor switching noise. When the OLED is unplugged the noise gets quiter, but is also still there...
Or does the decoupling via voltage regulators only work with a linear regulator?