EMERGENCY! My LCD I2C does not seem to work!

I am currently programming a calculator using an Arduino Uno Board, but for some reason the LCD does not display anything, I have looked online and some have said to change the contrast on the back of the LCD but that doesn't work either.

One thing i noticed was that at one point the L light on the Arduino Uno Board was flashing everytime I pressed a +,-,x,÷ key.

Here is the code I used:

/*

   Arduino Keypad calculator Program

*/


#include <LiquidCrystal_I2C.h> //Header file for LCD from https://www.arduino.cc/en/Reference/LiquidCrystal

#include <Keypad.h> //Header file for Keypad from https://github.com/Chris--A/Keypad

const byte ROWS = 4; // Four rows

const byte COLS = 4; // Three columns


// Define the Keymap

char keys[ROWS][COLS] = {


  {'7', '8', '9', 'D'},


  {'4', '5', '6', 'C'},


  {'1', '2', '3', 'B'},


  {'*', '0', '#', 'A'}


};


byte rowPins[ROWS] = { 0, 1, 2, 3 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.

byte colPins[COLS] = { 4, 5, 6, 7 }; // Connect keypad COL0, COL1 and COL2 to these Arduino pins.


Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); //  Create the Keypad


const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13; //Pins to which LCD is connected

LiquidCrystal_I2C lcd(0x27, 16, 2);


long Num1, Num2, Number;

char key, action;

boolean result = false;



void setup() {

  lcd.begin(16, 2); //We are using a 16*2 LCD display

  lcd.print("Arduino Calculator"); //Display a intro message

  lcd.setCursor(0, 1);   // set the cursor to column 0, line 1

  lcd.print("-YEEYEE"); //Display a intro message


  delay(2000); //Wait for display to show info

  lcd.clear(); //Then clean it

}


void loop() {



  key = kpd.getKey(); //storing pressed key value in a char


  if (key != NO_KEY)

    DetectButtons();


  if (result == true)

    CalculateResult();


  DisplayResult();

}


void DetectButtons()

{

  lcd.clear(); //Then clean it

  if (key == '*') //If cancel Button is pressed

  {
    Serial.println ("Button Cancel");
    Number = Num1 = Num2 = 0;
    result = false;
  }



  if (key == '1') //If Button 1 is pressed

  { Serial.println ("Button 1");

    if (Number == 0)

      Number = 1;

    else

      Number = (Number * 10) + 1; //Pressed twice

  }



  if (key == '4') //If Button 4 is pressed

  { Serial.println ("Button 4");

    if (Number == 0)

      Number = 4;

    else

      Number = (Number * 10) + 4; //Pressed twice

  }



  if (key == '7') //If Button 7 is pressed

  { Serial.println ("Button 7");

    if (Number == 0)

      Number = 7;

    else

      Number = (Number * 10) + 7; //Pressed twice

  }




  if (key == '0')

  { Serial.println ("Button 0"); //Button 0 is Pressed

    if (Number == 0)

      Number = 0;

    else

      Number = (Number * 10) + 0; //Pressed twice

  }



  if (key == '2') //Button 2 is Pressed

  { Serial.println ("Button 2");

    if (Number == 0)

      Number = 2;

    else

      Number = (Number * 10) + 2; //Pressed twice

  }



  if (key == '5')

  { Serial.println ("Button 5");

    if (Number == 0)

      Number = 5;

    else

      Number = (Number * 10) + 5; //Pressed twice

  }



  if (key == '8')

  { Serial.println ("Button 8");

    if (Number == 0)

      Number = 8;

    else

      Number = (Number * 10) + 8; //Pressed twice

  }




  if (key == '#')

  { Serial.println ("Button Equal");

    Num2 = Number;

    result = true;

  }



  if (key == '3')

  { Serial.println ("Button 3");

    if (Number == 0)

      Number = 3;

    else

      Number = (Number * 10) + 3; //Pressed twice

  }



  if (key == '6')

  { Serial.println ("Button 6");

    if (Number == 0)

      Number = 6;

    else

      Number = (Number * 10) + 6; //Pressed twice

  }



  if (key == '9')

  { Serial.println ("Button 9");

    if (Number == 0)

      Number = 9;

    else

      Number = (Number * 10) + 9; //Pressed twice

  }


  if (key == 'A' || key == 'B' || key == 'C' || key == 'D') //Detecting Buttons on Column 4

  {

    Num1 = Number;

    Number = 0;

    if (key == 'A')

    {
      Serial.println ("Addition");
      action = '+';
    }

    if (key == 'B')

    {
      Serial.println ("Subtraction");
      action = '-';
    }

    if (key == 'C')

    {
      Serial.println ("Multiplication");
      action = '*';
    }

    if (key == 'D')

    {
      Serial.println ("Division");
      action = '/';
    }


    delay(100);

  }



}


void CalculateResult()

{

  if (action == '+')

    Number = Num1 + Num2;


  if (action == '-')

    Number = Num1 - Num2;


  if (action == '*')

    Number = Num1 * Num2;


  if (action == '/')

    Number = Num1 / Num2;

}


