LCD backlight control

I use the Noiasca lcd library, because the text i receive over the serial port is in german and can contain umlauts,

There is the function 'lcd.backlight();

if this is put in the setup, it turns the backlight on.

But how would i turn the backlight off?
i know commenting 'lcd.backlight();' out does that,
but i want to be able to turn the backlight on or off as needed using commands in the loop part of the sketch,

Is this an option here, or should i just use the old way with a digital write high or low to the pin the backlight transistor is connected to, and ignore the backlight bit in the setup.

lcd.noBacklight();

will turn the backlight off.
by the way... this forum has a very active German section also.

Oh boy, i really show how stupid i am at programming when i couldn't work that out :slight_smile:
Thankyou for that.

Unfortunately i can only speak the very basic German i learnt at middle school, Dad was in the RAF, we're from england, and we were fortunate enough to be posted to Germany 2 times, so i lived and grew up in Germany from age 6 to 13 (1983 to 1990)
Annoyingly when back in england it was french we were taught, and i did not pick that language up at all.

But they say your early years shape you, so I have a definite love for German things,

Hence the bus simulator 'Omsi' is something i am into in a fairly big way, as it allows me to kind of re-live my youth, only instead of being a passenger on the bus from Krefeld to Düsseldorf for school every day, i 'virtually' drive the bus around German towns and cities.

All my arduino projects are related to connecting parts from real buses to the computer, i have the dashboard from a MAN NG272 that spent it's working life driving around Köln, and all the lights and gauges work showing the same values as in the simulator.
Over the past few years i've been collecting the other parts to build a replica 'Fahrerarbeitsplatz / Drivers cab'

There's only a few parts left that i need to complete it, but with england leaving the eu the German bus scrap yards do not wan't to deal with sending parts to england, or even replying to english emails requesting to buy parts at the moment :frowning:

Wondering if the backlight bit only works with i2c lcd's?

i'm using the 'NoiascaHW/lcd_4bit.h' library, lcd connected in paralell mode.

Backlight connected via a transistor to pin 9,

i have 'const byte bl = 9;' in the lcd setup, but calling 'lcd.backlight()'' does not turn it on,

it does turn on if i use the 'pinMode(9, OUTPUT);' then 'digitalWrite(9, HIGH);' method,

can you please make a drawing how you have wired the Arduino/Transistor/Resistor?/LCD because I'm testing with a keypad/lcd shield and this is working. So I would like to hook up something similar on a breadboard...

Here's the schematic i followed, i believe it will be something i've screwed up of course.

I've done this so i can have the lcd's contrast adjustable with the arduino, and also control the backlight, for my use i want to turn the backlight on and off when the bus headlights are on or off in the simulator.

I may want to have adjustable backlight control later, but for that i might have to do it the other way using a pwm signal on the backlight pin to vary the voltage... unless the 'lcd.backlight();' can set a value othe than on and off?

Some displays have a current limiting resistor on the LCD board, however, the emitter resistor should be moved to the collector, try 100R; change the base resistor to 220R.

Ahh yes, thankyou for pointing that out, i am figuring out issues with that schematic.

A big one is that for the contrast part of that circuit there needs to be a resistor between the arduino pin and capacitor, making a low pass filter,
But with just the capacitor as show in the schematic, it can damage the arduino due to high current flow each time the cap discharges (which is many times a second)

So i think i will simply remove the arduino controlled contrast part, and go back to using a 1k pot, as really the contrast is a set and forget thing.

I will change the resistor location and value of the base resistor that tomorrow,
The lcd has a 51 ohm resistor on board for the backlight.

Iv'e made the changes to the hardware,
removed the capacitor and the 'ability' to set ldc contrast by the arduino, gone back the the old tested method of the trimpot,

changed the transistor arrangement for the backilgiht, put a 100 ohm resistor on the collector, emitter to ground, and a 220 ohm resistor on the base.

The hardware side works, but i still cant get anything from calling the lcd.backlight(); or lcd.noBacklight(); functions :frowning:

It does work when i do a pinMode(10, OUTPUT) then call analogWrite(10, 50); to set the backlight at a fairly dim output, or a digitalWrite to set it either on or off,

As i want to have a few levels of backlight brightness, for day, night and off modes, am i right in thinking i have to do it the way i am doing it now,

And i can't call lcd.backlight(50); to set the backlight on at the intensity i want? i.e. lcd.backlight(); is for on, and off is noBacklight, and there's no way to vary the intensity here.

It is always wise to run library examples first. e.g.
C:\Users…\Documents\Arduino\libraries\NoiascaLiquidCrystal\examples\01_parallel\0401_4bit_HelloWorld\0401_4bit_HelloWorld.ino

const byte cols = 16;                  // columns/characters per row
const byte rows = 2;                   // how many rows
const byte rs = 8;
//const byte rw = 255;                 // set to 255 if not used - for future use
const byte en = 9;
const byte d4 = 4;
const byte d5 = 5;
const byte d6 = 6;
const byte d7 = 7;
const byte bl = 10;                    // set to 255 if not used

