20x4 backlight problem

so i am trying going to make an ammeter in the future and i am trying out different codes, this one works quite good, except for the fact that the back-light does a flash in the beginning and that’s it, it stays off. The lcd works great in other projects, i am having problem with the light only for this code, can you guys figure out what is wrong ?

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int analogInputvolts = A3;
int readvolts = 0;
float voltage = 0.0;
float volts = 0.0;

void setup() {
  pinMode(analogInputvolts, INPUT);
  lcd.init();
}
float fmap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void loop() {
  readvolts = analogRead(analogInputvolts);
  voltage = fabs(fmap(readvolts, 0.0, 1024.0, 0.00, 5.0));
  volts = voltage * (5.0 / 5.0);
  lcd.setCursor(0, 0);
  lcd.print("SCALE:    0V-5V");
  lcd.setCursor(0, 1);
  lcd.print(volts, 3);
  lcd.setCursor(15, 1);
  lcd.print("V");
  delay(200);
}

Surely you would call lcd.backlight(true); if you want the backlight on.

Different libraries might have different method names. And probably different default states.

Life is much safer with "hd44780" library which is documented and reliable.

David.

i get an error that says no matching function. i am a beginner in all this, i don't quite understand everything you said. sorry

lcd.setBacklight(HIGH); // ON

david_prentice:
Surely you would call lcd.backlight(true); if you want the backlight on.

larryd:
lcd.setBacklight(HIGH); // ON

Actually, both of those are incorrect.
According to LCD API 1.0 spec, ( Arduino Playground - LCDAPI ) setBacklight(dimvalue) takes a dimvalue argument.
To use HIGH is abusing the setBacklight(dimvalue) API as the function is intended for setting an intensity and HIGH (which is typically defined as 1) is a very dim value.
In the case of i2c backpack libraries they should pick "full on" when 1 is passed since they don't support dimming.
But still, passing HIGH is actually abusing the API since you really can't even depend on HIGH be 1, and when it is 1 would create backlight issues if the code were moved to an LCD module that did support dimming.

API functions backlight() and noBacklight() were introduced by newLiquidCrystal and take no arguments.

For this application, I would use backlight() and noBacklight() for backlight control,
and of course I would also use the hd44780 library.

--- bill

Actually this one "lcd.setBacklight(HIGH);" did the job, thank you so much.

You can as they say ...

Yup, i am once again jumping head first into things, but this will be my last project, possibly until i retire because i bought a piece of land and i need a solar charger for a cabin made by me, well, us, because there are a lot of kind people here :slight_smile:
I am thanking you in advance for every small pointed finger in the right direction i will get.

I am using below code but backlight is not turning on. Please help

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd;

const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
// lcd.init(); // initialize the lcd
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.backlight();
delay(250);
lcd.setBacklight(HIGH);
delay(250);

lcd.setCursor(0, 0);
lcd.print(“Code Alpha!”);
delay(2000);
}
void loop(){}
// put your main code here, to run repeatedly:

Backlight turns on on my LCD running your code on an Uno.

Is there a jumper on the I2C backpack for the backlight? Is the jumper in place?

Does any text show on the LCD with the contrast adjusted properly?

Thanks for your responce.

Yes, jumper is very well placed.

Texts are visible only backlight is not litting.

pankajsharma200:
Thanks for your responce.

Yes, jumper is very well placed.

Texts are visible only backlight is not litting.

Please respond.

I do not know what else can be wrong. Are you sure that the LCD has a backlight? I had some LCDs, a long time ago, that had no backlight.

Can you post photos of the LCD showing the solder joints between the LCD and I2C backpack?

pankajsharma200,

 lcd.backlight();
  delay(250);
  lcd.setBacklight(HIGH);
  delay(250);

does not make sense.
There is no need for delays and no need for multiple calls.

Also, once again, setBacklight(dimvalue) DOES NOT take a HIGH/LOW parameter.
I know that there may be code examples out there that incorrectly use setBacklight(), but
setBacklight(dimvalue) takes a dimvalue parameter NOT HIGH/LOW, zero/non-zero, 0/1, true/false.
setBacklight(dimvalue) takes a value between 0 and 255 to control the backlight intensity.
It happens to "work", for devices that do not support dimming, but will produce a very dim backlight (almost off) on devices that do support dimming.

As always, my suggestion is to run the I2Cexpdiag to checkout things out.
It could be that LCD module being used has a design that the hd44780_I2Cexp code cannot detect the active level.

--- bill

Thanks Bill for you guidance. I corrected accordingly and also executed suggested I2C diagnostic tool. I am attaching result below. Please guide me

It blinks BL Off three to four times without backlight then time starts

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd;

const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.setBacklight(200);
lcd.setCursor(0, 1);
lcd.print(“Code Alpha!”);

}
void loop(){}
// put your main code here, to run repeatedly:


Serial Initialized

I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool

hd44780 lib version: 1.3.1

Reported Arduino Revision: 1.8.13
CPU ARCH: AVR - F_CPU: 16000000

SDA digital pin: 18 A4
SCL digital pin: 19 A5

Checking for required external I2C pull-up on SDA - YES
Checking for required external I2C pull-up on SCL - YES
Checking for I2C pins shorted together - Not Shorted

Scanning i2c bus for devices…
i2c device found at address 0x27
Total I2C devices found: 1

Scanning i2c bus for all lcd displays (4 max)
LCD at address: 0x27 | config: P01245673L | R/W control: Yes
Total LCD devices found: 1

LCD Display Memory Test
Display: 0
Walking 1s data test: PASSED
Address line test: PASSED

Each working display should have its backlight on
and be displaying its #, address, and config information
If all pixels are on, or no pixels are showing, but backlight is on, try adjusting contrast pot
If backlight is off, wait for next test

Blinking backlight test: to verify BL level autodetection
If backlight is mostly off but
you briefly see “BL Off” on display with backlight on,
then the library autodetected incorrect BL level
and the library cannot autoconfigure the device

Displaying ‘uptime’ on all displays

  lcd.begin(LCD_COLS, LCD_ROWS);
  lcd.setBacklight(200);

Two things to note about this.

  1. begin() turns on the backlight at full intensity, if device has a backlight
  2. you are using a device that does not support dimming.
    So trying to set the intensity at 200/255 brightness is not possible on that type of device.
    You will get full brightness.

The call to setBacklight() is not necessary as begin() turns on the backlight.
You will see this noted in the HelloWorld example.

The diagnostic passed.
Did you see the backlight ever turn on?

Post some photos of your device so we can see what you have.
Show the front and back of the LCD so we can see LCD and the backpack and the soldering.

--- bill

a. Please find pictures of LCD

b. Did you see the backlight ever turn on?

Yes, it worked earlier.

c. begin() turns on the backlight at full intensity, if device has a backlight

Commented setBacklight()

Thanks

A.jpg

B.jpg

C.jpg

A.jpg

B.jpg

C.jpg

It is a bit hard to tell from your photo, but it looks like you have several soldering issues.
There can be lots of strange issues when there are poor electrical connections.

I'm curious why you decided to solder the backpack to the LCD that way.
Backpacks are not usually soldered to the LCD that way. They are typically put on the back of the LCD.

--- bill