Problem with IR Array (Thread closed. New thread started)

Guys

I had a problem with this sketch, which turned out to be due to the library, that I was using, disabling PWM on a couple of pins.
Larryd pointed me to another library that didn’t do this.
I have now incorporated the new library, and have a new problem.
I am assuming that the variable byteRX should contain the hex value of the pressed key.
What I am seeing is 0 no matter which key is pressed. The O/P of the Rx (VS1838B) looks good on the DSO.
It look like, the line,

byte byteRX = myRemote.checkCode();

myRemote.checkCode() is not giving a valid byte.
Ideas?

I have attached the code as txt file. Too long, I am afraid. Added 2nd version (minor change), but cannot remove the first

code.txt (8.32 KB)

code.txt (8.44 KB)

Larryd pointed me to another library that didn't do this.

Was that the Kent library or the Auburn library?

Did you wire to pin 2 or 3?

#include <IRremoteNEC.h>
//We must use an interrupt pin, 2 or 3 on an UNO, Ethernet or ATmega1284
//connect this pin to the IR Receiver Module
//#define interruptPin 3
#define interruptPin 2

Start with a smaller code printing just what the receiver gets

J-M-L

Pin 2

Why ride a bike with square wheels?
Use a Sony remote.

Create a minimal version of the sketch which includes just enough code to print the received IR code to the serial monitor and then progress from there. I guess from your code, it may look something like this:

#include <IRremoteNEC.h>
IRremoteNEC myRemote( 2 );  // pin D2

void setup()
{
  Serial.begin(9600);
  myRemote.beginIR(); 
}

void loop()
{
 if (myRemote.getIRflag())                            
  {
     uint32_t irCode = myRemote.checkCode();  //maybe a byte is too small
     Serial.println(irCode);
     myRemote.resetIRflag(); 
  }

}

What, incidentally, are you doing with two different Serial baud rates ?

@J-M-L & 6v6gt.

I decided to go back to the original sketch (IRremoteNEC17), in the examples for the IRreceiveNEC library.

The only changes I have made to it are:-
Changed the first 3 buttonCodes to match my remote
Changed the first 3 ASCIIcodes
As nothing appeared to happen, ie no tone and nothing on the serial monitor.

As the serial monitor appears to need a baud rate of 9600, I changed the baud rate and placed 3 Serial.printlns at the very beginning of loop().

These showed that myRemote.getIRflag() was at 0 until I pressed a key, when it went 1, but at all times, byteRX shows 0. This indicates that a valid interrupt was detected, but the byte appears to not being read correctly

//*****************************************************************************
//17 button IR remote
//NEC - IR code
//By: LarryD 
//
//This sketch demonstrates interfacing to a 17 button IR remote. http://goo.gl/Jk79FM
//These are commonly available on eBay for $2 USD.
//The remote usually comes with a controller. 
//It is an all in one IR detector/amplifier similar to TSOP38238, yours may vary
//**Always confirm the detector/amplifier you have is wired as per YOUR data sheet**
//Remove the detector from the controller for this discussion and wire it to +5V and GND.
//Datasheet for the IR detector: https://www.sparkfun.com/datasheets/Sensors/Infrared/tsop382.pdf
//For wiring, see:               https://learn.sparkfun.com/tutorials/ir-control-kit-hookup-guide
//Interrupt 0 (pin D2) is used to achieve fast receive response.
//See also:                      http://forum.arduino.cc/index.php?topic=289446.msg
//

//**************************************

#include <IRremoteNEC.h>
//We must use an interrupt pin, 2 or 3 on an UNO, Ethernet or ATmega1284
//connect this pin to the IR Receiver Module
//#define interruptPin 3  

#define interruptPin 2 

//confirm the correct interrupt pin has been selected
#if interruptPin != 2 && interruptPin != 3
#error interruptPin must be 2 or 3!
#endif
IRremoteNEC myRemote(interruptPin); //create the object using this pin

//**************************************

#define tonePin 7            //Piezo speaker is connected to this pin

//*****************************************************************************
//17 button Keypad
const byte buttonCode[18] = {
  0x97,0xCF,0xE7,
  0x43,0x15,0x00, //0X00 is not defined
  0x16,0x19,0x0D,
  0x0C,0x18,0x5E,
  0x08,0x1C,0x5A,
  0x42,0x52,0x4A
}; //END of buttonCode Array

const byte ASCIIcode[18] = {
  // 0    1   2  
  0x30,0x31,0x32,
  // >    v  nul 
  0x3E,0x76,0x00,
  // 1    2    3 
  0x31,0x32,0x33,
  // 4    5    6 
  0x34,0x35,0x36,
  // 7    8    9 
  0x37,0x38,0x39,
  // *    0    # 
  0x2A,0x30,0x23
}; //END of ASCIIcode Array 

//*****************************************************************************

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

  myRemote.beginIR();

} 
//************************** E N D   s e t u p ( ) *****************************

void loop(void) 
{
  //**************************************
  //Check if we have received a valid IR code yet. 
//     Serial.println(myRemote.getIRflag());
  if(myRemote.getIRflag())
  {
//     Serial.println(myRemote.getIRflag());
    byte byteRX = myRemote.checkCode();
//     Serial.println(byteRX);
    //If we get a verified button code, convert it to an ASCII code.
    if(byteRX) 
    {          
      //Scan through the buttonCode Array.
      //NOTE: IR remote repeat codes are not returned.
      for (int i = 0; i < 18; i++) 
      {
        if (buttonCode[i] == byteRX)
        {
          tone(tonePin,3400,100);
          Serial.print(char(ASCIIcode[i])); //get the ASCII code

          //We found it, no need to continue looking.
          break;
        } 
      }
    } // END of if(byteRX)

    //Get ready for the next falling edge.
    myRemote.resetIRflag(); 

  } // END of if(myRemote.getIRflag())
  //**************************************

  // Other loop stuff goes here

}
//************************** E N D   l o o p ( ) *****************************






//=============================================================================
//                             END OF CODE
//=============================================================================

The reason I have 2 baud rates in my sketch is to be able to get valid characters on the serial monitor, but leaving it at 115200, for the rest of the time, in case the sketch needed that baud rate, for some reason.

New thread started

IRremoteNEC library problem - IRremoteNEC library problem (Solved) - Programming Questions - Arduino Forum