#include <NoiascaLiquidCrystal.h>      // use the adopted library downloaded from https://werner.rothschopf.net/202003_arduino_liquid_crystal_umlaute.htm  
#include <NoiascaHW/lcd_4bit.h>        // parallel interface, 4bit
LiquidCrystal_4bit lcd(rs, en, d4, d5, d6, d7, bl, cols, rows);  // create lcd object

No. I have not installed this library. But it looks as if you simply set the bl argument to the correct pin. And the backlight functions should work.

If they don’t. Quote the example by name. And Noiasca will fix it.

Just saying “does not work” is no help unless you quote which example does not work. Possible with an excerpt of configuration code pasted to a “code window” in your message e.g. like I did

David.

Sorry about that, i’m still trying to learn this programming thing.

So, using the ‘0401_4bit_HelloWorld’ sketch by Noiasca,

const byte cols = 24;                  // columns/characters per row
const byte rows = 2;                   // how many rows
const byte rs = 8;
//const byte rw = 255;                 // set to 255 if not used - for future use
const byte en = 9;
const byte d4 = 7;
const byte d5 = 6;
const byte d6 = 5;
const byte d7 = 4;
const byte bl = 10;                    // set to 255 if not used

#include <NoiascaLiquidCrystal.h>      // use the adopted library downloaded from https://werner.rothschopf.net/202003_arduino_liquid_crystal_umlaute.htm  
#include <NoiascaHW/lcd_4bit.h>        // parallel interface, 4bit
LiquidCrystal_4bit lcd(rs, en, d4, d5, d6, d7, bl, cols, rows);  // create lcd object

void setup()
{
  lcd.begin();                         // initialize the LCD
  lcd.backlight();                     // turn on backlight

And the backlight does not turn on,
i’ve tried ‘lcd.noBacklight();’ as well, just in case it’s a low signal to turn mine on, and it’s not.

My backlight does work, as if i use…

  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

… in the same sketch, in place of ‘lcd.backlight();’

Don't panic. You have reported a problem and posted clear evidence. Absolutely correctly.

Wait for a few hours / days. Noiasca is often on the Forum. So he will see your message.

Yes, it will be nice to fix it. Meanwhile you can use digitalWrite() until this is done.

David.

p.s. it looks as if this is a private repository without an official means to report an "Issue"

Most Arduino libraries are hosted on GitHub. If you have a problem, there is a standard way to report an "Issue" or a "Pull Request". Library authors will probably respond to GitHub faster than an Arduino Forum.

Mind you, GitHub is more suitable for well written technical questions or problems.
The Arduino Forums are better for "many readers" and simple problems.

as offered yesterday, if you draw a short schematic of your wiring I will put it together on a breadboard. But I can't follow a written description or a wrong picture with commented changes. Please do a drawing.

Currently I can only confirm, that my keypad/LCD is working accordingly, but this might (will) have another schematic and the lib uses a hack for faulty keypads/LCD.

ps.:
this makes me somehow inconfident:

analogWrite(10, 50); to set the backlight at a fairly dim output,

and therefore I would like to see how you have connected the transistor.

gazz292:
get anything from calling the lcd.backlight(); or lcd.noBacklight(); functions
}

Look what I found in NoiascaLiquidCrystal.cpp:

expanderWrite(_backlightval); // reset expander and turn backlight off (Bit 8 =1)  // MISSING: checken, was tun bei Klassen ohne expander

void LiquidCrystal_dummy::noBacklight(void) {
  _backlightval = LCD_NOBACKLIGHT;
  expanderWrite(0);
}

void LiquidCrystal_dummy::backlight(void) {
  _backlightval = LCD_BACKLIGHT;
  expanderWrite(0);
}

void LiquidCrystal_dummy::expanderWrite(uint8_t _data) {
...
  //Wire.beginTransmission(_Addr);
  //Wire.write((int)(_data) | _backlightval);
  //Wire.endTransmission();
}
  • "checken, was tun bei Klassen ohne expander" - tells me this was written for use with expander (like PCF8574, I guess).
  • "//Wire.write((int)(_data) | _backlightval);" - this is where it was supposed to happen, I think.

Maybe removing all slashes in expanderWrite() can make it work? Or crash, I don't know... :wink:

This is how i wired up the transistor,

it's just a cheap common npn transistor, equivelent to a 2N2222,

Re: the analogWrite thing,
Changing the analogWrite number varies the brightness of the backlight, it's my understanding that the pwm from the arduino turns the transistor on and off rapidly, and varying the number in the command will vary how hard the transistor turns on, which varies the ammount of current it allows to pass, thus varying the backlights brightness,

So analogWrite(10, 255); turns the backlight fully on (well, almost, there will be a little loss in the transistor)

and analogWrite(10, 1); makes the backlight extremely dim, so any number between is a different backlight level,

But i can't get the lcd.backlight(); command to turn the led on for some reason,

Where as doing a digitalWrite(10, HIGH); does turn the backlight on (after declaring the pin to be an output of course)

