LCD displaying white lines [S0lV3D]

I use I2C 4 PIN 16 x 2 LCD.

I compiled the following code and it was compiled sucessfully

// C++ code
//

#include <Adafruit_LiquidCrystal.h>

int trigger = 7;

int echo = 6;
Adafruit_LiquidCrystal lcd_1(0);


void setup()
{
  Serial.begin(9600);
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);
  pinMode(echo, INPUT);
  lcd_1.begin(16, 2);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  pinMode(2, INPUT);
  
}

void loop()
{
  float cm = 0;
  double time = 0;


  digitalWrite(7, HIGH);
  delayMicroseconds(2);
  digitalWrite(7,LOW);
  time = pulseIn(echo, HIGH);
  cm = time*29/2*0.0473/100*2.511111;
  Serial.println(cm);
  
  lcd_1.setCursor(0, 0);
  lcd_1.setBacklight(1);
  lcd_1.print("cm: ");
  lcd_1.setCursor(0, 1);
  lcd_1.print(cm);
  lcd_1.print("cm +-0.1cm");
  delayMicroseconds(30);
}

and for circuit, I used following circuit

but it doesnt work any ideas?

it worked on simulation on tinkercad but it didnt work on real arduino uno

  • Remove the GND from the switch, in fact, keep the LCD power always connected.

  • What is the I2C address ?

1 Like

Hi @jasonbebrilliant ,

install the library "LiquidCrystal I2C" and try this

#include <LiquidCrystal_I2C.h>

const byte I2C_ADDR    =   0x27;
const byte LCD_COLUMNS = 16;
const byte LCD_LINES   = 2;

LiquidCrystal_I2C lcd_1(I2C_ADDR, LCD_COLUMNS, LCD_LINES);

and outcomment the existing lines as follows

//#include <Adafruit_LiquidCrystal.h>
//Adafruit_LiquidCrystal lcd_1(0);

Good luck!
ec2021

P.S.: I looked into the Adafruit_Liquidcrystal Library and found this

  /*!
   * @brief LiquidCrystal constructor for connection over i2c
   * @param i2cAddr Address of the display. Can use either actual I2C address
   * (0x20, 0x21, etc.) or offset from 0x20 base address (0, 1, etc.).
   * @param wire Optional pointer to Wire instance to use. Defaults to Wire.
   */
  Adafruit_LiquidCrystal(uint8_t i2cAddr, TwoWire *wire = &Wire);

So with the right call the lib you are using should support I2C as well.

It might be sufficient to try

Adafruit_LiquidCrystal lcd_1(0x27);

P.P.S.: Neither (0) nor (0x27) does work in the Wokwi Online simulation while the lib LiquidCrystal_I2C works without problems ...

@LarryD : Do you have experience with the Adafruit lib and I2C?

1 Like

ok so i found that the address is 0x27 and changed

Adafruit_LiquidCrystal lcd_1(0);

to


Adafruit_LiquidCrystal lcd_1(0x27);

now it starts to display this:

is this a good sign or bad sign?

*also i removed the switch

oh thanks!

ill try

#include <LiquidCrystal_I2C.h>

const byte I2C_ADDR    =   0x27;
const byte LCD_COLUMNS = 16;
const byte LCD_LINES   = 2;

LiquidCrystal_I2C lcd_1(I2C_ADDR, LCD_COLUMNS, LCD_LINES);

bro i love you
bro i love you
bro i love you
bro i love you
bro i love you
bro i love you
bro i love you
bro i love you
bro i love you
bro i love you
bro i love you
bro i love you
bro i love you
bro i love you

thanks too i luv you too

That's too much ... :wink:

Actually the example for i2c displays on github

https://github.com/adafruit/Adafruit_LiquidCrystal/blob/master/examples/HelloWorld_i2c/HelloWorld_i2c.ino

uses the address 0

// Connect via i2c, default address #0 (A0-A2 not jumpered)
Adafruit_LiquidCrystal lcd(0);

so you used a correct call but it seems not to work in simulation and reality (where reality is more relevant).

Have fun!
ec2021

  • Yes

I understand that it should work for standard 0x27 address if the call is

Adafruit_LiquidCrystal lcd(7);
or
Adafruit_LiquidCrystal lcd(0x27);

Using zero would address 0x20 as I looked up in the library:

Adafruit_LiquidCrystal::Adafruit_LiquidCrystal(uint8_t i2caddr, TwoWire *wire) {
  _i2cAddr = i2caddr <= 0x07 ? 0x20 | i2caddr : i2caddr;

Both options obviously do not work on Wokwi for (at least for me :wink: ) unknown reasons.

I made a test sketch using both libs depending on a define.

https://wokwi.com/projects/412097242415977473

Maybe a bug in the Wokwi simulation ... ?!?

P.S.: Just found this on github after searching for "Wokwi Adafruit_LiquidCrystal":

It's from 2021 and found in a thread regarding the ATtiny85

https://github.com/wokwi/wokwi-features/issues/152

but probably still valid ...

Think that's enough investigation for today :wink:

1 Like

Please, refrain from starting multiple topics with the same subject.

When I turn the power while the slideswitch is on, it works but if i turn the slideswitch off and on again, it displays some white lines :skull_and_crossbones:

the video link

my code

// C++ code
//

// #include <Adafruit_LiquidCrystal.h>
#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
// #include <string>

const byte I2C_ADDR    =   0x27;
const byte LCD_COLUMNS = 16;
const byte LCD_LINES   = 2;

LiquidCrystal_I2C lcd_1(I2C_ADDR, LCD_COLUMNS, LCD_LINES);

int trigger = 7;

int echo = 6;
// Adafruit_LiquidCrystal lcd_1(0x27);


void setup()
{
  Serial.begin(9600);
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);
  pinMode(echo, INPUT);
  lcd_1.begin(16, 2);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  pinMode(2, INPUT);
  pinMode(8,INPUT);
  
}

void loop()
{
  float cm = 0;
  double time = 0;


  digitalWrite(7, HIGH);
  delayMicroseconds(2);
  digitalWrite(7,LOW);
  time = pulseIn(echo, HIGH);
  cm = time*29/2*0.0473/100*2.511111;
  Serial.println(cm);
  
  lcd_1.setCursor(0, 0);
  lcd_1.setBacklight(1);
  lcd_1.print("cm: ");
  lcd_1.setCursor(0, 1);
  lcd_1.print(cm);
  lcd_1.print("cm +-0.1cm");
  delayMicroseconds(1000);
}

my circuit

I know it worked perfectly without switches, but I want switches for for some reason
:sweat_smile:

is there any ways too do this???

  • LCD is configured at Arduino power up time.

  • Turning the LCD off with a switch, looses this LCD configuration.
    When you turn the LCD back ON with the switch, there is no LCD configuration in the display.

  • A switch can be monitored by the Arduino and the LCD blanked if need be.

2 Likes

To do what, exactly???? What are you trying to accomplish by turning the power off to the display and then never initializing the display in your code?

:sweat_smile: I tried to turn off the display and turn it on again

thanks

Please, refrain from creating multiple topics with the same subject.

Threads merged.

So, just testing and the result is what you can expect if you do not follow through by initializing the controller inside the LCD display.