LCD2004 and Arduino mega 2560

Hi everyone, Im J
Im new to Arduino and get started playing with lcd2004 with arduino mega 2560
But i have met some problems



This two pic are my setup
RED- 5V
BLACK-GND
WHITE-SDA
BROWN-SDL

The problems is i cant get the I2c address for my lcd2004
This is my code


#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);
  Serial.println("\nI2C Scanner");
}


void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;

}

It keeps scanning and cant get the address
I have go through many posts and some of the solution are adding resistor 10kohm/5kohm between GND and SDA/SDL for pull down or 5V for pull up

but still cant solve my problems,
and anyone help me or some suggestion for me?
Thank you so much

Not sure whether the idea was an exercise in building your own I2C scanner, but the code just sets variables and prints "Scanning..." but does not appear to actually read anything from the I2C bus?

Have you tried the I2C scanner example that can be found through the IDE menu from:

File -> Examples -> Wire -> i2c_scanner?

That should give you a clue about what is missing from your program as well as a test to see whether your display is accessible.

Hi, thanks for reply.
i have tried the example but not working.


it keep scanning but didt get anything.

Im doubt if something wrong with my software
My arduino IDE patch is 2.3.6 and do i need to download any libraries for that?

The address is not from the LCD but the back pack address.

What pins is used for SDA , SCL?

  • what is the display type? (could you share a link?)
  • does it definitely run from 5V? Or does it need 3.3V perhaps?

Did you try the example I mentioned or just your own software?

IDE version is fine and the compiler would generate an error if you were missing a library.

please retry with the scanner sketch from the IDE example!

Have you tried different jumpers? Sometimes the wire breaks inside the insulation and is not obvious that the jumper is bad.

The connections look correct in the pictures.

Pin 20 for SDA
Pin 21 for SCL

already tried for few times but same result

thanks for reply,
already tried for different jumper but still the same.

Im buying it from online store and here is the link
Its LCD2004
https://my.shp.ee/uTUERJr

Did you try the example I mentioned or just your own software?

yes i tried the example but the same result, didt show anything

Ok thank you

That should work fine on 5V and on a Mega 2560. I should probably add that if you wanted to write something to the display then your would need the LiquidCrystal I2C library, but the display is not even responding with an address, so we are not at that stage yet.

Just out of curiosity, try connecting the display to the pins marked SDA and SCL at the other end of the board (near the USB connector).

If that doesn't work either then it would seem that the back board on the rear of the display is not responding.

Do you have another I2C device that you can connect and scan?

The normal default address on most of these displays is 0x27 but that can be changed:

I2C Interface

This display incorporates an I2C interface that requires only 2 pins on an MCU to interface with and it has good library support to get up and running fast. The I2C interface is a daughter board attached to the back of the LCD module.

The default I2C address for these displays is 0x27. The address is marked on the bag that the module comes in.

If you need to adjust I2C address to avoid a conflict, this can be done on the I2C adapter board on the back of the module. There are 3 address jumper locations marked A0, A1, A2. Normally these lines are pulled high. If you bridge these pads, it grounds that address line. If you were to bridge all 3 to ground, the address would be 0x20. The range of all possible addresses spans from 0x20 to 0x27

If you are unsure of the I2C address of this or any other device, it is easy to find out what it is. Just refer to this blog post.

Next you can try this basic simple code sample:

The code can be modified as written it uses the 0x27 address, 20 columns, 4 rows. Adjust for what you have be it 16 columns 2 rows or 20 columns 4 rows. On your Mega SDA to SDA and SCL to SCL or on your Mega ADC 4 and ADC 5.

See if that works.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address. Common addresses are 0x27 or 0x3F.
// You might need to run an I2C scanner sketch to find the correct address for your module.
LiquidCrystal_I2C lcd(0x27, 20, 4);  // I2C address, 20 columns, 4 rows

void setup() {
  // Initialize the LCD
  lcd.init();
  // Turn on the backlight
  lcd.backlight();

  // Set the cursor to the first column (0) and first row (0)
  lcd.setCursor(0, 0);
  // Print a message to the first row
  lcd.print("Hello, world!");

  // Set the cursor to the first column (0) and second row (1)
  lcd.setCursor(0, 1);
  // Print a message to the second row
  lcd.print("Arduino I2C LCD");

  // Set the cursor to the first column (0) and third row (2)
  lcd.setCursor(0, 2);
  // Print a message to the third row
  lcd.print("20x4 Display");

  // Set the cursor to the first column (0) and fourth row (3)
  lcd.setCursor(0, 3);
  // Print a message to the fourth row
  lcd.print("Example Code");
}

void loop() {
  // The loop can be used for dynamic content updates, scrolling text, etc.
  // For this basic example, it remains empty.
}


You have never explained what the real problem is. I have never heard of a 20x4 that isn't on 0x27, so, is your problem: your 20x4 is not on 0x27?

No. But im buying arduino UNO board to test, if get the same result might be the display prob

Have you tried what I suggested, including the code sample in post #14? That works fine with my Arduino Mega and Uno.

I also can’t see in your image where you have SDL and SCA going on your Mega board?

Ron

Some boards use the A version of the PCF8574 which has 3F for the default address. However if you find nothing on the I2C scan you have other problems. I would suggest you install the hd44780 library and try the diagnostic tests.

Thankyou, but still same, and the patch i downloaded is 1.3.2 by Bill Perry

Covering the bases: are the backpack pins soldered to the display, or are they just sitting loose in the holes?

HI Ron, thanks for help.
I have tried the code sample, nothing error and successful uploaded, but my display didt show anything.



Here is the image