Controlling backlight of Waveshare LCD 1602 I2C Module using hd44780 library

Hi

I am trying to control the backlight of waveshare 1602 i2c module (or alternatively setting the display to off) using the hd44780 library.

I am able to write text to the lcd (Using the simple Hello World sketch from the library examples) and use the AutoScroll function, so I am assuming the wiring is not a problem. I have already tried using noBacklight, noDisplay, off, SetBackLight(0), setContrast(0) without any effect.

Waveshare does provide a library of it's own, https://www.waveshare.com/w/upload/d/db/LCD1602_I2C_Module_code.zip , but while it has constants define for Display OFF (#define LCD_DISPLAYOFF 0x00), it also does not work.

This is my code as of now:



#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Clcd.h> // i2c LCD i/o class header

// declare the lcd object for auto i2c address location
hd44780_I2Clcd lcd;

//
// enter address of LCD.
// Addresses seen so far include:
// - 0x3a, 0x3b (PCF2119x)
// - 0x3c (unknwon chip)
// - 0x3d (unknwon chip)
// - 0x3e (unknwon chip)
// - 0x3f (unknwon chip)

// declare i2c address and constructor for specified i2c address
//const int i2c_addr = 0x3e;
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address

#define LCD_DISPLAYOFF 0x00

// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
void setup()
{
int status;

	// initialize LCD with number of columns and rows: 
	// hd44780 returns a status from begin() that can be used
	// to determine if initalization failed.
	// the actual status codes are defined in <hd44780.h>
	// See the values RV_XXXX
	//
	// looking at the return status from begin() is optional
	// it is being done here to provide feedback should there be an issue
	//
	status = lcd.begin(LCD_COLS, LCD_ROWS);
	if(status) // non zero status means it was unsuccesful
	{
		// begin() failed so blink error code using the onboard LED if possible
		hd44780::fatalError(status); // does not return
	}

	// Print a message to the LCD
	lcd.print("Hello, World!");
  delay(2000);

  int rv;
  rv = lcd.noBacklight();
  Serial.print("noBacklight -> ");
  Serial.println(rv);

  rv = lcd.noDisplay();
  Serial.print("noDisplay -> ");
  Serial.println(rv);

  rv = lcd.off();
  Serial.print("off -> ");
  Serial.println(rv);

  rv = lcd.setBacklight(0);
  Serial.print("setBacklight -> ");
  Serial.println(rv);
  
  rv = lcd.setContrast(0);
  Serial.print("setContrast -> ");
  Serial.println(rv);

  rv = lcd.command(LCD_DISPLAYOFF);
  Serial.print("command -> ");
  Serial.println(rv);
}

void loop() {}

Results of various commands that I have tried in the code:

00:02:37.818 -> noBacklight -> -3
00:02:37.819 -> noDisplay -> 0
00:02:37.819 -> off -> 0
00:02:37.819 -> setBacklight -> -3
00:02:37.819 -> setContrast -> -3
00:02:37.819 -> command -> 0

If the module is not supporting display off, would it make sense that I power this module off a digital pin from Arduino, setting it to high or low as needed, or will this draw more power than can be provided by a digital pin ?

hd44780 library https://github.com/duinoWitchery/hd44780
Waveshare LCD 1602 I2C Module https://www.waveshare.com/lcd1602-i2c-module.htm
http://www.waveshare.com/wiki/LCD1602_I2C_Module

P.S. : Using Arduino MKR 1010 WIfi

Most of those displays have the backlight powered directly by the A/K pins. If so, you can drive those pins with a PWM signal to modulate the backlight directly in hardware, no driver needed.

Sorry for the dumb question, but what are A/K pins ? By any chance, are they the VCC and GND pins on the module (I2C is inbuilt in the module, it doesn't expose any of the other pins )

"A" refers to the backlight LED anode.
"K" refers to the backlight LED cathode.

The anode is usually pin 15 and the cathode pin 16.

I2C backpack overrides Anode/K(c)athode, the back light led direct pins.

In my case, since the i2c is the only connection to the LCD (it's a module with builtin i2c, doesn't expose all the other pins a normal lCD exposes), I don't think that would work for me.

Post a picture of the rear side.

@amitabhkant
a)
please post a link to the product and a link to the datasheet.

If you see the zip you have posted and check the OEM Library you will see, that there is no member function for backlight control.
the private variable uint8_t _backlightval; in the .h file is not used in the .cpp
So I doubt you don't have backlight control via I2C - therefore - please let us check the product.

b)
check with an I2C scanner which I2C addresses are recognized on your bus. It might be that backlight control is done with another IC/another address.

c)

that's not the backlight, that's for the display itself...


This is the backside of the module

@noiasca

a)
LCD1602_I2C_Module.pdf (1.1 MB)
This is the datasheet.
https://www.waveshare.com/wiki/LCD1602_I2C_Module & https://www.waveshare.com/lcd1602-i2c-module.htm are the only two relevant pages I could find for the module from the manufacturers website.

b) Will check with an I2C scanner to see if any other I2C address is available

c) I though so, but I mistakenly assumed that setting the display off might do the trick, as I need the display to be on for a very brief period of time

b) please report the output of the I2C Scanner.

The datasheet is not very clear.
On one hand chapter 4 shows a hardwired backlight.
On the other hand chapter 8 states a PCA9633DP2 (RGB)
But based on your picture I assume there is no PCA9633 on your LCD
it might be you are sticked with an always on Backlight.

15:49:46.617 -> I2C device found at address 0x3E !
15:49:46.617 -> I2C device found at address 0x60 !
15:49:46.617 -> I2C device found at address 0x6B !

@noiasca if I am stuck with always on backlinght, can I use one of the digital pins to power the lcd ?

interesting.

0x3E is the display driver AIP
0x60 / 0x6B might be the display control for the PCA

If it is a non commercial project you can try my LCD library:

https://werner.rothschopf.net/202009_arduino_liquid_crystal_wire_en.htm

start with the examples from 05_wire

@noiasca your library also makes no effect to the backlight.

Using a digital pin to provide power doesn't work. Backlight switches on, but no text is displayed. [Updated to clarify what I was talking about]

so backlight control is working but the LCD doesn't show characters?
or is the backlight just on and stays on?

backlight just on and stays on

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