Lusya/audiophonics ADC for Pi

caveat...I'm an older audiophile and Linux user. I claim no coding skills and won't be supporting this how-to and any querys. However, it does work for me today and, as has been said before on this forum, 'even a blind squirrel sometimes finds a nut" 🙂

ADC Analog to Digital Converter AKM5720 I2S 24Bit / 96kHz - Audiophonics
Lusya lossless digital audio I2S ADC decoder Support 24bit 96K I2S Signal output A1 003|Digital-to-Analog Converter| - AliExpress

This walk through should set-up the above mentioned ADCs for recording.
Connection to the ADC is as for an i2s dac but changing the default Pi output GPIO Data pin to the Pi Data input GPIO pin...look up the GPIO pins for those.

The setup script will auto-detect your Pi model. I used a Pi2B with no other peripherals attached.
I am assuming you have a little Linux knowledge and are running a Linux PC.

Download Raspberry Pi O/S lite
Operating system images – Raspberry Pi

Burn to a micro-sd card using Balena Etcher
balenaEtcher - Flash OS images to SD cards & USB drives

With the micro-sd card still in your computer write an empty file titled ssh to the boot partition of the card. Option #3...
SSH (Secure Shell) - Raspberry Pi Documentation

Eject the card and insert it into your Pi (ethernet wired) then boot.

ssh to your Pi from another PC and follow the prompt to change the password.

Run..
Code:
sudo raspi-config
and in the Advanced tab select to Expand the filesystem. Exit raspi-config but don't reboot yet.
Run...
Code:
sudo nano /boot/config.txt
and uncomment this line to read..
Code:
dtparam=i2s=on
Save and exit.

Now reboot and log back in.
Do both..
Code:
sudo apt-get -y update
sudo apt-get -y upgrade
Then reboot and log back in and..
Code:
sudo apt install python3-pip
then..
Code:
cd ~
sudo pip3 install --upgrade adafruit-python-shell
wget [url]https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2smic.py[/url]
and finally...
Code:
sudo python3 i2smic.py

When that's all done reboot, log back in and ..
Code:
sudo nano Raspberry-Pi-Installer-Scripts/i2s_mic_module/snd-i2smic-rpi.c
and change this line..
Code:
.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS,
to read..
Code:
.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM,

save and then rerun the installer script..
Code:
sudo python3 i2smic.py

