Compliation with no errors - IR remote does not print to LCD

I can only assume I'm missing something, this sketch compiles and gives no errors, yet I cannot get the buttons to print to my LCD. The LCD shows a line of rectangles, it works when testing example code though. This is one of my first forays in to C++ and arduinos in general, I've succeeded with smaller projects and had the remote printing to serial without issue.

When it was giving errors I at least knew where to turn and what to do, now I'm a little stuck. If anyone has resources they can suggest, I'd appreciate those too.

Below is the complete code -

#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

//LCD
LiquidCrystal_I2C lcd(0x27,16,2);

//IR remote and receiver
#define IR_RECEIVE_PIN 7
#define IR_REMOTE_0 0
#define IR_REMOTE_1 12
#define IR_REMOTE_2 24
#define IR_REMOTE_3 94
#define IR_REMOTE_4 8
#define IR_REMOTE_5 28
#define IR_REMOTE_6 90
#define IR_REMOTE_7 66
#define IR_REMOTE_8 82
#define IR_REMOTE_9 74
#define IR_REMOTE_POWER 69
#define IR_REMOTE_VOLUP 70
#define IR_REMOTE_FUNSTOP 71
#define IR_REMOTE_REWIND 68
#define IR_REMOTE_PLAYPAUSE 64
#define IR_REMOTE_FASTFORWARD 67
#define IR_REMOTE_DOWN 7
#define IR_REMOTE_VOLDOWN 21
#define IR_REMOTE_UP 22
#define IR_REMOTE_EQ 1548
#define IR_REMOTE_STREPT 13


void setup() {
    lcd.begin(16,2);
    lcd.setContrast(50);
    lcd.clear();
    IrReceiver.enableIRIn();
}

void loop() {
    if (IrReceiver.decode()) {
        switch (IrReceiver.decodedIRData.command) {
            case IR_REMOTE_0:
                lcd.print("0");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_1:
                lcd.print("1");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_2:
                lcd.print("2");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_3:
                lcd.print("3");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_4:
                lcd.print("4");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_5:
                lcd.print("5");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_6:
                lcd.print("6");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_7:
                lcd.print("7");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_8:
                lcd.print("8");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_9:
                lcd.print("9");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_POWER:
                lcd.print("You turn me on...");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_VOLUP:
                lcd.print("LOUDER");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_FUNSTOP:
                lcd.print("Why stop my fun?");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_REWIND:
                lcd.print("Beep beep, reversing!");
                delay(3000);
                lcd.clear();
                break;
                   case IR_REMOTE_PLAYPAUSE:
                lcd.print("PLAY/PAUSE idk which you want");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_FASTFORWARD:
                lcd.print("Nyoooom~");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_DOWN:
                lcd.print("Please, senpai, don't turn me down :(");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_VOLDOWN:
                lcd.print("Turn that shit down");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_UP:
                lcd.print("Reach up to the skies");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_EQ:
                lcd.print("No idea what this does");
                delay(3000);
                lcd.clear();
                break;
            case IR_REMOTE_STREPT:
                lcd.print("Not a clue");
                delay(3000);
                lcd.clear();
                break;
            default:
                lcd.print("The fuck you doing?");
                delay(3000);
                lcd.clear();
                break;
        }
        IrReceiver.resume();
    }
}

this seems redundant

why would you need to specify twice that it's a 16x2 LCD

can you compare with the working examples? how do they initilize the LCD?

are you sure about the library being used?

also instead of doing a print, a wait and a clear

                lcd.print("Not a clue");
                delay(3000);
                lcd.clear();

just clear an print, the text will stay until the next code is sent and you don't get stuck for 3s

                lcd.clear();
                lcd.print("Not a clue");

That's almost certainly right, it should be just

lcd.begin();

Maybe two sketches were combined?

Which example code, exactly? Did you try button example code?

First, what resources are you using?

If I remove the first, it says that lcd is not defined in the scope.

Removing the second leaves me with the same problem of it compiling without error but not working.

I'll test with the delay removed and print() location changed.

of course, you can't remove the first one but may be it needs to be written differently (or the second one)

can you share the code that is working and showing something on screen? that will tell you how to configure the library correctly

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Hello, world!");
  lcd.setCursor(2,1);
  lcd.print("Ywrobot Arduino!");
   lcd.setCursor(0,2);
  lcd.print("Arduino LCM IIC 2004");
   lcd.setCursor(2,3);
  lcd.print("Power By Ec-yuan!");
}


