[GUIDE] Setup Audiophonics ES9018K2M DAC with Volumio 2

Hello,

This guide intends to provide Audiophonics ES9018K2M DAC users and especially Rasptouch backers with instructions to get a usable Volumio 2 sound system with volume control.
It has been tested with the following system configuration :

  • Volumio 2.041
  • RPi 3
  • ES9018K2M DAC
  • Official 7" touchscreen plugin
  • Volumio Spotify plugin
  • Balbuze Volspotconnect plugin

As Audiophonics does not provide any support for ES9018K2M DAC use with Volumio, please consider this guide as a workaround.
Audiophonics ES9018K2M DAC supports both 16 and 24 bitdepth sound files. But there is no automatic recognition of bitdepth.
User has to send configuration parameters over a serial link to select the correct bitdepth for the sound file to play.

Step 0
To accept parameters coming on its serial link input, the DAC has to be setup in “mode serial hardware” as per instructions on product page.

Step 1
Make a fresh install of Volumio 2.041.
Do not install the SDcard on the RPi now.
Do steps 2 and 3 before Volumio first start.

Step 2
Make changes in /boot/config.txt to free up UART0 if using a RPi 3 with embedded bluetooth and to provide a suitable sound driver to the DAC.
Add following lines to /boot/config.txt

dtoverlay=pi3-disable-bt
dtoverlay=hifiberry-dac

After changes, /boot/config.txt contents should look like this:

initramfs volumio.initrd
gpu_mem=16
force_turbo=1
max_usb_current=1
disable_splash=1
dtparam=audio=on
dtparam=i2c_arm=on
dtoverlay=pi3-disable-bt
dtoverlay=hifiberry-dac

Step 3
If using a RPi 3 with embedded bluetooth, remove any reference to ttyAMA0 in /boot/cmdline.txt file.
These parts have to be removed:

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200

Step 4
Insert the SDcard in the RPi and switch on the system.
Wait until Volumio 2 initial setup ends.
If required, install touchscreen plugin and/or Spotify plugin and/or volspotconnect plugin, reboot.
Then, SSH to your Volumio system.
User is volumio
Pass is volumio

Step 5
Go to file system root:

cd /

Disable UART0 use by the modem:
Root pass is also volumio

sudo systemctl disable hciuart

Step 6
Check your ES9018K2M DAC is well recognized by the system:

aplay -l

The DAC shall appear as card 1, assuming there is no other sound card but RPi embedded sound card on your system.
If this step fails, do no proceed further. Fix this step before.

Step 7
Reboot the Volumio system to make the asound.state file created.
SSH again to the Volumio system.

Step 8
As there is no driver for the ES9018K2M DAC, we have to create a dummy mixer to be able to control sound level through Volumio UI.

Go to file system root:

cd /

Edit file var/lib/alsa/asound.state

sudo nano var/lib/alsa/asound.state

Add following lines to var/lib/alsa/asound.state file:

state.sndrpihifiberry {
	control.1 {
		iface MIXER
		name Digital
		value.0 99
		value.1 99
		comment {
			access 'read write user'
			type INTEGER
			count 2
			range '0 - 99'
			tlv '00000001000000080000000000000032'
			dbmin 0
			dbmax 4950
			dbvalue.0 4950
			dbvalue.1 4950
		}
	}
}

Step 9
Activate the dummy mixer:

sudo alsactl restore 1

Check that the dummy mixer has been correctly created:

amixer -c 1

Output shall look like this:

Simple mixer control 'Digital',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 99
  Front Left: 99 [100%]
  Front Right: 99 [100%]

If this step fails, do no proceed further. Fix this step before.

Step 10
Update packages list:

sudo apt-get update

Install python-serial package. This package is required to control DAC with a python script over the serial link:

sudo apt-get install python-serial

Step 11
Create python script required to control the DAC over serial link. This script is a derivative of the one created by Audiophonics for Runeaudio.

nano /volumio/app/plugins/system_controller/i2s_dacs/scripts/ES9018K2M_serial_sync_volumio2.py

Paste contents of this file and save.

Create bash script required to activate python script when Volumio boots:

nano /volumio/app/plugins/system_controller/i2s_dacs/scripts/ES9018K2M-serial.sh

Paste following lines and save:

#!/bin/sh
# Audiophonics ES9018K2M DAC hardware volume management starting script for Volumio 2
# Author: Jean-Charles BARBAUD
#
python /volumio/app/plugins/system_controller/i2s_dacs/scripts/ES9018K2M_serial_sync_volumio2.py

Make bash script executable:

chmod ugo+x /volumio/app/plugins/system_controller/i2s_dacs/scripts/ES9018K2M-serial.sh

Step 12
Add ES9018K2M DAC definition in Volumio 2:

nano /volumio/app/plugins/system_controller/i2s_dacs/dacs.json

Paste following line with respect to DAC name alphabetical order. Notice it is a single line even if this forum is showing it on multiple lines.

