balena-io-experimental / balena-sound

Build a single or multi-room streamer for an existing audio device using a Raspberry Pi! Supports Bluetooth, Airplay and Spotify Connect
https://balena.io/blog/turn-your-old-speakers-or-hi-fi-into-bluetooth-receivers-using-only-a-raspberry-pi/
MIT License
2.43k stars 430 forks source link

Add support for Waveshare WM8960 DAC HAT #264

Open lahramon opened 4 years ago

lahramon commented 4 years ago

I would like to use the Waveshare WM8960 Audio HAT for the Raspberry Pi Zero W running BalenaSound and would love to see it appearing on the list of supported DACs!

I have taken a look at the installation manual but do not know how to install the drivers on the Balena OS.

Any support regarding the matter would be greatly appreciated!

AlexProgrammerDE commented 4 years ago

@AnomahR after taking a look at the installation programm i found this: wm8960-soundcard can you please set this as your dtoverlay? Please let me know if it works

lahramon commented 4 years ago

@AlexProgrammerDE Thanks for your quick response! After setting the BALENA_HOST_CONFIG_dtoverlay parameter to wm8960-soundcard, I got the following error messages: dtoverlay_wm8960-soundcard.txt

Also I tried to connect via bluetooth and Spotify Connect but neither way I could hear any sound. The usual "bluetooth-connecting" sound was not played aswell.

Hope that helps!

cryptoAlgorithm commented 4 years ago

I hope that this can be fully working soon as I also have this HAT lying around somewhere and would like to try it out for lower noise and higher volume.

lahramon commented 4 years ago

