Infrared (IR) Transmitter

Sorry, I am absolute beginner in github, so I created a zip-file :wink:
Here you go, if you have questions, just ask.
volume_guard.zip (5.6 KB)

Thanks, it looks doable. Run the script on the RPi and load the Ino using the IDE for arduino. Hook arduino up and check that its on ttyUSB0 or adjust.

I need to change the ir code I think. If i hold down the volume button the code should alternate between two different HEX codes. Not quite sure how to do it, but the idea is like below. Is it just plain bash code I should make use of?

  for (int i=0; i < le; i++){
    n=$(($i % 2)) 
    if [ n -eq 0 ]; then
        IrSender.sendNEC(0x3412, 0x22, 1);
    else
        IrSender.sendNEC(0xXXXX, 0x22, 1);
    fi
delay(100);
  }

One question. Does arduino receive the +'s or -'s until the stream ends and then start to process and send ir or does it start sending ir as soon as the first key press is detected?

In the former case user would have to guess for how long the ‘increase volume button’ can be pressed.

I think the logic might work, but arduino sketches need to be coded in C, not bash.
Upload the sketch to the arduino with Arduino IDE: https://www.arduino.cc/en/software
Make sure to use the correct IR-Codes and protocol.
You can find documentation and examples for the IRremote-library here:
GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols

That depends on the delays in the communication.
The volumio plugin sends the amount of “+” or “-” according to the difference to the standard-volume.
So the arduino might receive a single “+” or e.g. “++++++++++++++++”.

Hi again , how did you connect the IR blaster? The IR diodes that I see are 1.2V do would have to reduce the voltage with a resister. Do you drive the diode with a transistor to limit the current on the Arduino GPIO?

I have a wired IR led as you showed, but I guess this would also be 1.2V rating…

Hi!
I just connected the IR Blaster directly, one pin GPIO and one pin GND without resistor.
Up to now, it works :wink:
Maybe using a resistor would be safer, but it seems also to work without.

Hi, almost got it working now. The arduino works with my RC-5 HEX codes.

But now installing your plugin on the RPi. I get an error about versions:

Volume Guard - Installing serialport node dependency
npm WARN notsup Unsupported engine for serialport@12.0.0: wanted: {"node":">=16.0.0"} (current: {"node":"14.15.4","npm":"6.14.10"})
npm WARN notsup Not compatible with your version of node/npm: serialport@12.0.0
npm WARN notsup Unsupported engine for @serialport/bindings-cpp@12.0.1: wanted: {"node":">=16.0.0"} (current: {"node":"14.15.4","npm":"6.14.10"})
npm WARN notsup Not compatible with your version of node/npm: @serialport/bindings-cpp@12.0.1

Are your script installing some versions that are obsolete?

Br anders

edit - what I wrote was wrong.
I remember that I also had errors when installing that package.
Maybe try to install it manually.

You can check like this, if the package was installed:

cd into this directory: /data/plugins/system_hardware/volume_guard/node_modules
npm list serialport

I installed the IRRemote plugin - seems that whatever that installed has helped. Still says wrong version but the serialport is now there.

But in Volumio GUI it says it is failing to start the plugin. Have you tried it in Volumio 3?

I am getting a bit futher by change the install.sh to use version 11 of serialport

echo "Volume Guard - Installing serialport node dependency"
npm install serialport@11.0

But I now get an error about missing kew.

I tried npm install kew but it fails with:

Could not install from "node_modules/kew" as it does not contain a package.json file.

Hi,

well, this was my first plugin ever… For my understanding, kew is a rather standard package for volumio (see here: Index.js | Volumio Developers Documentation).
I am using the latest volumio version.
My difference was, that I created that plugin on my volumio-installationm following this guide: The Plugin Utility | Volumio Developers Documentation.
I do not know if that makes a difference, but maybe things are different when setting up a existing plugin vs. creating one.
Sorry for not beeing helpful here…

btw, this are the packages installed on my system in the plugin directory:

I appreciate your help. Sorry for all the questions… I just want to make this work :crossed_fingers:

In the end I made it work by manually copying kew into the plugin directory. Volumio can now send volume commands to the Arduino and as such the system is working. Nice!

But with an USB DAC connected the volume control setting in Volumio is either None or Software.

If i select None there is no way to make Volumio change volume and the plugin cant be used.

If I select Software the signal has to pass software and it will be bad for the music quality.

How have you setup your system?

Hi,

for my DAC (RME Adi-2 DAC FS) I can choose “Hardware”, but no matter what the volume is set to, it is always 100%. Thats why I created the plugin and IR-Solution.
If you cannot choose “Hardware”, I think that approach will not work for you.

@volumio : Maybe it would be a nice feature to add a kind of “virtual mixer” volume control, which just does nothing, but gives plugins the possibility to read the current volume and use that data to do something.

you can get volume level in a plugin using websocket

self.socket.on('pushState', function (data) {
console.log('volume is '+data.volume)
}

I am aware of that. But If you set the Mixer to “none”, the volume control disappears.
For my DAC it works, as I can still choose “Hardware”, despite it has no effect. But for other DACs, like the one @lyhnet is using, “Hardware” is not available and setting the Mixer to “none” makes the volume control disappear. That why a “Virtual” mixer might be a nice feature.

I managed to do a hack to make it work… but it is not a nice way.

Firstly I need to expose the volume control for Mixer=None and then I need to prevent volumio from setting volume to 100 everytime the system sees a volume change. (that causes an infinite loop with volume_guard that then resets to 50.

Edit /volumio/app/volumecontrol.js

// Public methods -----------------------------------------------------------------------------------
CoreVolumeController.prototype.alsavolume = function (VolumeInteger) {
  var self = this;

  if (volumeOverride) {
    return this.commandRouter.executeOnPlugin(overridePluginType, overridePluginName, 'alsavolume', VolumeInteger);
  } else {
    var defer = libQ.defer();
    self.logger.info('VolumeController::SetAlsaVolume' + VolumeInteger);
    if (mixertype === 'None') {
      //Volume.vol = 100;   //Anders: Prevent this!!!! this prevents infinite loop with volume_guard
      Volume.mute = false;   
      Volume.disableVolumeControl = false; //Anders: Prevent this!!!! set = false!!! (this should enable vol-cont in gui)
      defer.resolve(Volume);
1 Like