Let's say I am trying to embed a Pi WH in my motorcycle helmet. I need thin speakers just by the ear to hear sounds (so, I don't need them to be too loud).
* by the way, piezo speakers won't do it in this project
Since Pi WH doesn't have a 3.5mm audio jack, I think my choices are
- use USB speakers
- use PWM + audio amplifier + speakers
I can certainly buy a set of USB speakers and just connect to it, but the size matters. so I am thinking #2 would only be my choice.
As far as I researched, I think this is the way to go.
setup
Option 1. Use Device Tree Overlay
https://learn.adafruit.com/adding-basic-audio-ouput-to-raspberry-pi-zero/pi-zero-pwm-audioconnect a LM386 audio amplifier to one of the PWM pins
- RPi 5v pin -> VCC
- RPi ground -> GND
- RPi a PWM pin -> IN
- RPi ground -> GND
connect speakers like this to the audio amplifier
remove noises by this config
audio_pwm_mode=2
play sounds by
aplay
command
Please let me know if any of the steps are wrong before I go ahead and buy all of the parts.
update:
I did the followings to just make sure a speaker without an amplifier would sound just enough.. but I hear nothing coming out of the speaker, not even a noise. It's complete silence. Anything I am missing or not doing right?
- add
dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4
to /boot/config.txt
dtparam=audio=on
is not commented sudo raspi-config
-> Advanced Options -> Audio -> Force 3.5mm ('headphone') jack- reboot
gpio readall
shows
ALT5 | GPIO. 1 | 1 | 18
and
| 13 | 23 | GPIO.23 | ALT0
alsamixer
and set the volume 100%- hooked a speaker like this (PWM0 = stereo right channel?)
aplay /usr/share/sounds/alsa/Rear_Center.wav
ormpg321 some.mp3