6

my board is a firebeetle esp32 that I am using as an IR remote.

After using the Ken Shirrif IRremote library for about 6 months successfully, then the time came to change a few things on the web front end. This has been a disaster.

I tried to recompile my working code that the board is currently using and got errors everywhere I turned.

So i switched libraries to this one;

https://github.com/ExploreEmbedded/Arduino-IRremote

Now it does compile successfully, with the only change between the two libraries was to pull out the pin I defined for IR tx in the Ken Shirriff library. For example; previously my code looked like this to work with the old library.

IRsend irsend(33);

Now it looks like this;

IRsend irsend;

As stated, it does compile; only issue is that IR doesn't work. It says in the library that pin 5 is defined as the tx pin for the ESP32 in boarddefs. Snip from boarddefs where I believe pin 5 is defining IR tx.

// ESP32 has it own timer API and does not use these macros, but to avoid ifdef'ing
// them out in the common code, they are defined to no-op. This allows the code to compile
// (which it wouldn't otherwise) but irsend will not work until ESP32 specific code is written
// for that -- merlin
// As a warning, sending timing specific code from an ESP32 can be challenging if you need 100%
// reliability because the arduino code may be interrupted and cause your sent waveform to be the
// wrong length. This is specifically an issue for neopixels which require 800Khz resolution.
// IR may just work as is with the common code since it's lower frequency, but if not, the other
// way to do this on ESP32 is using the RMT built in driver like in this incomplete library below
// https://github.com/ExploreEmbedded/ESP32_RMT
#elif defined(IR_TIMER_USE_ESP32)
#define TIMER_CHANNEL       1
#define TIMER_LENGHT        8 //8-bit Timer
#define TIMER_PWM_PIN      5
#define TIMER_ENABLE_PWM    ledcAttachPin(TIMER_PWM_PIN, TIMER_CHANNEL);         
#define TIMER_DISABLE_PWM   ledcDetachPin(TIMER_PWM_PIN); 
#define TIMER_RESET  
#define TIMER_ENABLE_INTR    
#define TIMER_DISABLE_INTR   
#define TIMER_INTR_NAME      

//---------------------------------------------------------
// Unknown Timer
//
#else
#   error "Internal code configuration error, no known IR_USE_TIMER# defined\n"
#endif

#endif // ! boarddefs_h

I know it says that IR with the ESP32 will not work, but it said the same thing for several libraries that i've used that do work, most notably the one by Ken; which appears to have moved here.

https://github.com/z3t0/Arduino-IRremote

Quick example of my code;

#include "IRremote.h"
  IRsend irsend;
int khz = 38;
String input;
  String tv;
void changehdmi() {
if (Server.args() > 0 ) {
  for ( uint8_t i = 0; i < Server.args(); i++ ) {
    if (Server.argName(i) == "input") {
      input = String(Server.arg(i));
      Serial.println("input is " + input);
    }
    if (Server.argName(i) == "tv") {
      tv = String(Server.arg(i));
      Serial.println("tv is " + tv);
    }

  }
}
if (input == "1" && tv == "1") {
  unsigned int irSignal[] = {9000, 4450, 600, 550, 550, 550, 600, 550, 550, 550, 600, 500, 600, 550, 550, 600, 550, 550, 600, 1650, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1650, 600, 1650, 550, 1700, 550, 550, 600, 550, 550, 1700, 550, 550, 600, 500, 600, 550, 550, 600, 550, 550, 600, 1650, 550, 1700, 550, 550, 600, 1650, 550, 1700, 550, 1700, 550, 1700, 550}; // NEC FF906F
  irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
}
else if (input == "2" && tv == "1") {
  unsigned int irSignal[] = {9000, 4500, 550, 550, 600, 550, 550, 550, 550, 600, 550, 550, 600, 550, 550, 550, 550, 550, 600, 1650, 600, 1700, 500, 1700, 600, 1700, 500, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 550, 550, 1700, 550, 1700, 550, 1700, 550, 550, 550, 550, 600, 550, 550, 550, 600, 1700, 500, 600, 550, 550, 600, 500, 600, 1650, 600, 1650, 600, 1650, 550}; // NEC FFB847
  irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
}

Has anyone gotten this to work recently? The libraries that are available seem to have lost support for this functionality.

1 Answer 1

1

For the ESP32, you should really check out IRremoteESP8266, which also works on your board, and is frequently updated, very widely used, and lets you use any compatible GPIO pin easily.

Here's a sample of a simple IR send demo:

#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>

#define IR_PIN 4

IRsend irsend(IR_PIN);  // Set the GPIO to be used to sending the message.

void setup() {
  irsend.begin();
  Serial.begin(115200);
}

void loop() {
  Serial.println("NEC");
  irsend.sendNEC(0x00FFE01FUL);
  delay(2000);
}

This example will send an NEC code very 2 seconds. The library also has extensive support for other formats, as well as raw.

If you want to be extra safe, the creator of the project menions here that GPIO 4 and 18 are safe, but I know for a fact that many other ESP32 pins are okay to use as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.