Skip to content

I2S ​

The Rhino Pi IQ9N provides 1 I2S digital audio interface, using the WAFER-GH1.25-4PLB connector.

Interface Definition ​

For the position of the I2S interface on the board, see the interface layout diagram in Rhino Pi IQ9N Interface Description on the first page.

PinSignalDescription
1DATAAudio data
2SCKBit clock
3WSChannel select (frame sync)
4GNDGround

This interface outputs I2S digital audio signals, so an external DAC or codec chip with I2S input is required to drive speakers.

Audio System Overview ​

ItemDescription
Onboard audio2 × 5W Speaker, output through the SPK interface
Array microphone4Mic Array omnidirectional microphone
AECSupports echo cancellation; must be used together with the internal USB2.0 audio interface

For wiring instructions for the speakers and microphone, see Audio Test.

Viewing Sound Cards and Devices ​

bash
aplay -l
arecord -l

Playing Audio ​

Use aplay to play a WAV file:

bash
aplay -D hw:0,0 test.wav

Specify the sound card and device:

bash
aplay -D plughw:<card>,<device> test.wav

Recording Audio ​

bash
arecord -D hw:0,0 -f S16_LE -r 48000 -c 2 -d 5 rec.wav

Parameter description:

ParameterDescription
-f S16_LE16-bit little-endian sample format
-r 48000Sample rate 48 kHz
-c 2Stereo
-d 5Recording duration 5 seconds

Configuring the Default Sound Card ​

View the list of available sound cards:

bash
cat /proc/asound/cards

To set the default sound card, edit /etc/asound.conf:

text
defaults.pcm.card 0
defaults.ctl.card 0

Example: Reading I2S Microphone Data (Python) ​

python
import wave
import pyaudio

FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 48000
CHUNK = 1024
SECONDS = 5

p = pyaudio.PyAudio()
stream = p.open(
    format=FORMAT,
    channels=CHANNELS,
    rate=RATE,
    input=True,
    frames_per_buffer=CHUNK,
)

frames = []
for _ in range(int(RATE / CHUNK * SECONDS)):
    frames.append(stream.read(CHUNK))

stream.stop_stream()
stream.close()
p.terminate()

with wave.open("rec.wav", "wb") as wf:
    wf.setnchannels(CHANNELS)
    wf.setsampwidth(p.get_sample_size(FORMAT))
    wf.setframerate(RATE)
    wf.writeframes(b"".join(frames))

Installing the dependency:

bash
sudo apt install -y python3-pyaudio

Notes ​

  • The interface is 3.3V level; external devices must support 3.3V I2S timing.
  • When connecting an external I2S device, confirm whether it is in slave or master mode to avoid clock direction conflicts.
  • Parameters such as sample rate and bit width must match the capabilities of the slave device, otherwise noise or silence will result.
  • For wiring and interface position descriptions, see Debug & Expansion Interfaces.