void DisplayResult()

{

  lcd.setCursor(0, 0);   // set the cursor to column 0, line 1

  lcd.print(Num1); lcd.print(action); lcd.print(Num2);



  if (result == true)

  {
    lcd.print(" =");  //Display the result
    lcd.print(Number);
  }



  lcd.setCursor(0, 1);   // set the cursor to column 0, line 1

  lcd.print(Number); //Display the result

}

OK, the first thing to work on is how to present your code.

Please go and read the instructions, then go back and modify your post (use the "More --> Modify" option to the bottom right of the post) to mark up the code (but it needs to be the complete code) as such so we can examine it conveniently and accurately. Do not post a ".ino" file as an attachment - that means that you are expecting people to actually load it to their IDE to look at it and that is extra unnecessary labour. In fact, attachments do not always show properly on different operating systems.

If you do not mark it up as code, the code you post could well be garbled and is certainly anything but easy to read, so you will find little enthusiasm for assistance with it.

Note: Also mark up any data in the same way. This includes error output that you get from the IDE.

And - before you post any code, use "Auto Format" in the Tools menu of the IDE to properly present the code. You can then use the "Copy for forum" option in the edit menu in order to paste it back in your forum post.

Try and avoid unnecessary white space (blank lines). You should only use these to separate functional blocks of code.

Until you reply and demonstrate that you understand these points that have been made so far, there is absolutely no point working through the other problems with the code, and I suspect other people feel the same way, so I will leave it at that for the present.

Thanks Paul, Ill fix it immediately!

OK, though it is still double- and even triple-spaced and therefore very difficult to read.

Now, you say "the LCD does not display anything". The next question is "Did it ever?" :astonished:

Did it work when you set it up with the "Hello World" test sketch? I rather suspect not. :roll_eyes:

I see you are using the "LiquidCrystal_I2C.h" library. This implies you are using the I2C version of the library in order to connect with a "backpack" connected to the I2C pins A4 and A5. And you would be extremely lucky if that worked at all since there are a number of different I2C backpacks which use different wiring and port addresses.

You are however advised to just forget those older libraries, and use bperrybap, Bill's HD44780 library which can be automatically installed using the library manager in the IDE and has a test program which will figure out all the settings for you.

Hey, thanks for responding, as you can tell I'm new to this whole arduino thing.

I installed the library you recommended, but it still seems as if nothing is working.

What would I do after installing the library. Would I delete the old I2C library?

The LCD IS turning on, and only displays big white blocks, or nothing at all when I mess with the contrast. But other than that it isn't displaying any numbers or messages.

You need to run the test examples supplied with that library.

I think you also need to explain - and show us some pictures - how you have it wired up.

In the ioclass, hd44780I2C_exp examples of the hd44780 library there is a I2CexpDiag sketch. Load and run that example and copy and paste the output into a new post. That will give us an idea of what is going on.

That and the pictures requested by Paul__B will be a big help to solving your issue. We have seen, lately, poor solder joints on I2C backpacks and the backpack to LCD connections.

For some the reason the site is not allowing me to post pictures. I keep getting this page that says "entity too large"

Hey fungus Im not sure but is where im supposed to find it?

I have the 8 pins of the keypad connected to the first 8 pins on the arduino starting at 0>RX. I have the GND, VCC, SDA, SCl pins connected to female ports: GND, 5V, A4, A5 respectively.

Yes, that is the sketch. Don't post a screenshot. Load the I2CexpDiag sketch and open the serial monitor. The sketch should run and then you can copy the sketch output text from serial monitor and paste the text into a reply, here.

Pins 0 and 1 are the hardware serial pins (USB). Using those pins for something else may interfere with program upload and serial communication. Can you use other pins?

I clicked on serial monitor under tools and this is what popped up.

I am not sure if i can, or cannot use other pins.

Wouldnt using other pins, require me to change my code?

Heres what I have setup

Untitled document.pdf (387 KB)

UPDATE:

I compiled the I2CexpDiag. Now im getting this LCD:0 (0x27) and a timer.

It also displayed this for a short amount of time:
LCD:0
0x27,P01245673H

Wouldnt using other pins, require me to change my code?

Yes you need to change the code. You need to move the keypad off of pins 0 and 1 or serial and/or the keypad will not work right. Serial is the best debugging tool that you have. You cannot afford to not have serial communication.

I compiled the I2CexpDiag. Now im getting this LCD:0 (0x27) and a timer.

That is good to hear. That means that the HD44780 library has found your display and it is working OK.
Does the "hello world" example from that same set of examples work?

How would i get the hello world example to work?

Sorry for asking so many questions, I appreciate the time you've taken to respond to all my questions.

The example is in the same folder as the I2CexpDiag sketch is. Load the example to the IDE, upload to your Arduino and it should just work.

Yep, Hello World! works just fine!

What would my next step be?

How would I change the pins to read the keypad?

MEGA UPDATE: OH MY GOD IT WORKS! IM SO FRICKING HAPPY GUYS!

THANK YOU PAUL, AND THANK YOU SO MUCH FUNGUS!!!!!