In this project we build simple I2S stereo decoder with amplifier. To decode I2S data we use Princeton Technologies PT8211 16bit DAC. KA2206 audio power amplifier is used as driver stage of this system.
Structure of this I2S amplifier is self-explanatory from the schematic. We select PT8211 and KA2206 combination due to lower cost and availability. Unfortunately PT8211 DIP package is not available in local market and we use SO package in our prototype. We design PCB for the DIP packages, and therefore we solder PT8211 SO package to PCB using “SO8 to DIP8” converter.
Pi Zero is a small board – part of the Raspberry family – designed for embedded applications where space is a constraint. The low cost(about 10€ for version W, with wifi connectivity) and the ability to run different operating systems makes it the ideal choice for different applications (media centers, data loggers…).
It may be sometimes difficult to buy a Raspberry Pi Zero… it’s indeed often out of stock on the different webstores. A help may come from the ThePiLocator website, which displays in realtime the availability of the different Pi Zero boards on the official stores.
Raspberry Pi Zero unfortunately doesn’t offer a dedicated audio connector: audio output is indeed normally performed via HDMI:
Although this is perfect for applications like media centers (where audio and video are reproduced by the monitor/television connected via HDMI), it’s not handy in embedded applications where you only need to play some audio files (for example to add audio warnings). Even if you can find on the market some devices that extract audio flows from the HDMI stream, those devices are often expansive and bigger than the Raspberry Pi Zero itself!
A very simple solution, well explained in a tutorial by Adafruit, is to generate the audio signal using two PWM (Pulse Width Modulation) pins and a low-pass filter made with some passive components. This solution has the advantage of being very cheap and easy to make; by contrast the sound quality is not very high.
In today’s tutorial I’ll show you how to generate high quality audio using the I2S bus.
I2S is a serial bus designed to connect different audio devices and to transfer audio signals in digital form.
The bus specification has been published by Philips in 1986. The I2S bus requires at least 3 signals:
clock (labelled as SCK – serial clock o also as BCLK – bit clock)
word select (WS, sometimes defined also LRCLK – left/right clock)
serial data (SD, or also SDATA…)
We can use this bus to communicate audio data between our Pi Zero and an amplifier that accepts audio input via I2S bus:
What you need
I chose an I2S amplifier based on the MAX98357chip by Maxim. This chip offers 3.2W in output and you can connect directly a small 4 ohm speaker. Both the breakout board with the Maxim chip and the speaker are from Adafruit:
In the end of this post, I’d like to show you how to use a program, mps-youtube, to play audio tracks from Youtube using only a command-line interface. Because of it’s written in Python3, you have to install version 3 of the language interpreter and one if its package managers, pip:
sudo apt-get install python3 python3-pip
Now you can install mps-youtube and its requirements with:
sudo pip3 install youtube-dl mps-youtube
Run the program with the command mpsyt. First you have to configure the player you want to use (mpv):
Then you can search for a video, typing the search string preceded with /. Alternatively, if you already know the video URL, you can play it with the command playurl <url>:
Noise when changing track
It may happen that when changing the track or at the beginning of a new reproduction, you hear some noise coming from the speaker. The reason is well explained in this thread on the Adafruit customer forum (thread I also contributed to): the cause is the frequency change of the I2S clock signal.
The easiest way to solve the problem is to continuously play a silence signal of a fixed frequency (for example 48KHz):
aplay -t raw -r 48000 -c 2 -f S16_LE /dev/zero &
Run the above program before starting mpv or any other player and you’ll find that all the noise is gone!
[curcuz]’s BoomBeastic mini is a Raspberry Pi based smart connected speaker. But don’t dis it as just another media center kind of project. His blog post is more of a How-To guide on setting up container software, enabling OTA updates and such, and can be a good learning project for some. Besides, the design is quite elegant and nice.
The hardware is simple. There’s the Raspberry-Pi — he’s got instructions on making it work with the Pi2, Pi2+, Pi3 or the Pi0. Since the Pi’s have limited audio capabilities, he’s using a DAC, the Adafruit I2S 3W Class D Amplifier Breakout for the MAX98357A, to drive the Speaker. The I2S used by that part is Inter-IC Sound — a 3 wire peer to peer audio bus — and not to be confused with I2C. For some basic visual feedback, he’s added an 8×8 LED matrix with I2C interface. A Speaker rounds out the BoM. The enclosure is inspired by the Pimoroni PiBow which is a stack of laser cut MDF sheets. The case design went through four iterations, but the final result looks very polished.
On the software side, the project uses Mopidy — a Python application that runs in a terminal or in the background on devices that have network connectivity and audio output. Out of the box, it is an MPD and HTTP server. Additional front-ends for controlling Mopidy can be installed from extensions, enabling Spotify, Soundcloud and Google Music support, for example. To allow over-the-air programming, [curcuz] is using resin.io which helps streamline management of devices that are hard to reach physically. The whole thing is containerized using Docker. Additional instructions on setting up all of the software and libraries are posted on his blog post, and the code is hosted on GitHub.
There’s a couple of “To-Do’s” on his list which would make this even more interesting. Synced audio being one: in a multi-device environment, have the possibility to sync them and reproduce the same audio. The other would be to add an Emoji and Equalizer display mode for the LED matrix. Let [curcuz] know if you have any suggestions.