{"id":"es9018k2m-serial","name":"Audiophonics ES9018K2M Serial Mode DAC","overlay":"hifiberry-dac","alsanum":"1","mixer":"Digital","modules":"","script":"ES9018K2M-serial.sh","needsreboot":"yes"},

Step 13
Go to Volumio UI through a web browser.
In page “Playback options”:

  • activate I2S
  • in DAC model, select “Audiophonics ES9018K2M Serial Mode DAC” and save configuration.

Step 14
As Volumio 2 overwrites /boot/config.txt file when a DAC is selected, do again changes in /boot/config.txt file as per step 2.
Then, do not change DAC model as it will overwrite /boot/config.txt again.

Step 15
Shutdown the system and remove power supply.
Wait 10 seconds at least to reset the DAC.
Switch on the system.
At this stage, the startup sound management is not yet configured. So, a highly distorted sound may occur.

Step 16
Go to Volumio UI through a web browser.
In page “Playback options”:

  • Mixer type shall be set to “Hardware”
  • Mixer Control Name shall be set to “Digital”

In page “Playback”, volume control shall operate normally when clicking on it.

Check MPD settings:

cat /etc/mpd.conf

“audio_output” section shall look like this:

audio_output {
                type            "alsa"
                name            "alsa"
                device          "hw:1,0"
                dop                     "yes"
                mixer_device    "hw:1"
                mixer_control   "Digital"
                mixer_type      "hardware"
}

If Spotify plugin is installed, /etc/spopd.conf configuration file shall look like this:

[spop]
spotify_username = your_username
spotify_password = your_password


high_bitrate = true
audio_output = sox
pretty_json = true
search_results = 50
cache_path =/run/shm

[sox]
output_type = alsa
output_name = hw:1

If this step fails, do no proceed further. Fix this step before.

At this stage, your Volumio system shall operate normally with Audiophonics ES9018K2M DAC.
Notice there is some latency, around half a second, when changing volume level through Volumio Ui. it is due to processing load to send new volume setting to the DAC.

Step 17
To fix startup sound playing, edit /volumio/app/platformSpecific.js file and search for PlatformSpecific.prototype.startupSound function.
Original Volumio 2.041 startupsound function is as follow:

PlatformSpecific.prototype.startupSound = function () {
        var self = this;
        var outdev = self.coreCommand.sharedVars.get('alsa.outputdevice');
        var hwdev = '--device=plughw:' + outdev + ',0';
        if (outdev === 'softvolume'){
                hwdev = '-D softvolume';
        }
        exec(/usr/bin/aplay '+hwdev+' /volumio/app/startup.wav', function (error, stdout, $
                if (error !== null) {
                        console.log(error);
                } else self.coreCommand.pushConsoleMessage('Startup sound played');
        });
}

Replace following lines:

exec('/usr/bin/aplay '+hwdev+' /volumio/app/startup.wav', function (error, stdout, stderr) {
		if (error !== null) {
			console.log(error);
		}
	});

with this one:

execSync('stty -F /dev/ttyAMA0 2400 && echo "A,0,100,1" > /dev/ttyAMA0 && /usr/bin/aplay '+hwdev+' /volumio/app/startup.wav', { uid: 1000, gid: 1000});

After making changes, startupsound function shall be as follow:

PlatformSpecific.prototype.startupSound = function () {
        var self = this;
        var outdev = self.coreCommand.sharedVars.get('alsa.outputdevice');
        var hwdev = '--device=plughw:' + outdev + ',0';
        if (outdev === 'softvolume'){
                hwdev = '-D softvolume';
        }
        execSync('stty -F /dev/ttyAMA0 2400 && echo "A,0,100,1" > /dev/ttyAMA0 && /usr/bin/aplay '+hwdev+' /volumio/app/startup.wav', { uid: 1000, gid: 1000});
}

Reboot the Volumio system and enjoy.
Startup sound shall now play nicely.

I’ve been trying this, still with no luck. Could there be an error in Step 9? sudo alsactl restore 1 is done two times?

Kjartan

Yes, you are right.
Second command line at step 9 shall be:

amixer -c 1 Original post updated.
But it does not explain why you didn’t succeed.
Notice that your DAC firmware shall support hardware mode. According to Audiophonics, DACs manufactured before november 1st 2016 do not support this mode. It includes DACs provided to Rasptouch backers. In such case, you have to request a firmware update to Auciophonics customer support.

