0

I have 16x2 LCD display with a I2C backpack. This is the library I am using https://drive.google.com/drive/folders/16_UqfwFm4VKWcdeJfDmHRV2Hj_IoaTai?usp=sharing

So as given in the code below, by changing variable back to a 0 or 1, I can turn on and off the backlight. However if I change the values of back to 100, or 50 the backlight does not get affected, how do I make this happen without the need of an external resistor/potentiometer and but with code.

Note that on my backpack, there is no connection between pins A and K to keep the backlight on but if I connect the two, then the backlight is turned off.

If you don't care of the above here's it summarized-

How do I control Backlight of LCD with I2C backpack through code?

Code-

#include "LiquidCrystal_PCF8574.h"
#define LCD_ADDRESS 0x27
#define LCD_ROWS 2
#define LCD_COLUMNS 16
#define SCROLL_DELAY 150
int back = 1; // 1-on, 0-off

LiquidCrystal_PCF8574 lcdI2C;

void setup(){
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);
}

void loop(){
delay(1000);
back = 0;
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);
delay(1000);
back = 1;
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);

}
2

You don't. The PCF8574 is an IO expander. It doesn't have any provision for PWM. It's either on, or off.

8
  • Ok, kinda disappointing, but good to know
    – Coder9390
    Jun 20 at 14:08
  • Can I just use analog write and connect that pin to Pin A on the lcd?
    – Coder9390
    Jun 20 at 14:14
  • 1
    @Coder9390, if you want to do that, you should probably interpose a transistor. The backlight current is typically more than you'd want going through an Arduino I/O pin.
    – timemage
    Jun 20 at 14:20
  • ....and then use PWM on the transistor right
    – Coder9390
    Jun 20 at 14:32
  • Note that on my backpack, there is no connection between pins A and K to keep the backlight on but if I connect the two, then the backlight is turned off. -- Sounds like you're short circuiting the back light there.
    – Majenko
    Jun 20 at 14:34

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.