void loop()
{
}

This works fine.

I realised I was using begin rather than init, now the squares are gone but there's still no output, it may be the contrast now. -

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setContrast(25);
  lcd.clear();
  IrReceiver.enableIRIn();
}

I'll try with the cursor set as it may be that it requires that.

Yes, I used begin rather than init. Still isn't working but it may now be down to the contrast as the rectangles are gone.

not if it's working fine with the other code

With this -

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setContrast(75);
    lcd.setCursor(3,0);
  lcd.print("Hello, world!");
   lcd.setCursor(2,3);
  lcd.print("please work");
  delay(3000);
  lcd.clear();
  IrReceiver.enableIRIn();
}

I get a brief flash of what I've asked it to print, without the contrast set it doesn't do anything.

Removing the delay and moving the clear keeps it on the screen. Still no output from the buttons on the controller.

try with this

#include <IRremote.h>

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display

struct {
  const uint16_t command;
  const char * description;
} irCodesToText[] = {
  {0, "IR REMOTE 0"},
  {12, "IR REMOTE 1"},
  {24, "IR REMOTE 2"},
  {94, "IR REMOTE 3"},
  {8, "IR REMOTE 4"},
  {28, "IR REMOTE 5"},
  {90, "IR REMOTE 6"},
  {66, "IR REMOTE 7"},
  {82, "IR REMOTE 8"},
  {74, "IR REMOTE 9"},
  {69, "IR REMOTE POWER"},
  {70, "IR REMOTE VOLUP"},
  {71, "IR REMOTE FUNSTOP"},
  {68, "IR REMOTE REWIND"},
  {64, "IR REMOTE PLAYPAUSE"},
  {67, "IR REMOTE FASTFORWARD"},
  {7, "IR REMOTE DOWN"},
  {21, "IR REMOTE VOLDOWN"},
  {22, "IR REMOTE UP"},
  {1548, "IR REMOTE EQ"},
  {13, "IR REMOTE STREPT"},
};

void setup() {
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  lcd.clear();
  lcd.print("Ready");
  IrReceiver.enableIRIn();
}

void loop() {
  if (IrReceiver.decode()) {
    bool found = false;
    uint16_t command = IrReceiver.decodedIRData.command;
    IrReceiver.resume();

    for (auto & entry : irCodesToText) {
      if (entry.command == command) {
        found = true;
        lcd.clear();
        lcd.print(entry.description);
        break;
      }
    }

    if (! found) {
      lcd.clear();
      lcd.print("The f*ck you doing?");
    }
  }
}

do you see "ready" displayed on screen?

which pin is used for your IrReceiver?

"Ready" shows, receiver is on 7.

I managed to work it out, checked through several other examples and implemented them as such -

#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

//LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

//IR remote and receiver
#define IR_RECEIVE_PIN 7
#define IR_REMOTE_0 0
#define IR_REMOTE_1 12
#define IR_REMOTE_2 24
#define IR_REMOTE_3 94
#define IR_REMOTE_4 8
#define IR_REMOTE_5 28
#define IR_REMOTE_6 90
#define IR_REMOTE_7 66
#define IR_REMOTE_8 82
#define IR_REMOTE_9 74
#define IR_REMOTE_POWER 69
#define IR_REMOTE_VOLUP 70
#define IR_REMOTE_FUNSTOP 71
#define IR_REMOTE_REWIND 68
#define IR_REMOTE_PLAYPAUSE 64
#define IR_REMOTE_FASTFORWARD 67
#define IR_REMOTE_DOWN 7
#define IR_REMOTE_VOLDOWN 21
#define IR_REMOTE_UP 22
#define IR_REMOTE_EQ 1548
#define IR_REMOTE_STREPT 13

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  lcd.clear();
  lcd.print("hello");
}