Three days of not doing what I was intended to later I finally made it work! Not the most elegant solution but it works for my Pi Zero W with the WM8960 DAC HAT. In case it might be helpful here is how I did it:

  1. Added the wm8960-soundcard.dtbo to the overlays folder of the image before flashing it to the SD card (see instructions. Furthermore before flashing, I added the following lines to the config.txt file in the boot partition of the image:
dtparam=i2s=on
dtoverlay=i2s-mmap
dtoverlay=wm8960-soundcard
  1. Installed the remaining drivers in a Docker container and added it to my fork of the BalenaSound project. Pushed the current state on GitHub here: https://github.com/AnomahR/balena-sound. The additional container has its own repository: https://github.com/AnomahR/WM8960-Audio-HAT.

  2. After deploying the project to my Pi Zero, I changed the DT parameters as suggested in the DAC configuration: For the DT parameter, "audio=off" and then I set the custom configuration variable BALENA_HOST_CONFIG_dtoverlay to "wm8960-soundcard".

Thats it! Unfortunately there is no sound when I connect to this specific Pi via Spotify Connect (but it still plays sound if I connect to my other Raspberry using Spotify Connect), maybe you have a clue what could cause the problem? Also not optimal: Now this additional container is installed on all other devices doing nothing... definitely looking forward to the DAC HAT being "officially" supported!

kevincastejon commented 4 years ago

I'm also highly interested on using that hat, i'm sad to read that the workaround above does not allow Spotify Connect cause it's the main usage of my project...

tmigone commented 4 years ago

hey @AnomahR , from your notes I think you should be able to get the DAC to work following this instructions but using both dtoverlays as such:

BALENA_HOST_CONFIG_dtoverlay="i2s-mmap", "wm8960-soundcard"

It also should not affect the Spotify Connect usage at all, so maybe there is something else going on there.

kevincastejon commented 4 years ago

@tmigone I just tried that config but still no sound after reboot...

lahramon commented 4 years ago

@tmigone You are right about the initial Spotify issues which turned out not to be related to the soundcard. Eventually I got everything to work using my additional container that installs the required kernel module (see repo above), but then realized my soundcard also had a hardware issue, meaning I had to send it back and cannot test your suggested configuration unfortunately. But I will definitely try it once I have the soundcard again!

@kevincastejon Did you modify the config only did you also install the kernel modules following the instructions above?

kevincastejon commented 4 years ago

@AnomahR Actually I just changed the config, I have to say I don't really know to proceed the steps you mentionned above with docker and stuff... is there a tutorial of some kind about it? Or maybe can I use your repo? Edit : I followed the steps to add the dtbo file and modify the config.txt into a fresh balenasound image, flashed that iamge and put it on raspberry, then I deploy using your github repo (i know nothing about docker...). After updating, modifying config into balena interface and rebooting, I still have no sound at all and plenty of errors : ` 09.09.20 16:53:16 (+0200) bluetooth-audio ALSA lib confmisc.c:767:(parse_card) cannot find card '0'

09.09.20 16:53:16 (+0200) bluetooth-audio ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory

09.09.20 16:53:16 (+0200) bluetooth-audio ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings

09.09.20 16:53:16 (+0200) bluetooth-audio ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory

09.09.20 16:53:16 (+0200) bluetooth-audio ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name

09.09.20 16:53:16 (+0200) bluetooth-audio ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

09.09.20 16:53:16 (+0200) bluetooth-audio ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory

09.09.20 16:53:16 (+0200) bluetooth-audio ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default

09.09.20 16:53:16 (+0200) bluetooth-audio /usr/bin/bluealsa-aplay: Couldn't open PCM: No such file or directory `

lahramon commented 4 years ago

To me this looks like the config was correct but there are still driver issues.

Which hardware are you using? Tested the repo on my Raspberry Pi Zero W with the kernel version 4.19. Waveshare just released new drivers for the kernel version 5.4 but in my repository the older version is still used.

You can check your kernel version when you SSH into the wm8960-soundcard Docker container (from the balena dashboard) by typing

uname -r

To test if the soundcard is detected at all, could you give the output of

aplay -l?

kevincastejon commented 4 years ago

@AnomahR thx for helping, I used the Balena dashboard terminal interface (targeting Host OS), I'm not sure that's what you mean by "SSH into the wm8960-soundcard" when I type uname -r I got this : 4.19.118 when I type aplay -l I got this : bash: aplay: command not found

jellyfish-bot commented 4 years ago

[tmigone] This issue has attached support thread https://jel.ly.fish/78237442-c266-4724-b9b4-ffd83058fe3e

shawaj commented 3 years ago

@kevincastejon you need to add the dt overlay for the card before applying the settings in balenaCloud.

Once you have programmed the SD card you can just add the wm8960-soundcard.dtbo file to resin-boot/overlays folder.

By the way, for the aplay -l command you would need to run that in a terminal window in the audio container.

shawaj commented 3 years ago

Possible duplicate of #166 as both use the WM8960 chip. Will need testing though

shawaj commented 3 years ago

Added a PR for the overlay for this to the upstream kernel https://github.com/raspberrypi/linux/pull/4039

@AnomahR @kevincastejon @cryptoAlgorithm - might need your help testing this when it gets pulled in, as I don't currently have one of these cards available

cryptoAlgorithm commented 3 years ago

Ok sure i have the hat and zero unused so i can install and test it out.

shawaj commented 3 years ago

@cryptoAlgorithm awesome - will keep you up to date on when the update is pulled in upstream

cryptoAlgorithm commented 3 years ago

Thanks, always ready to help!

shawaj commented 3 years ago

good news - this has been pulled into the upstream kernel https://github.com/raspberrypi/linux/pull/4039

will take a bit of time to filter down into here, however it should be possible for you to pull in the overlay manually once it hits the raspberry pi firmware. or you could build the .dtb yourself and pull it in but that is a bit more involved.

shawaj commented 3 years ago

Interestingly, the Adafruit Voice Bonnet also uses this same wm8960 driver as you can see from this page - https://learn.adafruit.com/adafruit-voice-bonnet/audio-setup

It will be interesting to see if anybody has this so we can test it.

shawaj commented 3 years ago

@AnomahR @kevincastejon @cryptoAlgorithm this is now in the raspberry pi firmware - https://github.com/raspberrypi/firmware/blob/master/boot/overlays/wm8960-soundcard.dtbo

shawaj commented 3 years ago

Added the overlay to the PR here - https://github.com/balena-os/balena-raspberrypi/pull/585/files