EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: MrOmnos on August 10, 2016, 12:28:18 pm

Title: How to digitally control the brightness of 16x2 LCD
Post by: MrOmnos on August 10, 2016, 12:28:18 pm
Hi, is it possible to digitally control the brightness of 16X2 LCD. I have searched all over my workshop, I don't have a pot laying around. So, I was thinking If I could use Arduino itself to control the brightness of the LCD. PWM? How do I do it?
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: JPortici on August 10, 2016, 12:31:14 pm
brightness or contrast? pwm in any case but for contrast it might get tricky
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: MrOmnos on August 10, 2016, 12:35:06 pm
brightness or contrast? pwm in any case but for contrast it might get tricky

Sorry, I meant contrast!!
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: JPortici on August 10, 2016, 12:41:48 pm
i think you could be able to do it with filtered pwm, the pwm source must be able to sink current
google seems to confirm
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: rob77 on August 10, 2016, 01:11:58 pm
filtered PWM would work... but the question is how will you adjust the contrast in software with user controls (buttons, encoder) if you don't see the text on the LCD because of wrong contrast setting ?  :-//
every piece of those cheap 16x2 displays from china  is different (that's my experience at least), there is no universal contrast setting for them - so you can't use a pre-set value in software.
the best way is a multi-turn trimpot (cheap one from china is more than good enough) and set the contrast for every piece individually.
if you really don't have a trimpot around and you need it for a one-off then try different values of fixed resistors to make the right voltage divider for the contrast, the contrast is not drifting on those LCDs (at least not noticeably) so the fixed divider is ok.
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: batteksystem on August 10, 2016, 01:22:14 pm
Another way you could probably use a digital potentimeter, microchip has a tons of these with lots of selection, fairly easy to use (I believe it is controlled by I2C) but hell expensive.
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: madires on August 10, 2016, 01:54:08 pm
filtered PWM would work... but the question is how will you adjust the contrast in software with user controls (buttons, encoder) if you don't see the text on the LCD because of wrong contrast setting ?  :-//
every piece of those cheap 16x2 displays from china  is different (that's my experience at least), there is no universal contrast setting for them - so you can't use a pre-set value in software.
the best way is a multi-turn trimpot (cheap one from china is more than good enough) and set the contrast for every piece individually.
if you really don't have a trimpot around and you need it for a one-off then try different values of fixed resistors to make the right voltage divider for the contrast, the contrast is not drifting on those LCDs (at least not noticeably) so the fixed divider is ok.

I can confirm that from my experience with the TransistorTester project. Several graphic LCD controllers set the contrast by software and it's no easy to find a suitable default value for the contrast. Still there are several users which got problems with the display after upgrading the firmware, because their display requires some uncommonly low or high contrast value. And some screw up the contrast while adjusting it in the contrast setting function. Therefore I've added a special reset mode selectable while powering on.
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: linux-works on August 10, 2016, 02:06:18 pm
pwm for brightness, digital pot for contrast.
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: MrOmnos on August 10, 2016, 04:23:16 pm
filtered PWM would work... but the question is how will you adjust the contrast in software with user controls (buttons, encoder) if you don't see the text on the LCD because of wrong contrast setting ?  :-//
every piece of those cheap 16x2 displays from china  is different (that's my experience at least), there is no universal contrast setting for them - so you can't use a pre-set value in software.
the best way is a multi-turn trimpot (cheap one from china is more than good enough) and set the contrast for every piece individually.
if you really don't have a trimpot around and you need it for a one-off then try different values of fixed resistors to make the right voltage divider for the contrast, the contrast is not drifting on those LCDs (at least not noticeably) so the fixed divider is ok.

I made a voltage divider using two 4.7k resistors and connected the contrast pin to it. I had to play around with few resistor values to get the result I wanted. 4.7k seems to be the sweet spot for all  4 LCDs I have. I think fixing the contrast in hardware is a better idea for any LCD project. Trim pot is just too much hassle and no one is going to use it anyway.  Thanks everyone!!
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: danadak on August 10, 2016, 08:02:47 pm
I used a PWM on a PSOC UP to control contrast on a 16 x 2 and 20 x 4.

In code when part started up it output a standard value on PWM which equated to V.

If the user could not see display he started it up coupled with a button push. That
triggered in code a routine that slew the PWM value from min to max, slowly, and when
LCD screen came into view able contrast he/she could press button again to freeze at that
value.

Same routine was used when system was setup in a utility and the optimal user perceived
contrast value was saved for future user startup.

Don't forget to LP Filter the pwm out to get DC for contrast pin. See attached design considerations.

Regards, Dana.
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: macboy on August 11, 2016, 04:59:50 pm
The contrast pin virtually never needs a pot, so using one will just waste power. For these HD44780 type modules, all that is required in my experience is a resistor to ground. Often a value of zero works, i.e. connect the contrast pin directly to ground. Otherwise just play with the value until you find the one the works for your module. If you really want/need end user adjustability, then you could try PWM.
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: tooki on August 14, 2016, 02:38:11 pm
I've used filtered PWM to control contrast, works fine. Doesn't solve the issue of variability between units of course.

What's a real pain in the ass are the LCD modules (big ones, in my experience) whose contrast adjustment range spans both positive and negative voltages!
Title: Re: How to digitally control the brightness of 16x2 LCD
Post by: dannyf on August 14, 2016, 03:35:16 pm
Quote
I meant contrast!!

The simplest would be to use a digital pot.

Alternatively, use a pulse generator (pwm for example) + charge pump (diodes + capacitor).