Raspi-Sonic-Hat


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.


Paper PCB

Parts

  • Resistors:
  • 4x 33 Ohm
  • 2x 100 Ohm
  • 1x 1 kOhm
  • 2x 1.3 kOhm
  • 4x 5.6 kOhm
  • 2x 47 kOhm
  • Capacitors:
  • 2x 22 pF
  • 2x 220 pF
  • 2x 100 nF
  • 2x 1 µF
  • 5x 10 µF
  • Diodes:
  • 1x LED
  • Inductor
  • 1x 10µH
  • Cristal
  • 1x 12 MHz
  • Semiconductors
  • 1x LD1117V33 (3V3 version!)
  • 1x WM8731
  • Mechanical:
  • 1x SMD adapter board 28 pins
  • 2x pin strip male 1×14 pin
  • 2x pin strip male 1×4 pin
  • 1x pin strip male 1×3 pin
  • 1x pin strip female 1×2 pin
  • 1x push button

Installation

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

Alsa Mixer Settings

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

Test

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

Simple Play and Record

Recording:

 $ arecord -r 48000 -f S16_LE -c 2 -d 20 test.wav

Playing back:

 $ aplay test.wav

Microphone

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


I2S and I2C Pins

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/


Install the Shutdown Button and the LED

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

License

The Raspi-Sonic-Hat was designed by Wolfgang Spahn 2020.
It is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Creative Commons License