WM8960 Audio HAT

From Waveshare Wiki
Revision as of 13:18, 19 January 2022 by Waveshare-eng11 (talk | contribs)
Jump to: navigation, search
WM8960 Audio HAT
WM8960 Aydui HAT

WM8960 Stereo CODEC Audio Module, Low Power, Play/Record
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

This is a sound card HAT designed for Raspberry Pi, low power consumption, supports stereo encoding / decoding, features Hi-Fi playing / recording, what's more, it can directly drive speakers to play music.

Features

  • Standard Raspberry Pi 40PIN GPIO extension header, supports Raspberry Pi series boards
  • Integrates WM8960 low power stereo CODEC, communicates via I2S interface
  • Integrates dual high-quality MEMS silicon Mic, supports left & right double channels recording, nice sound quality
  • Onboard standard 3.5mm earphone jack, play music via external earphone
  • Onboard dual-channel speaker interface, directly drives speakers
  • Supports sound effects such as stereo, 3D surrounding, etc.

Specifications

  • CODEC: WM8960
  • Power supply: 5V
  • Logic voltage: 3.3V
  • Control interface: I2C
  • Audio interface: I2S
  • DAC signal-noise ratio: 98dB
  • ADC signal-noise ratio: 94dB
  • Earphone driver: 40mW (16Ω@3.3V)
  • Speaker driver: 1W per channel (8Ω BTL)

Dimension

WM8960-Audio-HAT-size.jpg

The guides can only be used with Raspberry Pi OS

Install Driver

Update system:

sudo apt-get update
sudo apt-get upgrade

:Clone driver

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
[email protected]:~ $ 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
[email protected]:~ $ 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
[email protected]:~ $ 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

Test record/play

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

Record

sudo arecord -D hw:0,0 -f S32_LE -r 16000 -c 2 test.wav

test.wav is the file name outputed

Play

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

sudo alsamixer

If WM8960 is not the default sound card, you should press F6 to choose an audio device.
Wm8960 audio hat alsamixer.png


mpg123 palyer

aplay command can only support wav file, if you want to paly MP3 file, you can install 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

Right click and set the wm8960-soundcard as default device
Wm8960 audio hat smplayer.png
Open the smplayer software in Menu, choose a audio fiel and play
Wm8960 audio hat smplayer2.png
Wm8960 audio hat smplayer3.png

Examples

We prvide 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 http://www.waveshare.com/w/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
  • Play
sudo python playwav.py music.wav
  • Record
sudo python recordwav.py out.wav

FAQ

 Answer:
  • Check the kernel version first
uname -a
  • If the kernel version of your system is lower than 5.0 (that is, the Raspberry Pi system version is before 2020-05-27), please download the following driver:
git clone -b rpi-4.9.y https://github.com/waveshare/WM8960-Audio-HAT.git
  • If the kernel version is higher than 5.0, please download the following driver:
git clone https://github.com/waveshare/WM8960-Audio-HAT

【Note】Please do not run both of the above two commands!

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
Please run the following command to restart the sound card service and test it again.
sudo systemctl restart wm8960-soundcard.service
{{{3}}}
{{{4}}}

{{{5}}}


Support

Support

If you require technical support, please go to the Support page and open a ticket.