void loop() {
  if (IrReceiver.decode()) {
    switch (IrReceiver.decodedIRData.command) {
      case IR_REMOTE_0:
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("0");
        break;
      case IR_REMOTE_1:
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("1");
        break;
      case IR_REMOTE_2:
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("2");
        break;
      case IR_REMOTE_3:
        lcd.clear();
        lcd.setCursor(8,0);
        lcd.print(":3");
        break;
      case IR_REMOTE_4:
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("4");
        break;
      case IR_REMOTE_5:
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("5");
        break;
      case IR_REMOTE_6:
      lcd.setCursor(1,0);
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("6");
        break;
      case IR_REMOTE_7:
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("7");
        break;
      case IR_REMOTE_8:
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("8");
        break;
      case IR_REMOTE_9:
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("9");
        break;
      case IR_REMOTE_POWER:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("You turn me on...");
        break;
      case IR_REMOTE_VOLUP:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("LOUDER");
        break;
      case IR_REMOTE_FUNSTOP:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Why stop my fun?");
        break;
      case IR_REMOTE_REWIND:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Beep beep beep");
        break;
      case IR_REMOTE_PLAYPAUSE:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("PLAY/PAUSE idk");
        break;
      case IR_REMOTE_FASTFORWARD:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Nyoooom~");
        break;
      case IR_REMOTE_DOWN:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Depressing...");
        break;
      case IR_REMOTE_VOLDOWN:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("stfu");
        break;
      case IR_REMOTE_UP:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Reach up to the skies");
        break;
      case IR_REMOTE_EQ:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("No idea what this does");
        break;
      case IR_REMOTE_STREPT:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Not a clue");
        break;
      default:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("what are you doing?");
        break;
    }
    IrReceiver.resume();
  }
}

Now to work out how to use both lines of the LCD...

#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

//LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

//IR remote and receiver
#define IR_RECEIVE_PIN 7
#define IR_REMOTE_0 22
#define IR_REMOTE_1 12
#define IR_REMOTE_2 24
#define IR_REMOTE_3 94
#define IR_REMOTE_4 8
#define IR_REMOTE_5 28
#define IR_REMOTE_6 90
#define IR_REMOTE_7 66
#define IR_REMOTE_8 82
#define IR_REMOTE_9 74
#define IR_REMOTE_POWER 69
#define IR_REMOTE_VOLUP 70
#define IR_REMOTE_FUNSTOP 71
#define IR_REMOTE_REWIND 68
#define IR_REMOTE_PLAYPAUSE 64
#define IR_REMOTE_FASTFORWARD 67
#define IR_REMOTE_DOWN 7
#define IR_REMOTE_VOLDOWN 21
// #define IR_REMOTE_UP - doesn't work
#define IR_REMOTE_EQ 1548
#define IR_REMOTE_STREPT 13

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  lcd.clear();
  lcd.print("Ready");
}

void loop() {
  if (IrReceiver.decode()) {
    switch (IrReceiver.decodedIRData.command) {
      case IR_REMOTE_0:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("0");
        break;
      case IR_REMOTE_1:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("1");
        break;
      case IR_REMOTE_2:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("2");
        break;
      case IR_REMOTE_3:
        lcd.clear();
        lcd.setCursor(8,0);
        lcd.print(":3");
        break;
      case IR_REMOTE_4:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("4");
        break;
      case IR_REMOTE_5:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("5");
        break;
      case IR_REMOTE_6:
      lcd.setCursor(0,0);
        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print("6");
        break;
      case IR_REMOTE_7:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("7");
        break;
      case IR_REMOTE_8:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("8");
        break;
      case IR_REMOTE_9:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("9");
        break;
      case IR_REMOTE_POWER:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("You turn me on...");
        break;
      case IR_REMOTE_VOLUP:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("LOUDER");
        break;
      case IR_REMOTE_FUNSTOP:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Why stop my fun?");
        break;
      case IR_REMOTE_REWIND:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Beep beep beep");
        lcd.setCursor(0,1);
        lcd.print("reversing!");
        break;
      case IR_REMOTE_PLAYPAUSE:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("PLAY/PAUSE idk");
        break;
      case IR_REMOTE_FASTFORWARD:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Nyoooom~");
        break;
      case IR_REMOTE_DOWN:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Depressing...");
        break;
      case IR_REMOTE_VOLDOWN:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("stfu");
        break;
  //  case IR_REMOTE_UP: //doesn't work
    //   lcd.clear();
    //   lcd.setCursor(0,0);
    //   lcd.print("Reach up to the skies");
      // break;
      case IR_REMOTE_EQ: //doesn't work
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("No idea what this does");
        break;
      case IR_REMOTE_STREPT:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Not a clue");
        break;
      default:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("The fuck you doing?");
        break;
    }
    IrReceiver.resume();
  }
}

The ^ and EQ buttons currently don't work, but I can fix that.

It's not much, but I did a thing.

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