Combine RS232 Volume Control with Hifiberry Digi

I run music from an RPi with Hifiberry Digi into a Rotel A12 Amplifier with integrated DAC via SP-DIF.
The optical connection does not allow volume control, so I was wondering, if I could use the RS232 control-interface of the amp to control the volume.
A short test with a USB-to-Serial adapter works from the shell, letting me remote control functions of the amp.
I was wondering, what the best way of integration would be: I would like the volume slider on the GUI to control the volume of the amp. However, a quick look into the code showed me, that the volume controls (mixer with hardware, software, none) are pretty tied to the DACs configurations and I would probably need to start messing with those.
Is there an easier way to allow e.g. a plugin to read the slider and then send RS232 commands without having to add new functions to the mixer setup? Currently the slider is fixed at 100% with the default setting for the Digi.

My current idea would be a new mixer type “Websock” that would just broadcast any movement of the slider as a websocket message and each plugin wanting to act upon that info would just subscribe to the messages. Other suggestions how it could be implemented? I basically need to untie the slider from the hardware and sound processing and just be able to use it as a pure input device.


Volumio also has the ability to call a shell script on volume actions - for similar use cases. I don’t believe it is thoroughly documented though. Look at volumescript in the volumecontrol.js code to get some ideas!

Hi, thanks for the hint, looks like it could be easier than expected. Will look into it a bit more and see, if I can use it. Would really be great to control the volume from the GUI and not having to use the remote control all the time.
Currently still some issues with the serial - all commands like mute, change input and switch speakers are working except the volume setting :confused: - have to figure out why before trying to integrate it into volumio.

Keep us posted! I have a plugin template that does exactly that :wink:

I looked into the volumecontrol.js code and I think I understand the idea. I also have found and fixed my issue with communication over the serial interface.
I have already programmed 4 simple scripts,,, and confirmed they are working. The command line arguments and response should match with the volumecontrol.js code. There would even be more functionality I could implement later (power down amp when Volumio powers down, switch to correct audio input when Volumio starts playing, set bypass, treble, bass from GUI, pause Volumio when amp is muted from remote… lot’s of ideas come to mind).
Next step would be to try embed everything in a plugin - so if there is something I could build on, that would be quicker - hints are welcome :bulb:.

Below is one of my scripts as example + the object configuration that would need to overwrite the default. Let me know if this looks reasonable (did not try to call it from Volumio code yet). takes two command-line arguments (serial device, volume int):

# Send vol_xx! command to the serial port and return setting from response
# Start read command in the background to wait for the return from the amp
(read -n 60 -t 5 -d \$ RESP < $1; RET=$(echo $RESP | sed 's/volume=//g');echo $RET)&
#sleep 200ms to give the read time to launch
sleep 0.2
# Send volume command
echo -e -n vol_$2!  > $1
# Wait for background read to complete

This is how the volumescript object would look like (+ some path probably):

var volumescript = { 
    enabled: true,
    setvolumescript: ' /dev/ttyUSB0 ',
    getvolumescript: ' /dev/ttyUSB0',
    mapTo100: true,
    maxVol: 50,
    minVol: 0,
    getMuteScript: ' /dev/ttyUSB0',
    setMuteScript: ' /dev/ttyUSB0 '