Template: WM8960 Audio HAT Guide
The guides can only be used with Raspberry Pi OS.
sudo apt-get update sudo apt-get upgrade
git clone https://github.com/waveshare/WM8960-Audio-HAT
Install WM8960 driver:
cd WM8960-Audio-HAT sudo ./install.sh sudo reboot
Check if the driver is installed.
sudo dkms status
pi@raspberrypi:~ $ sudo dkms status wm8960-soundcard, 1.0, 4.19.58-v7l+, armv7l: installed
Note: If the WM8960 Audio HAT has a noise problem, please reinstall the driver and test it again.
If the 3.5mm jack has no audio output, please run the following command to restart the service.
sudo systemctl restart wm8960-soundcard.service
Check the Soundcard
- Test playing：aplay -l
pi@raspberrypi:~ $ aplay -l **** List of PLAYBACK Hardware Devices **** card 0: wm8960soundcard [wm8960-soundcard], device 0: bcm2835-i2s-wm8960-hifi wm8960-hifi-0  Subdevices: 1/1 Subdevice #0: subdevice #0
- Test recording：arecord -l
pi@raspberrypi:~ $ arecord -l **** List of CAPTURE Hardware Devices **** card 0: wm8960soundcard [wm8960-soundcard], device 0: bcm2835-i2s-wm8960-hifi wm8960-hifi-0  Subdevices: 1/1 Subdevice #0: subdevice #0
record and play
sudo arecord -f cd -Dhw:0 | aplay -Dhw:0
After running the command, you can hear the sound recorded by mic from earphones or speakers. Note that the speaker should be away from the mic to void from noise.
sudo arecord -D hw:0,0 -f S32_LE -r 16000 -c 2 test.wav
test.wav is the file name outputed.
sudo aplay -Dhw:0 test.wav
Play the audio.
Adjust the volume
The default volume is small, and you can install the alsamixer to adjust it.
aplay command can only support wav files, if you want to play MP3 file, you can install the mpg123 tool:
sudo apt-get install mpg123 sudo mpg123 music.mp3
You can replace the music.mp3 with the actual file name.
smplayer for GUI controlling
Note that this software can only work for:
sudo apt-get install smplayer
We provide examples for testing.
- Install ibraries
sudo apt-get install libasound2-dev git clone https://github.com/larsimmisch/pyalsaaudio cd pyalsaaudio sudo python3 setup.py build sudo python3 setup.py install
- Download examples:
wget https://files.waveshare.com/upload/1/19/WM8960_Audio_HAT_Code.tar.gz tar zxvf WM8960_Audio_HAT_Code.tar.gz sudo chmod 777 -R WM8960_Audio_HAT_Code
sudo python playwav.py music.wav
sudo python recordwav.py out.wav
Replace the command at startup with the following:
ext4load mmc 1:3 a0000000 /boot/uEnv.txt env import a0000000 17c setenv fdtfile starfive/jh7110-visionfive-v2-wm8960.dtb sysboot mmc 1:3 ext2 b0000000 /boot/extlinux/extlinux.conf
202302 System, Driver Loading
Boot and enter the system, and input the commands:
Go to the system boot configuration file, comment out section 1, and add section 2:
Start to Use
apt install alsa-utils
If the module is not connected at the beginning, you need to restart VisionFive2 to detect the audio device.
Type aplay -l to list sound cards and digital audio devices.
Pay attention to the position marked on the picture, which indicates the device number of the sound card and digital audio equipment, where card0 and device0 are the headphone jacks on the VisionFive2 board, card0 and device2 are the headphone jacks on the WM8960 module.
Type arecord -l to list sound cards and recording devices.
Pay attention to the position marked on the picture, which indicates the device number of the sound card and recording device, card0 and device1 are the two patch microphones on the WM8960 module.
Input the command:
arecord -Dhw:0,1 -f S32_LE -r16000 -c2 -d 10 -t wav sound_32b_16k.wav
Start recording 10 seconds of 32-bit, 16kHz audio, and save it in the current directory, the file name is sound_32b_16k.wav.
input the command:
aplay -Dhw:0,2 -f S32_LE -r16000 -t wav sound_32b_16k.wav
Use the WM8960 module onboard headphone interface to play audio.
Note that the headphone jack on the VisionFive2 board only supports audio output in 16-bit audio format.