IRremote library doesn't work as expected under Arduino IDE

There is a very simple sketch to read and decode IR signal:

#include <Arduino.h>
#include <IRremote.h>

const int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode()) {
    unsigned long return_code = (irrecv.results.value);
    Serial.print(return_code, HEX);Serial.println(" - IR code");
    irrecv.resume();
  }
}

Board: Nano V3
Library: IRremote v 3.0.0
Windows 10

Compiled and uploaded under Arduino IDE returns zero.
Compiled and uploaded under PlatformIO returns button code.

Can anyone explain this behaviour? (Without blaming code itself, please. Code is confirmed.)

I expect something wrong with Arduino IDE itself. Tried Arduino IDE 1.8.13 from Microsoft store, Arduino IDE 1.8.14 nightly downloaded as zip file and also some older version (don't remember which now), all with the same results.

ide.jpg

platformio.jpg

ide.jpg

platformio.jpg

Are PlatformIO and the Arduino IDE using the same version of the library ?

Yes. Both 3.0.0.

What about the time stamp? It's printed in one screen shot but not the other. Actually the code you posted has nothing that prints a time stamp. Maybe you need to re-confirm that you are compiling the same sketch both times.

Try removing one step:

    Serial.print(irrecv.results.value, HEX);Serial.println(" - IR code");

Try removing one step:

aarg:

    Serial.print(irrecv.results.value, HEX);Serial.println(" - IR code");

It will definitely solve the problem (in the same way as throwing computer out of window), but it's not what I want to achieve.
Time stamp is irrevelant. I can get proper output on any serial monitor (that from Arduino IDE as well) as long as I compile the sketch using PlatformIO.

It will definitely solve the problem (in the same way as throwing computer out of window), but it’s not what I want to achieve.

How do you know that? Did you try? What do you want to achieve?

What I’m suggesting is standard divide and conquer methodology. Once you solve the problem, you can go back to assigning it to a variable.

OK, Divide and Conquer, but… DON’T FIX IF AIN’T BROKEN.
I’m not asking about code. I’m asking about the compiler (Arduino IDE).
As i stated in first post, code is good and works fine (under PlatformIO).

Have a look at the readme here: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols
You have some relics relevant to an older version in your code. Also note how new all the changes are. There could easily be a mismatch between various nuances of version 3.0.0 of that library in different places.

For unknown to me reason library 3.0.0 installed by PlatformIO seems to be older version than 3.0.0 from Arduino IDE, however both have 3.0.0 number in file README.md.

droid-21:
For unknown to me reason library 3.0.0 installed by PlatformIO seems to be older version than 3.0.0 from Arduino IDE, however both have 3.0.0 number in file README.md.

Welcome to the land of free, community developed software with loose version management, often poor documentation, arbitrary release procedures etc. etc. and be thankful that, when you have problems, people are willing to respond. Of course, it is not ideal but it is the reality. The problem is that the alternative is to go the completely professional route and pay big money for less features.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.