cmangla
Posts: 12
Joined: Tue Apr 11, 2023 7:26 am

Pi Zero W with Codec Zero not working, help needed

Thu May 18, 2023 6:32 pm

I have a fairly new Pi Codec Zero, RPi Zero W and latest Raspbian Lite 32bit. I cannot get the "Extra Codec Zero configuration" steps at https://www.raspberrypi.com/documentati ... figuration to work.

As directed in the official docs, I have `#dtparam=audio=on` commented out in `/boot/config.txt`, and I rebooted after that. I ran `raspi-config` and selected the Codec Zero HAT for audio option. The HAT is detected by the kernel:

Code: Select all

$ grep -a . /proc/device-tree/hat/*
/proc/device-tree/hat/name:hat
/proc/device-tree/hat/product:Raspberry Pi Codec Zero
/proc/device-tree/hat/product_id:0x0101
/proc/device-tree/hat/product_ver:0x0001
/proc/device-tree/hat/uuid:7c582b02-e8d3-4142-976d-24290cc45f3f
/proc/device-tree/hat/vendor:Raspberry Pi Ltd.
I downloaded the alsa config scripts from the git repository noted in the docs and the step after that is what fails:

Code: Select all

$ sudo alsactl restore -D Zero -f Pi-Codec-master/IQaudIO_Codec_OnboardMIC_record_and_SPK_playback.state 
No state is present for card Zero
alsa-lib main.c:1014:(snd_use_case_mgr_open) error: failed to import hw:1 use case configuration -2
Found hardware: "RPi_Codec_Zero" "" "" "" ""
Hardware is initialized using a generic method
No state is present for card Zero
It is the same issue with all four `.state` files.

I noticed that a similar issue was mentioned by people using the pre-rebranding IQaudIO Codec Zero. It seems my issue is different. I have a fairly new, post-rebrand Codec Zero (from the Pi shop in Cambridge!), and it is detected correctly as so by the kernel.

Some more diagnostics:

Code: Select all

$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault
    Default Audio Device
default
output
hw:CARD=vc4hdmi,DEV=0
    vc4-hdmi, MAI PCM i2s-hifi-0
    Direct hardware device without any conversions
plughw:CARD=vc4hdmi,DEV=0
    vc4-hdmi, MAI PCM i2s-hifi-0
    Hardware device with all software conversions
sysdefault:CARD=vc4hdmi
    vc4-hdmi, MAI PCM i2s-hifi-0
    Default Audio Device
hdmi:CARD=vc4hdmi,DEV=0
    vc4-hdmi, MAI PCM i2s-hifi-0
    HDMI Audio Output
dmix:CARD=vc4hdmi,DEV=0
    vc4-hdmi, MAI PCM i2s-hifi-0
    Direct sample mixing device
hw:CARD=Zero,DEV=0
    RPi Codec Zero, Raspberry Pi Codec Zero HiFi da7213-hifi-0
    Direct hardware device without any conversions
plughw:CARD=Zero,DEV=0
    RPi Codec Zero, Raspberry Pi Codec Zero HiFi da7213-hifi-0
    Hardware device with all software conversions
sysdefault:CARD=Zero
    RPi Codec Zero, Raspberry Pi Codec Zero HiFi da7213-hifi-0
    Default Audio Device
dmix:CARD=Zero,DEV=0
    RPi Codec Zero, Raspberry Pi Codec Zero HiFi da7213-hifi-0
    Direct sample mixing device

$ arecord -L
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault
    Default Audio Device
default
output
hw:CARD=Zero,DEV=0
    RPi Codec Zero, Raspberry Pi Codec Zero HiFi da7213-hifi-0
    Direct hardware device without any conversions
plughw:CARD=Zero,DEV=0
    RPi Codec Zero, Raspberry Pi Codec Zero HiFi da7213-hifi-0
    Hardware device with all software conversions
sysdefault:CARD=Zero
    RPi Codec Zero, Raspberry Pi Codec Zero HiFi da7213-hifi-0
    Default Audio Device
dsnoop:CARD=Zero,DEV=0
    RPi Codec Zero, Raspberry Pi Codec Zero HiFi da7213-hifi-0
    Direct sample snooping device
Does anyone else have this specific combination (Pi Zero W + Codec Zero) working?

Any help will be much appreciated!

cmangla
Posts: 12
Joined: Tue Apr 11, 2023 7:26 am

Re: Pi Zero W with Codec Zero not working, help needed

Thu May 18, 2023 6:43 pm

Based on a reply I got from another forum, using `alsactl store` instead of `restore` on the initial run does not throw up errors:

Code: Select all

sudo alsactl store -D Zero -f Pi-Codec-master/IQaudIO_Codec_OnboardMIC_record_and_SPK_playback.state
I'm testing the rest of the instructions just now.

cmangla
Posts: 12
Joined: Tue Apr 11, 2023 7:26 am

Re: Pi Zero W with Codec Zero not working, help needed

Thu May 18, 2023 7:03 pm

After getting past that issue, I setup `.asoundrc` as required:

Code: Select all

$ cat ~/.asoundrc 
pcm.!default {
        type hw
        card Zero
}
But now `aplay` errors:

Code: Select all

$ aplay A.wav 
Playing WAVE 'A.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
aplay: pcm_write:2058: write error: Input/output error
Any suggestions for this?

cmangla
Posts: 12
Joined: Tue Apr 11, 2023 7:26 am

Re: Pi Zero W with Codec Zero not working, help needed

Fri May 19, 2023 4:34 pm

Right, I made some more progress with this. It seems `aplay` needs the `-D sysdefault` argument to not error out:

Code: Select all

root@audpi:~# aplay -vvv -D sysdefault  /usr/share/sounds/alsa/Noise.wav
Playing WAVE '/usr/share/sounds/alsa/Noise.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Plug PCM: Route conversion PCM (sformat=S16_LE)
  Transformation table:
    0 <- 0
    1 <- 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 1
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 24000
  period_size  : 6000
  period_time  : 125000
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 6000
  period_event : 0
  start_threshold  : 24000
  stop_threshold   : 24000
  silence_threshold: 0
  silence_size : 0
  boundary     : 1572864000
Slave: Hardware PCM card 0 'RPi Codec Zero' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 24000
  period_size  : 6000
  period_time  : 125000
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 6000
  period_event : 0
  start_threshold  : 24000
  stop_threshold   : 24000
  silence_threshold: 0
  silence_size : 0
  boundary     : 1572864000
  appl_ptr     : 0
  hw_ptr       : 0
Max peak (6000 samples): 0x00001029 ###                  12%
Max peak (6000 samples): 0x00000f54 ###                  11%
Max peak (6000 samples): 0x00000fb3 ###                  12%
Max peak (6000 samples): 0x00000d30 ###                  10%
That's how it is running now but I don't get any sound from the speakers I've connected to the terminals. I don't have an oscilloscope, but I couldn't see any voltage on the speaker terminal pins using my multi-meter, which might not mean much. I double-checked and I am using `IQaudIO_Codec_OnboardMIC_record_and_SPK_playback.state` with `alsactl`.

What can I try next?

frodojj
Posts: 4
Joined: Mon May 22, 2023 11:45 pm

Re: Pi Zero W with Codec Zero not working, help needed

Tue May 23, 2023 1:39 am

So I got my IQaudIO Codec Zero to work. I know you got the newer Raspberry Pi version, but maybe the steps I did can help.

1. First, with a fresh /boot/config.txt, add the line dtoverlay=iqaudio-codec and comment out the line dtparam=audio=on Do not add dtoverlay= before the sound card overlay, even though the official instructions say to use it.

2. Clone the repository with git clone https://github.com/iqaudio/Pi-Codec.git

3. Add to /etc/rc.local

Code: Select all

sudo alsactl restore -f /home/pi/Pi-Codec/IQaudIO_Codec_OnboardMIC_record_and_SPK_playback.state
If your user is not pi then replace that with your user name/directory.

4. Edit .asoundrc in your user directory and add the following

Code: Select all

pcm.!default {
  type hw
  card IQaudIOCODEC
}
This worked for me. Testing with speaker-test -c2 should output white noise. You need to use 2 channels even though you are using mono output. I don't know why.

For the Raspberry Pi card, you could try using dtoverlay=rpi-codeczero instead of iqaudio-codec even though the instructions say you don't need that line. Also, use card Zero instead of IQaudIOCODEC. If those don't work, you could try adding dtoverlay= before the overlay, but I think that might make it not work.
Last edited by frodojj on Tue May 23, 2023 2:00 am, edited 3 times in total.

cmangla
Posts: 12
Joined: Tue Apr 11, 2023 7:26 am

Re: Pi Zero W with Codec Zero not working, help needed

Tue May 23, 2023 11:33 am

cmangla wrote:
Thu May 18, 2023 6:43 pm
Based on a reply I got from another forum, using `alsactl store` instead of `restore` on the initial run does not throw up errors:

Code: Select all

sudo alsactl store -D Zero -f Pi-Codec-master/IQaudIO_Codec_OnboardMIC_record_and_SPK_playback.state
I realise now that this is just silly. The `store` command just stores something in the `.state` file, which is not what we are trying to achieve.

cmangla
Posts: 12
Joined: Tue Apr 11, 2023 7:26 am

Re: Pi Zero W with Codec Zero not working, help needed

Tue May 23, 2023 11:35 am

frodojj wrote:
Tue May 23, 2023 1:39 am
1. First, with a fresh /boot/config.txt, add the line dtoverlay=iqaudio-codec and comment out the line dtparam=audio=on Do not add dtoverlay= before the sound card overlay, even though the official instructions say to use it.

2. Clone the repository with git clone https://github.com/iqaudio/Pi-Codec.git

3. Add to /etc/rc.local

Code: Select all

sudo alsactl restore -f /home/pi/Pi-Codec/IQaudIO_Codec_OnboardMIC_record_and_SPK_playback.state
If your user is not pi then replace that with your user name/directory.
Thanks @frodojj . I tried following your suggestions and its variations but I still get an error when I try the `alsactl restore` command.

frodojj
Posts: 4
Joined: Mon May 22, 2023 11:45 pm

Re: Pi Zero W with Codec Zero not working, help needed

Tue May 23, 2023 12:27 pm

I'm sorry it didn't work for you. The documentation says that the Raspberry Pi audio hats should "just work" with the full Raspberry Pi OS (the one with the desktop environment). Does your hat work with a fresh install of the full OS with a monitor, keyboard and mouse attached? At least you could rule out hardware problems if it does work.

cmangla
Posts: 12
Joined: Tue Apr 11, 2023 7:26 am

Re: Pi Zero W with Codec Zero not working, help needed

Thu May 25, 2023 4:25 pm

frodojj wrote:
Tue May 23, 2023 12:27 pm
Does your hat work with a fresh install of the full OS with a monitor, keyboard and mouse attached? At least you could rule out hardware problems if it does work.
I might get around to trying the full OS with the GUI at some point. I have low confidence in it though, because it will still need the `alsactl restore` command to work for the codec zero. Everything in the headless setup seems to be fine until that point. The HAT shows up in `/proc/` as it should.

It would be good to hear from anyone who got the new Codec Zero working. So far, all the replies I've got and all the other posts I've found only refer to the IQaudIO branded boards.

cmangla
Posts: 12
Joined: Tue Apr 11, 2023 7:26 am

Re: Pi Zero W with Codec Zero not working, help needed

Thu May 25, 2023 4:36 pm

Actually, I've had a bit of a breakthrough. I edited the files in `iqaudio/Pi-Codec.git` and replaced "IQaudIOCODEC" with "Zero" and I got sound out of it for the first time!

cmangla
Posts: 12
Joined: Tue Apr 11, 2023 7:26 am

Re: Pi Zero W with Codec Zero not working, help needed

Thu May 25, 2023 6:06 pm

cmangla wrote:
Thu May 25, 2023 4:36 pm
Actually, I've had a bit of a breakthrough. I edited the files in `iqaudio/Pi-Codec.git` and replaced "IQaudIOCODEC" with "Zero" and I got sound out of it for the first time!
This actually seems to be the solution for now, until the files in that repository are updated.


Return to “HATs and other add-ons”