I’m thinking maybe I did step 8 wrong, I replaced the
state.ALSAMixer {
control.1 {

to state.sndrpihifiberry {
control.1 {
and the rest of the code.

Is that right, or should I add the statements in step 8 as you say? Thought it could be a typo error to have two control.1

First, keep in mind that this procedure is suitable for a fresh Volumio installation.
Second, you have to add the statement at the end of the file, not to replace existing statement with new one.
This will add a new mixer to alsa.

Now I’ve done everything, but the 16 bit files are still distorted.
One thing I noticed is that the config.txt did not change when I selected the Audiophonics DAC. I can choose Hardware as Mixer type in Playback options, and Mixer control name is Digital. I can’t turn the volume up and down through the web page of Volumio in Playback. All outputs that you did show are identical to mine.
If my jumper-settings were not right on the DAC, I could not choose Hardware in Playback options, am I right?
One thing I did not do, were to install the plugins as you said. I installed the later, but I don’t believe that could be the problem. I’ve looked over all files that should be changed, and can’t find any difference between what you wrote and my files.
I also tried to update Volumio to 2.118, but it doesn’t matter.
Any help is greatly appreciated.

Kjartan

What 16 bit file source do you try ? Spotify ?

Did you save the Volumio settings after selecting Audiophonics DAC by clicking on “save” button in Volumio UI ?

No, you are not.
There is no relationship between Volumio UI settings and the behaviour of the DAC.
The procedure creates a dummy mixer required to make UI volume control working as expected. That’s all.
Then the python script is asking current sound file playback parameters (bitdepth, current volume) to Volumio periodically and forwards these parameters to the DAC through the serial link.
What is the manufacturing date of your DAC ?
Are you sure it embeds the right firmware ?
If your DAC has been manufactured before november 1st 2016 then it cannot work in hardware mode without firmware update from Audiophonics.

Got mine mid December, it got delayed because the update of firmware.

1 Like

Didn’t try flac files as I don’t have any but it works with Spotify.

So it should be hardware mode compliant.
When changing volume through Volumio UI, does the DAC sound output follow the volume change ?
What version of RPi do you use ?

The DAC output does not follow volume change.
RPi 2 Model B
I’m trying a new setup and first installed the Touchscreen plugin. It have been in 70% Disabling Kios Service for about 10 minutes.

Will it work with ES9023 Dac?

Sent from my iPhone using Tapatalk

Are you having same problem with yor DAC,?

Sent from my SM-G930F using Tapatalk

I can’t adjust the volume using volumio web client, software control. It changes the value but no effective at all.
Actually, es9023 does not have hardware volume control.

Sent from my iPhone using Tapatalk

The procedure is written for the RPi 3. I have no RPi 2 so I cannot make tests.
Assuming your DAC is able to run in hardware mode, as your DAC output does not follow UI volume change it is obvious there is something wrong with UART0 settings.
At step 2, there is no need for RPi 2 to add dtoverlay=pi3-disable-bt in config.txt as there is no bluetooth interface to disable.
At step 3, may be reference to UART0 is not ttyAMA0 but something else like serial0, ttyS0,… Thus, the python script has to be amended with the right UART0 interface name.
You can check if ttyAMA0 exists on your system by entering in the console:

ls -l /dev

Output should look like that :

crw-rw---- 1 root dialout 204, 64 Mar 25 11:46 ttyAMA0 crw-rw---- 1 root dialout 4, 64 Mar 24 19:56 ttyS0
At boot, wait for the UI availability and check Volumio log to see if there is something wrong with DAC init:

cat /var/log/volumio.log

in the Voumio log, this error occurs.

2017-03-26T17:23:54.660Z - error: Cannot execute DAC script: Error: Command failed: /volumio/app/plugins/system_controller/i2s_dacs/scripts/ES9018K2M-serial.sh
Traceback (most recent call last):
  File "/volumio/app/plugins/system_controller/i2s_dacs/scripts/ES9018K2M_serial_sync_volumio2.py", line 14, in <module>
    import time , serial
ImportError: No module named serial

And this is the first lines in the python script

#!/usr/bin/python2
# coding: utf-8
#
# Audiophonics ES9018K2M DAC hardware volume management script for Volumio 2
# 
# Based on script for Runeaudio by Audiophonics and Fujitus
# https://github.com/audiophonics/ES9018K2M_serial_sync
#
# Adapted to Volumio 2 by Jean-Charles BARBAUD
#
# Require to setup ES9018K2M DAC in serial hardware mode as defined on Audiophonics product page.
# Refer to http://www.audiophonics.fr/fr/dac-diy/audiophonics-i-sabre-dac-es9018k2m-raspberry-pi-3-pi-2-a-b-i2s-p-11500.html

import time , serial
import subprocess , os
from urllib2 import Request, urlopen, URLError

I really appreciate your help @Vigo.

Kjartan

This error occurs because python serial module is not installed on your system.
Proceed step 10 to install serial module.

No errors in the volumio log, but

ls -1 /dev tty7 tty8 tty9 ttyAMA0 ttyprintk uhid uinput urandom , no ttyS0, and no dates or time

ttyAMA0 is available, that’s right.
Install python serial module as stated above and it should work.

I did install python before, and this log-file is after the install of python.

This error means python serial module is not installed.
Try again.
If it still doesn’t work, try from a fresh Volumio installation.