The Raspi-Sonic-Hat is a sound card for the Raspberry Pi. It is based on the WM8731 I2S sound chip by Cirrus Logic (former Wolfson). The board design is a hybrid of the WM8731 datasheet, the Audio Codec Board - PROTO and the Audio Injector. That is why one can use the Audio Injector software.
This sound card features two line inputs and two line outputs.
blue = record in signal and yellow = play back signal of a Pure Data 440Hz wave from a laptop.
The board and the manual is made and tested for an Raspberry Pi 4 running Raspian Buster on it.
After connecting the Audio Injector to the Raspberry Pi some software should be installed.
First you have to download the deb package from http://forum.audioinjector.net/viewtopic.php?f=5&t=3.
$ wget https://github.com/Audio-Injector/stereo-and-zero/archive/master.zip
Unpack it:
$ unzip master.zip
And install it:
$ cd stereo-and-zero-master/ $ sudo apt install ./audio.injector.scripts_0.1-1_all.deb
Change some configurations, in:
$ sudo nano /boot/config.txt
Put in comment:
# dtparam=audio=on
And type in:
# Enable audio (WM8731) dtoverlay=audioinjector-wm8731-audio
ctl + o for saving, press return and ctl + x to leave.
Reboot your Raspberry Pi:
$ sudo reboot
To enable the audio output:
$ amixer set 'Output Mixer HiFi' on
Go into the folder:
$ cd stereo-and-zero-master/audio.injector.scripts-0.1/
To setup the output run the following command: In combination with the microphone input:
$ alsactl --file asound.state.MIC.thru.test restore
or in combination with the lines input:
$ alsactl --file asound.state.RCA.thru.test restore
to check the alsa setting:
$ alsamixer
For the 10 kHz test follow the instructions on https://github.com/Audio-Injector/stereo-and-zero.
Then install sox:
$ sudo apt install sox
In /home/pi/stereo-and-zero-master/ run:
$ sudo chmod 755 audioInjector-test.sh $ ./audioInjector-test.sh
Recording:
$ arecord -r 48000 -f S16_LE -c 2 -d 20 test.wav
Playing back:
$ aplay test.wav
Three pins for a electret microphone are marked: MIC IN, MIC BIAS and GND. One can connect a microphone like that:
C1 = 220pF, C2 = 1µF, R1 = 680 Ohm, R2 = 47k
The following pins are used by the sound card, don't use them for anything else!
Beside the power (5V and 3V3) and ground (GND) the I2S bus needs the following pins:
GPIO 18 (Pin12) BIT CLOCK (BCLK); GPIO 19 (Pin 35) IN and OUT LR CLOCK (DACLRC and ADCLRC); GPIO 20 (Pin 38) DATA IN (ADCDAT); GPIO 21 (Pin 40) DATA OUT (DACDAT);
And the I2C bus needs these pins:
GPIO 02 (pin 03) SDIN GPIO 03 (pin 05) SCLK
graphic from:
https://hifiduino.wordpress.com/2014/11/13/raspberry-pi-b-digital-audio/
Download the Python script:
$ wget www.dernulleffekt.de/programme/scripts.tar.xz
And unpack it:
$ tar -xf scripts.tar.xz
Go to in the script folder
$ cd /home/pi/scripts
Change owner & rights
$ sudo chown root:root shutdownbutton.py blink.py $ sudo chmod 755 shutdownbutton.py blink.py
Create the autostart:
$ sudo nano /etc/rc.local
Write before “exit 0”:
# run reset and shutdown script and the blink script printf ">>>>>>>> Starting shutdown aund reset button on GPIO 27 and a blinking LED on GPIO 04" /home/pi/scripts/shutdownbutton.py & /home/pi/scripts/blink.py &
To save and leave press: CTRL+O, Enter, CTRL+X
Reboot:
$ sudo reboot
https://statics.cirrus.com/pubs/proDatasheet/WM8731_v4.9.pdf
https://www.fredrikolofsson.com/f0blog/?q=node/656
https://www.mikroe.com/audio-codec-proto-board
http://www.audioinjector.net/rpi-hat
https://github.com/Audio-Injector/stereo-and-zero
https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp/raspberry-pi-usage
https://alsa-project.org/wiki/Main_Page
The Raspi-Sonic-Hat was designed by Wolfgang Spahn 2020.
It is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.