2

is it my coding wrong or my board have problem because my lcd does not display anything. here my coding

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


// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 6, 2, 3, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C add 27 / 3F



void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600); //
  lcd.begin(16,2);         // initialize the lcd for 16 chars 2 lines, turn on backlight
  lcd.backlight();

}

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{

  lcd.setCursor(0, 0);               
  lcd.print("HELLO");

  delay(200);

  lcd.setCursor(0, 1);            
  lcd.print ("HI");

  delay(2000);

  lcd.clear();

  delay(2000);

  lcd.setCursor(0, 0);               
  lcd.print("NICE");

  delay(200);

  lcd.setCursor(0, 1);            
  lcd.print ("GOOD ");

  delay(2000);

  lcd.clear();

  delay(2000);
}

enter image description here

this is how i wirring it. what should i do?

3
  • You should add some Serial.println() to know if the program is running (or at least make a LED blinking in the loop). Looking at the dispay, it seems to me that either the iniialization is not correct, or the contrast is not set properly (I can't see the external potentiometer/resistor, but that particular display might not require it). – next-hack Aug 23 '17 at 11:39
  • but when i compile and upload in arduino it did not show any error. can you tell me where should i add Serial.println(). because this is my first time using this. – AIN MIMI Aug 23 '17 at 11:42
  • Well, put some lines after each time you call an lcd method. For instance, after lcd.begin(16,2); you could write Serial.println("After lcd.begin()"); Etc. If, on the serial monitor, you don't see "After Begin", then even the begin method does not succeed. This might be due to incorrect wirings. – next-hack Aug 23 '17 at 12:00
1

Well, I have the hardware, so I tested OP's configuration. It didn't work for me either. Same OP's problem.

The cause is the I2C address we are using (0x27). That's not my LCD address, probably neither your address. It's 0x3F in my case.

I discovered it I2CScanner, a short sketch that lists all I2C devices connected at that moment. So, run it (with the LCD connected) and watch with Serial Monitor for the address of your LCD.

Then replace all references to 0x27 (like lcd(0x27, 16, 2)) with your real address. Just change one value for the other.

Hello World

This is I2CScanner

//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}


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

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

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknown error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}
6
  • the serial monitor show that my lcd address is 0x3F. but when i change my address in my coding and i start run the program the lcd start blinking but any of the word does not display. – AIN MIMI Aug 24 '17 at 14:41
  • Well, you also have to change that lcd.begin(16,2); with lcd.init(); I tested your code and it runs OK with that change. You are using old API calls. Study the examples that comes under **LiquidCrystal I2C" and learn how to properly use this LCD. – user31481 Aug 24 '17 at 14:57
  • thank you for helping me. my lcd already display. can you help me how to active the lcd using push button? – AIN MIMI Sep 5 '17 at 6:05
  • Google "arduino push button lcd" and you will find lot of examples. – user31481 Sep 5 '17 at 7:04
  • i cannot find any examples that suitable. i dont know how to wiring it.can you help me? – AIN MIMI Sep 5 '17 at 7:22
0

The first thing you have to do is run the examples from the library. If that doesn't works, check your connections and components.

If example works, it have to be your sketch (programing problem).

Good practice: write short sketchs that test only one component in your project. Example: your project use a LCD, a temp sensor, and a button, you wrote three short tests. If something goes wrong with your project, you can use the test sketchs to identify where the problem is

3
  • when i compile and upload this coding it didn't show any error. but lcd still cannot display anything. i already run the examples, but lcd still cannot display. what should i do? i just used lcd because i just need lcd to display. but it failed. Thank you for answering my question. – AIN MIMI Aug 23 '17 at 11:51
  • @AINMIMI. I think your LCD initialization is wrong. Your are using an I2C LCD, so initialization must looks like this: LiquidCrystal_I2C lcd(0x27, 16, 2); – user31481 Aug 23 '17 at 12:39
  • i already change it into that but it still didn't work – AIN MIMI Aug 24 '17 at 13:54
0

the black bars indicate that the lcd isn't correctly initialized.

check the hardware / connection and make sure that your software initializes it correctly.

0

I agree with Look Alterno about the LCD initialization. Upload this simple sketch then try adjusting the 10k ohm potentiometer on the back of the I2C circuit board until you can see the text.

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

const byte LCDcolumns = 16;
const byte LCDrows = 2;

// 0x27 is the default address. Is your address 0x3F - if so, change 0x27 to 0x3F
LiquidCrystal_I2C lcd(0x27, LCDcolumns, LCDrows);

void setup(){
  lcd.init();
  lcd.backlight();
  lcd.home();
  lcd.print("16 x 2 LCD Test");
}

void loop(){

}

There could be different versions of the LiquidCrystal_I2C library out there. The "HelloWorld" example that came with my library has the following comments at the top of the sketch:

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1

You could change the I2C address in this sketch to 0x3F and try it again.

The potentiometer that needs adjustment is on your I2C board shown here with a red arrow pointing to it:

Arrow pointing to potentiometer

1
  • i didn't use potentiometer because my lecturer tell me just use lcd. i try the coding that u give but still not working – AIN MIMI Aug 24 '17 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.