i know i will likely have to do all the backlight dimming with analogWrite commands, but i'm curious why i cant get the lcd.backlight(); command to work, i've tried 2 different arduino uno's,

By the way, thankyou so much for creating the Nosiasca lcd library's,
Being able to display capital and lowercase umlauts on a standard lcd just by typing them is a game changer for me, before scripts i've seen wrote their own characters and did all the stuff to send them to the lcd each time they needed to display an umlaut,

But that doesent make it easy when my sketch will be reading a serial stream that contains German words thus umlauts are standard, and displaying the strings on the lcd, now i can just read the incoming serial data, split it up and write it to the lcd in the places i want.

gazz292 …

could you please be so kind and try this sketch.
Modify the pins to your need.
It should blink the backlight.

/*******************************************************************************
   Custom Backlight for NoiascaLiquidCrystal
   by noiasca
   2020-11-05
   
*******************************************************************************/

const byte cols = 16;                  // columns/characters per row
const byte rows = 2;                   // how many rows
const byte rs = 8;
const byte en = 9;
const byte d4 = 4;
const byte d5 = 5;
const byte d6 = 6;
const byte d7 = 7;
const byte bl = 13;                    // Backlight

#include <NoiascaLiquidCrystal.h>      // use the adopted library downloaded from https://werner.rothschopf.net/202003_arduino_liquid_crystal_umlaute.htm  
#include <NoiascaHW/lcd_4bit.h>        // parallel interface, 4bit

class MyLCD_4bit : public LiquidCrystal_4bit {
  protected:
    const byte blPin;
    
  public:
    MyLCD_4bit(uint8_t rsPin, uint8_t enPin, uint8_t d4Pin, uint8_t d5Pin, uint8_t d6Pin, uint8_t d7Pin, uint8_t blPin, uint8_t lcd_cols, uint8_t lcd_rows) :
      LiquidCrystal_4bit(rsPin, enPin, d4Pin, d5Pin, d6Pin, d7Pin, blPin, lcd_cols, lcd_rows),
      blPin(blPin)
    {}

    void noBacklight(void) {
      digitalWrite(blPin, LOW);
    }

    void backlight(void) {
      digitalWrite(blPin, HIGH);
    }
};

MyLCD_4bit lcd(rs, en, d4, d5, d6, d7, bl, cols, rows);  // create lcd object for your new class

void setup()
{
  lcd.begin();                         // initialize the LCD
  //pinMode(bl, OUTPUT);
  lcd.backlight();                     // turn on backlight
  lcd.setCursor(2, 0);
  lcd.print("Hello, world!");
  lcd.setCursor(0, 1);
  lcd.print("αβμΣ°÷∞←→äöüßÄÖÜ");     // show some special character entered in UTF-8
}

void loop()
{
  lcd.noBacklight();
  delay(500);
  lcd.backlight();
  delay(2000);
}

does it blink?

if you need another converter (small/Ae/special) just let me know, currently this parameter is not in this example.

@Erik that’s just a dummy class, the grandparent. The implementation of the backlight will differ in the several hardware classes. The Expander is in the dummy because the I2C class and the SPI class are using the same code. I was to lazy to make a further class. I should for sure search for “MISSING” comments in my code for the next release :confused:

that sketch does blink the backlight

sounds good.

I will check tomorrow with hardware what I can do regarding the dimming, but that should be straight forward, mostly I have to see what the LCD API says about the naming convention (if any).

Nevertheless these changes will not get into the library for the 4bit class.
~~But I hope this inherited "MyClass_4bit" pattern in your user sketch is acceptable - it's just the 10 lines of code you have to add. ~~

edit: I will adopt the library, but I have to do some additional testing. In the meantime you can use the workaround with the local class as shown with the additional 10 lines of code.

Do you need support of any custom character converter or are you just using the default replacement from Ä to A (large Umlaut to plain character)?

gazz292:
And i can't call lcd.backlight(50); to set the backlight on at the intensity i want? i.e. lcd.backlight(); is for on, and off is noBacklight, and there's no way to vary the intensity here.

The LCD API 1.0 defines 3 functions for backlight control:
backlight() - turn on backlight
noBacklight() - turn off backlight

setBacklight(dimlevel) - to turn on backlight with dimlevel backlight intensity

From looking at the code for the noaiscaLiquidCrystal library lcd_4bit i/o class. it looks like, unfortunately, it doesn't implement this as specified in LCD API 1.0 so there is no way to set a backlight intensity even if you call setBacklight(dimlevel)

Also, the code appears to not drive the backlight pin HIGH to drive the backlight circuit but rather sets the pin to input mode instead.
This may cause backlight issue depending on the backlight circuit, like if it doesn't have a pullup to turn on the circuit if it isn't driven by the Arduino pin.
This was likely done to avoid a short circuit created by the broken LCD keypad backlight circuit on some LCD keypad shields that creates a short when the backlight control pin is set to HIGH.

If you really want/need backlight dimming, you may want to look at the the hd44780 library which supports backlight control, including dimming, using the LCD API 1.0 api function setBacklight(dimlevel).

--- bill