reboot log in and run ..
Code:
arecord -l
output should be...
Code:
**** List of CAPTURE Hardware Devices ****
card 1: sndrpii2scard [snd_rpi_i2s_card], device 0: simple-card_codec_link snd-soc-dummy-dai-0 [simple-card_codec_link snd-soc-dummy-dai-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

then run ..
Code:
arecord -L
output should be..
Code:
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=sndrpii2scard
    snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
    Default Audio Device
sysdefault:CARD=sndrpii2scard
    snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
    Default Audio Device
dmix:CARD=sndrpii2scard,DEV=0
    snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
    Direct sample mixing device
dsnoop:CARD=sndrpii2scard,DEV=0
    snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
    Direct sample snooping device
hw:CARD=sndrpii2scard,DEV=0
    snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
    Direct hardware device without any conversions
plughw:CARD=sndrpii2scard,DEV=0
    snd_rpi_i2s_card, simple-card_codec_link snd-soc-dummy-dai-0
    Hardware device with all software conversions

If that is all good try recording with..
Code:
arecord -D sysdefault:CARD=1 -c2 -f S32_LE -r 96000 --vumeter=stereo test.wav
which should give (with no input to the adc card yet) the following output and a basic vu meter showing 00% for both channels. (ctrl + c to stop)
Code:
Recording WAVE 'test.wav' : Signed 32 bit Little Endian, Rate 96000 Hz, Stereo
                                  +00%|00%+

Connect a source to the card and adjust the #1 dip-switch for gain then rerun the recording command with some content playing.

With much thanks to forum member Phofman posts 7 & 9 here..
SBC with I2S codec drivers for playing/recording

and the information from this site..
Raspberry Pi Wiring & Test | Adafruit I2S MEMS Microphone Breakout | Adafruit Learning System

If IIUC the set-up above uses the scripts for an i2s device (microphone) modified to work with the ADC by changing it from slave to master mode ( CBS_CFS to CBM_CFM)

You will most probably need a Pi4 with 4GB ram (or better) (or set up a ram-drive for lesser Pi. I did this to allow one side of an LP to be recorded then moved the files to my PC ...rinse and repeat.)
To send the audio elsewhere in real time you may need to research piping to external devices or over the network.
 
Last edited:
Hi Drone7.

Thanks a lot for having sorted out this tricky connexion of a WM8782 ADC to a RPi. Until now, the only way to inject audiophile analog to the Pi was using the HifiBerry DAC+ADC Hat. Very limiting if you already hook a high quality dac and only wanted to get the ADC feature.

I wondered if you could provide the pin connexion scheme between the I2S output of the card and the GPIO pins of RPi.

My intention is to benefit from the « analog input » feature of paid Volumio subscription to inject turntable audio in the system and correct it with FIR convolution filters before decoding in the DAC. Until now, only the digitally sourced music was benefiting from the DSP enhancement.

cheap DSP modules use most of the time low quality ADC and DAC chips with DSP limited to parametric correction, so I assume the proposed workflow should provide a higher quality output.

Thanks a lot for the connexion info you may provide.

Benoit
 
Hello Benoit
The connections are as follows From the ADC to the Pi.
VCC to 5vPWR(Pin2). ------ Mute = not connected.------- GND to GND(pin6).------ LRCK to GPIO19(pin 35).----- DATA to GPIO20(Pin 38). ------ BCLK to GPIO18(Pin 12)

Use the white jumper that ships with the board to connect MCLKin to the CLOCKout on the ADC.

_IGP2730-1024x1024.JPG

https://learn.microsoft.com/en-us/windows/iot-core/learn-about-hardware/pinmappings/pinmappingsrpi

All the best for your experiment. You will be using the DSP function to adjust for RIAA ?
 
Last edited:
Thanks for the connexion details, Drone7.
No I do not intend to RIAA compensate the raw turntable signal. I will use the turntable preamp signal (so already « RIAA reformatted ») and use CamillaDSP to correct for room and drivers irregularities.

When you digitalize your LP’s what frequency do you use : 48-96-192 KHz?

Cheers,

Benoit
 
I record at 96KHz/24Bit WAV using an RME Card in an HP thinclient and linear supply. Split to tracks with wavbreaker. Process for clicks pops and crackle with ClickRepair then adjust for levels,naming, etc in Audacity and export as .wav.
Often I can then load the resulting tracks into Musicbrainz and do a sigscan to get useful metadata and artwork. If not then I can convert to flac and try the same with beets for metadata and discogs for artwork.
 
I get the card and the connexion properly done.
Unfortunately, It seems I get stuck with a missing file preventing the script to properly compile the driver : /lib/modules/5.10.92-v7l+/build.

I followed all the steps but starting from the Debian coming with Volumio (updated and upgraded though).

Any thought? As I want the ADC to work on Volumio…

I could try anything you propose to testw

Benoit
 
Hi!
Thank you @DRONE7 for the excellent writeup! However...I'm on a RPi5 4GB running Raspberry Pi OS Bookworm 64bit and I'm getting errors.
sudo pip3 install --upgrade adafruit-python-shell
Does not work and in effect I cannot execute:
sudo python3 i2smic.py
So I opened i2smic.py and executed all commands by hand as best as possible, but I'm not getting any sound recording devices listed when I execute:
arecord -l
or
arecord -L

Can you help me out?
 
I forgot to specify the errors I was getting. So here you go:
error: externally-managed-environment


× This environment is externally managed

╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
For more information visit http://rptl.io/venv

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.

hint: See PEP 668 for the detailed specification.
Also, in the i2smic.py script the RPi5 is not recognized, so the script would exit if it would actually run, but this can be overcome I believe to edit the script.
 
Good morning,

My first post on this forum... and yes.. reviving an older thread since I happened to find this post very useful but it's needs some updates on newer rpi releases to work. So here we go:

I am running this on a Raspberry Pi 4, with the next OS specs, either 64- or 32bit, both found to be working:

Code:
PRETTY_NAME="Raspbian GNU/Linux 12 (bookworm)"

NAME="Raspbian GNU/Linux"

VERSION_ID="12"

VERSION="12 (bookworm)"

VERSION_CODENAME=bookworm



64bit kernel config:

Linux raspberrypi 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux

OR

32 bit kernel config:

Linux raspberrypi 6.6.51+rpt-rpi-v7l #1 SMP Raspbian 1:6.6.51-1+rpt3 (2024-10-08) armv7l GNU/Linux

arm_64bit=0 in /boot/firmware/config.txt


the next part of the tutorial needs some modification:
Code:
cd ~
sudo pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2smic.py

Nowadays they want us to use virtual environments on python, so do next:

In a terminal type the next to install the 'venv' python module

Code:
pip install venv

Then create a python virtual environment like next:

Code:
python -m venv my-venv

Then activate the virtual python environment:

Code:
source my-venv/bin/activate

After this activation all python related command must be executed from my-env/bin (all python roads point to my-env), so:

installing the adafruit python shell module:

Code:
sudo ~/my-env/bin/pip install --upgrade adafruit-python-shell

or executing the i2smic.py script

Code:
sudo ~/my-env/bin/python i2smic.py

The last thing that needs a change for the i2mic kernel module to compile successfully (this is done when the i2smic.py script runs) is that a struct name changed in the kernel source which gives errors on the current source code included in ~/Raspberry-Pi-Installer-Scripts/i2s_mic_module/snd-i2smic-rpi.c

Change the next to lines in ~/Raspberry-Pi-Installer-Scripts/i2s_mic_module/snd-i2smic-rpi.c:

Code:
From:
static struct simple_card_info card_info;

To:
static struct asoc_simple_card_info card_info;

and

Code:
From:
static struct simple_card_info default_card_info = {

To:
static struct asoc_simple_card_info default_card_info = {

and

Code:
From:
  .daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS,
 
To:
  .daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFM,

With the python virtual environment usage and the changes in the snd-i2smic-rpi.c you should be able to get the i2s stuff up and running in no time.

To drop out of you're python virtual environment and continue normal life, type next in a terminal:
Code:
cd ~/my-env/bin
deactivate

Good luck!
 
Honestly I would prefer running the commands executed by https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/main/i2smic.py directly, one by one, watching their output and learning what's going on, instead of having to create a python environment to run a python script which will exec the couple of shell commands at once. But that's just my mode of operation.

But please correct me if I am wrong:

Code:
From: 
.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS, 
To: 
.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFM,
Switching daifmt to SND_SOC_DAIFMT_CBS_CFM is rather unusual. It means that the codec is slave for the bitclock and master for the frame clock.

WM8782 datasheet does not seem to describe such mode being supported:

1732881895675.png


Based on the daifmt bitmap the I2S DAI/interface driver for RPi will configure its I2S pins. RPi4 can configure bclk and lrclk pins as master/slave independently :
https://github.com/torvalds/linux/b...0a8b795/sound/soc/bcm/bcm2835-i2s.c#L386-L412 -> https://github.com/torvalds/linux/b...0a8b795/sound/soc/bcm/bcm2835-i2s.c#L540-L546 . Unlike RPi5 which allows LRCLK + BLCK as master or slave only (like WM8782).

Therefore I am surprised your config works OK with no glitches as it seems to configure RPi bclk as output (driving against the codec bclk output) and lrclk as input (correctly reading the codec lrclk output). I can imagine if the RPi clock and codec clock were close to each other (by chance, as they are independent), the two bclks would run quite similarly and no glitches would happen for a while.
 
  • Like
Reactions: DRONE7