I2C Bus LCD Problem

Hi. My LCD is not showing anything. I am using an I2C bus. Does anyone know what is wrong?

#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <ezButton.h>

#define Ypos A0
#define P1 A1
#define P2 A2
#define ESC_PIN 2
Servo esc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
ezButton button(3);

int speed = 0;
int Press1;
int Press2;
int avg_Ps;

void setup() {
  lcd.noBacklight();
  lcd.setBacklight(50);
  lcd.backlight();
  lcd.setCursor(1, 1);
  lcd.print("hello World");
  Serial.begin(9600);
  lcd.print("Calibrate?");
    delay(3000);
  if (button.isPressed()) {
    esc_init(1000, 2000);
    lcd.clear();
    lcd.print("Calibrated!");
    delay(1000);
    lcd.clear();
  } else if (!button.isPressed()) {
    lcd.clear();
    lcd.print("Skipped.");
      delay(1000);
    lcd.clear();
    esc.attach(ESC_PIN, 1000, 2000);
  }
  pinMode(Ypos, INPUT);
  pinMode(P1, INPUT);
  pinMode(P2, INPUT);
}

void loop() {
  lcd.print("Starting wind...");
  lcd.clear();
  lcd.setCursor(1, 1);
  for (speed = 0; speed == 180; speed++) {
    esc.write(speed);
    lcd.print("RPM =");
    lcd.setCursor(1, 6);
    int RPM = map(speed, 0, 180, 0, 35000);
    lcd.print(RPM);
    Press1 = analogRead(P1);
    Press2 = analogRead(P2);
    avg_Ps = (Press1 + Press2)/2;
    lcd.println("Pressure:");
    lcd.setCursor(2, 10);
    lcd.print(avg_Ps);
  }
}
void esc_init(int min, int max) {
  esc.attach(ESC_PIN, min, max);
  esc.write(180);
  delay(5000);
  esc.write(0);
  delay(2000);
  esc.write(10);
}

I see two potential problems. One I do not have a clue if it is connected properly, an annotated schematic would be a big help. Two there is more then one library with that name, not sure which one you have. Mine needs a statement lcd.begin(), That Initializes the interface to the LCD screen. It also specifies the display configuration ie width and height in characters of the display. Note begin() must be called before any other LCD library commands.

Try the following adjusted sketch of post #1.

#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <ezButton.h>

#define Ypos A0
#define P1 A1
#define P2 A2
#define ESC_PIN 2
Servo esc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
ezButton button(3);

int speed = 0;
int Press1;
int Press2;
int avg_Ps;

void setup()
{
  Serial.begin(9600);
  lcd.begin(); //or lcd.init()
  lcd.backlight();
  lcd.setCursor(0, 0); //dp0; line-0
  lcd.print("hello World");
  lcd.setCursor(0, 0); //dp0; line-0
  lcd.print("Calibrate?");
  delay(3000);
  if (button.isPressed())
  {
    esc_init(1000, 2000);
    lcd.clear();
    lcd.print("Calibrated!");
    delay(1000);
    lcd.clear();
  }
  else if (!button.isPressed())
  {
    lcd.clear();
    lcd.print("Skipped.");
    delay(1000);
    lcd.clear();
    esc.attach(ESC_PIN, 1000, 2000);
  }
  pinMode(Ypos, INPUT);
  pinMode(P1, INPUT);
  pinMode(P2, INPUT);
}

void loop()
{
  lcd.print("Starting wind...");
  lcd.clear();
  lcd.setCursor(0, 1);
  for (speed = 0; speed <= 180; speed++)
  {
    esc.write(speed);
    lcd.print("RPM =");
    lcd.setCursor(5, 1); //two line lcd
    int RPM = map(speed, 0, 180, 0, 35000);
    lcd.print(RPM);
    Press1 = analogRead(P1);
    Press2 = analogRead(P2);
    avg_Ps = (Press1 + Press2) / 2;
    lcd.println("Pressure:");
    lcd.setCursor(2, 10);
    lcd.print(avg_Ps);
  }
}
void esc_init(int min, int max)
{
  esc.attach(ESC_PIN, min, max);
  esc.write(180);
  delay(5000);
  esc.write(0);
  delay(2000);
  esc.write(10);
}

You should firstly confirm you have the correct address for the LCD.

Try the I2C scanner sketch and per the following...
https://playground.arduino.cc/Main/I2cScanner/

Hi,

Have you tried one of the example codes that comes with that library?

Forget your code for the moment and get back to just running the LCD software, this will prove if your hardware is okay.

Have you written your code in stages?

  1. Code to JUST get LCD working, try an example eg, Hello World.
  2. Code JUST to get the servo working, try an example.
  3. Code to JUST check the ezButton library, try an example.
  4. Code to JUST check the ESC library, try an example.

When you have all of those working individually, combine them ONE at a time, debugging before adding the next bit of code.

This way you will have fewer bugs as you approach the final code.

Tom... :smiley: :+1: :coffee: :australia: :santa:

Yea I do.

Yea you do what?

If you have code that works please post that as well.

As in completely blank, or do you see a row of boxes.

Do you have a contrast adjustment pot on your LCD?

Have you tried the contrast adjustment?

For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.

To install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.

The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results.

For best help, post a schematic showing how the display should be connected and photos showing how it is connected.

Hi,
with some new LCD_i2c DFR0063 DFROBOT (new = with 2 connectors HE10) there are problems.
Those LCDs work with UNO board but not with nano every.
There are 2 mosfet transistors between four 10K resistors, bottom center on the board I2C.
Just remove them.
they are sometimes triggered and produce disturbances on the I2C bus.

ByeBye

...and you can use the traditional #include <LiquidCrystal_I2C.h>

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