20x4 LCD Backlight Issues

I'm attempting to use tcMenuGenerator, a menu generator tool that seems very promising.

I'm using an Arduino Mega to control a a 20x4 LCD, using I2C on 0x27 (pins SDA 20 and SCL 21, along with Vcc and Ground). I was using it successfully with the LiquidCrystal_I2C library.

The menu generator uses LiquidCrystalIO, a custom fork of LiquidCrystal included with the tool.

My issue is that the menu text displays on my LCD, but the backlight does not activate. lcd.backlight() doesn't work.

Can anyone point me toward getting the backlight turned on?

I have included the code files generated by the tool on my test run. Some of the files are named "Smoker_Menu", because this system is intended to be a PID control for a smoker, but there is nothing in the attached files except for a few test menu items. I apologize that there are 5 files to look at, but they are all relatively short and I didn't want to omit something important to sorting this out...

Perhaps I should add that the backlight comes on when I power up the system, but then turns off when the sketch finishes loading and starts running.

Also, there are a bunch of pin options for controlling the LCD in the setup for the tool, but since I am using I2C, I didn't know what to do with them and left them at their defaults. They show up in Smoker_Menu.h, lines 28-33. Maybe that is the problem?

I have also attached an image of the options available when running the menu generator.

Thanks in advance.

Smoker_Menu.cpp (1.79 KB)

Smoker_Menu.h (1.49 KB)

Smoker_Menu.ino (158 Bytes)

tcMenuLiquidCrystal.cpp (2.25 KB)

tcMenuLiquidCrystal.h (1.47 KB)

Hi there,

Glad that you are trying out TcMenu.

The backlight will be one of the pins on the 8574 IO device that is connected to your display. I’m actually on my mobile at the moment so can’t download the cpp and header file to take a look. I’d imagine if you know the pin the backlight is connected to, you can just Switch on or off that pin:

First keep a reference to the io device passed to LiquidCrystal - probably ioFrom8574(..) as an IoAbstractionRef

Then just set the appropriate pin ( I think it’s pin 3 by default on the expander ) as output and try it high and low until you get the desired result. TcMenu relies heavily on IoAbstraction, I include a link to an example that will give the idea.

https://github.com/davetcc/IoAbstraction/blob/master/examples/example8574/example8574.ino

I’ll stay subscribed to this so let me know if this is not clear enough.

I’ve raised a bug to support backlight out of the box, rather than needing to hack the cpp file to do it.

Bug raised #24 to track this.

That did it! Thanks much for your help!

Specifically, I modified the [project_name].cpp file by changing

LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7, ioFrom8574(LCD_I2C_ADDR));
LiquidCrystalRenderer renderer(lcd, LCD_WIDTH, LCD_HEIGHT);

to

IoAbstractionRef ioExpander = ioFrom8574(LCD_I2C_ADDR);

LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7, ioExpander);
LiquidCrystalRenderer renderer(lcd, LCD_WIDTH, LCD_HEIGHT);

and adding

ioDeviceDigitalWrite(ioExpander, 3, 1);

to the beginning of the setupMenu() method.

Awesome!

Now I'm off to find out why my rotary encoder is only registering clicks and not rotations... I may pester you again if I can't sort that out tonight.

Thanks again, and nice work on this menu tool!

Figured out the rotary encoder.

I had been using the ClickEncoder library, which doesn't require the use of scarce interrupt pins...

No matter, they aren't in use on this build anyhow. Moving the pins over did the trick.

Thanks again Dave; I'm impressed with the quality of product you've put together as well as your willingness to bail out the clueless neanderthals who put their grubby hands all over it.

PS- if you're desperately seeking a way to spend even more hours on this project, besides dodging the interrupt pin issue, the ClickEncoder library allows a long press event, a release event, and a doubleclick event in addition to the regular old click. Oh, and it also includes acceleration, to speed up the increment when you turn the encoder quickly, which is intuitive and handy to most. Could give your users some added flexibility. I'm more than happy with what you've done, but thought I'd throw this out there.

The switches class that handles the button press does actually support both long presses and repeat presses. I’ve just not worked out what the long press could do in the menu yet. Any feedback welcome!

I’ve looked at acceleration and it’s reasonably easily implemented, but I’ve not had chance to implement yet.

You can put the rotary encoder and any other switches on a pcf8574 or mcp23017 io expander too. I often do that on 32 bit units with less pins. The generator has an option for that I think where you just provide it an IoAbsractionRef. Example: