irrecv.enableIRIn(); breaks code for controlling Onkyo amplifier via RI-cable

Hi there,

[EDIT: I SOLVED THE ISSUE, SEE 3rd POST]

I’m new to the forum, new to arduino and consider myself a coding noob. But hey I’m having fun :wink:

After having bought my first starter kit and completing some easy projects I’m now working on my first project. Things went quite smooth sofar but the last piece of the metaphorical puzzle does not seem to fit. So I would appreciate your help.

Let me first explain what I want to achieve.

I own a onkyo A9010 amplifier which has a ‘RI-in’ port to control it. My aim is to use the arduino for this. The arduino will in turn be controlled via the infrared remote of the Onkyo (at least for now).

More info on this can be found here: Onkyo RI Protocol

And I’m using this library to control the Onkyo:

For the IR-receiver I’m using IRremote

My arduino board is an Elegoo uno R3

To make this work I broke the problem down in 2 parts.

  1. Control the arduino with the Onkyo infrared remote control

  2. Use the arduino to control the Onkyo amplifier via the RI cable. For testing purposes I use a physical button on the arduino.

To my own suprise I got both these things to work. Seperatly at least. But integrating them hasn’t worked so far.

I have done some debugging and found out that the following function stops the sending of the RI signal to the Onky amplifier:

irrecv.enableIRIn();

The interesting thing is that there are now error messages and that the code still appears to function in full. I added lines to check via the serial bus if the bits are still being send, which seems to be the case.

Also when I deactive the irrecv.enableIRIn(); line, basically not starting the IR-reiver, the code functions in full. Meaning that I can control the amplifier with the physical button, which basically mimics one IR button.

I’ve attached two images of the serial bus. One in which I pressed the physical button on the arduino to send the RI signal, and the second one in which I used the IR-remote to send the same signal. As can be seen both actions create the same result.

Who can help me or point me in the right direction?

The code:

#include "OnkyoRI.h"
#include "IRremote.h"


//DEFINE PINS
  const int button1_pin = 2;
  const int ONKYO_PIN = 9;
  const int IR_PIN = 11;

//define serial speed
const int UART_SPEED = 9600;

//define variables
  int i=0;  
  int button1_state = 0;

//ONKYO IR-REMOTE CODES (RECIEVED BY ARDUINO)
  unsigned long ONK_IR_Power = 0x4B20D32C;
  unsigned long ONK_IR_Input_left = 0x4B20F807;
  unsigned long ONK_IR_Input_right = 0x4B207887;
  unsigned long ONK_IR_Volume_up = 0x4BC040BF;
  unsigned long ONK_IR_Volume_down = 0x4BC0C03F;
  unsigned long ONK_IR_Mute = 0x4BC0A05F;

//ONKYO RI-CABLE CODES (SEND TO ONKYO AMPLIFIER)
  unsigned long RI_ONKYO_Power_ON = 0x02f;
  unsigned long RI_ONKYO_Power_OFF = 0x0da;
  unsigned long RI_ONKYO_Input_left = 0x0d5;
  unsigned long RI_ONKYO_Input_right = 0x0d6;
  unsigned long RI_ONKYO_Volume_up = 0x002;
  unsigned long RI_ONKYO_Volume_down = 0x003;
  unsigned long RI_ONKYO_Mute = 0x005;

IRrecv irrecv(IR_PIN);
decode_results results;

//SETUP

void setup() { 
  
  Serial.begin(UART_SPEED);

  pinMode(button1_pin, INPUT);
  pinMode(ONKYO_PIN, OUTPUT);
  pinMode(IR_PIN, INPUT);
  
  digitalWrite(ONKYO_PIN, LOW);
  
 //START IR-RECEIVER
 irrecv.enableIRIn(); //THIS LINE MAKES THE CODE 'CRASH'
 
  
  Serial.println("Setup ready");
}

void loop() {
  
  button1_state = digitalRead(button1_pin);

  if (button1_state == HIGH) {
       Serial.println("Button 1 pressed");
    onkyoSend(RI_ONKYO_Input_right); 
  }


// CHECK IR FOR RESULT

    if (irrecv.decode(&results)) {
  
// IF IR RESULT INITIATE FUNCTION
    
    if (results.value == ONK_IR_Power) { 
      onkPower();
      }
    else if (results.value == ONK_IR_Input_left) {
      onkInputLeft();
      }
    else if (results.value == ONK_IR_Input_right) {
      onkInputRight();
      }
    else if (results.value == ONK_IR_Volume_up) {
      onkVolumeUp();
      }
    else if (results.value == ONK_IR_Volume_down) {
      onkVolumeDown();
      }
    else if (results.value == ONK_IR_Mute) {
      onkMute();
      }        
    irrecv.resume(); 
    }
  }

//FUNCTIONS FOR CONTROLLING ONKYO AMPLIFIER

  void onkPower(){
    onkyoSend(RI_ONKYO_Power_ON);
    Serial.println("Power");
  }

  void onkInputLeft(){
    onkyoSend(0x0d5);
    Serial.println("Input left SEND");
  }

  void onkInputRight(){
    onkyoSend(RI_ONKYO_Input_right);
    Serial.println("Input right");
  }

  void onkVolumeUp(){
    onkyoSend(RI_ONKYO_Volume_up);
    Serial.println("Volume up");
  }

  void onkVolumeDown(){
    onkyoSend(RI_ONKYO_Volume_down);
    Serial.println("Volume Down");
  }
  
  void onkMute(){
    onkyoSend(RI_ONKYO_Mute);
    Serial.println("Mute..");
  }

//END CONTROL ONKYO


//ONKYO SEND

void onkyoSend(int command)
{
  onkyoWriteHeader();
  Serial.println("Header send");
  
  for(int i=0;i<12;i++)
  {
    bool level = command & 0x800;
    command <<= 1;
    onkyoWriteBit(level);
    Serial.println(level);
  }

  onkyoWriteFooter();
  Serial.println("Footer send");
}

void onkyoWriteHeader()
{
  //Serial.println(micros());
  digitalWrite(ONKYO_PIN,HIGH);
  delayMicroseconds(3000);
  digitalWrite(ONKYO_PIN,LOW);
  delayMicroseconds(1000);
  //Serial.println(micros());
}
void onkyoWriteBit(bool level)
{
  digitalWrite(ONKYO_PIN,HIGH);
  delayMicroseconds(1000);  
  digitalWrite(ONKYO_PIN,LOW);
    
  if(level)
    delayMicroseconds(2000); 
  else
    delayMicroseconds(1000); 
}
void onkyoWriteFooter()
{
  digitalWrite(ONKYO_PIN,HIGH);
  delayMicroseconds(1000);
  digitalWrite(ONKYO_PIN,LOW);
  delay(20);
}

//END ONKYO SEND

button press debug.PNG

IR remote debug.PNG

Anyone who has an idea?

In case anyone runs in to the same issue in the future. I solved the problem.

I made two main changes that toghether seem to have fixed the problem.

  1. I changed the IR library, now using IRMP instead of IRremote

  2. It turned out that serial.print was causing problems when executed before sending the signal to the Onkyo.

So this does NOT work:

Serial.println(F("Onkyo volume up"));
onkyoClient.send(0x2);

But this does work:

onkyoClient.send(0x2);
Serial.println(F("Onkyo volume up"));

Happy listening!