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