8 years, 7 months ago.

How can I switch "on" and "off" my 16x2 LCD display.

I have setup a 16x2 LCD display HD44780 with I2C interface. The library files are

  1. include "mbed.h"
  2. include "TextLCD.h"

It works great with:

lcd.cls(); lcd.printf("Hello World!\n"); lcd.locate(1,1); lcd.printf("Val: %f", ana_val);

However i do not know the command to switch ON/OFF the backlight. Can anyone tell me how to do this. (Where can I find this kind of information myself???)

Thank, Harrie

1 Answer

8 years, 7 months ago.

Please use <<code>> and <</code>> tags on separate lines around your posted code above to keep it readable.

I assume you are using my enhanced TextLCD lib with an I2C expander port device like the pcf8574 to control the LCD. The lib has a method to set or reset a bit on the expander that should drive the backlight LED through a driver transistor. The API link is on the component page for TextLCD. Check the TextLCD notebook page for a wiring example and more info https://developer.mbed.org/users/wim/notebook/textlcd-enhanced/

Accepted Answer

Hello Wim, Thanks for your answer.

Yes, I am using the enhanced lib with an I2C expander port with a pcf8574. I am stil not able to switch on the backlight because I do not know the instruction code. I tried things like <<code>> lcd.setBacklight(LCDBacklight LightOn); <</code>> without succes.

What is the right syntax to switch on the backlight???????? (I was not able to find it myself!)

I "rewired" the port as follows, which appeared to work.

define D_LCD_PIN_D4   4 // 0
#define D_LCD_PIN_D5   5 // 1
#define D_LCD_PIN_D6   6 // 2
#define D_LCD_PIN_D7   7 // 3
#define D_LCD_PIN_RS   0 // 4
#define D_LCD_PIN_E    2 // 5
#define D_LCD_PIN_E2   1 // 6
#define D_LCD_PIN_BL   3 // 7

Thanks, Harrie

posted by Harrie Vandenhork 09 Sep 2015

Check the LCD datasheet. First make sure the display has a backlight. Some have the pins 15 (anode) and pin 16 (cathode) for the backlight but there is no actual LED mounted on the display. There may also be jumpers that disable the backlight or even switch it on permanently. Some (older) displays may also have reversed the pins: pin 16 is anode and pin 15 is cathode.

Try to power the backlight indepently from the portexpander to make sure it works.

You should be able to use any pin mapping you like as long as the #defines above match the wiring. In your case the Backlight control bit has been mapped to bit 3 of the PCF8574 portexpander. When you call the method

lcd.setBacklight(TextLCD::LightOn);

the corresponding bit 3 should toggle between low and high level. Can you observe that with a multimeter or similar?

Finally check the driver transistor between the portexpander and the backlight. In most cases an NPN transistor is used to switch pin 16 (cathode) to GND. The anode (pin 15) should be tied to VCC (typically 5V)

posted by Wim Huiskamp 09 Sep 2015

You made my day, Wim..

It works

Thanks again.

posted by Harrie Vandenhork 09 Sep 2015

Great!

posted by Wim Huiskamp 10 Sep 2015