How to control the display's backlight in the sketch?

Hello :slight_smile:

I have Sainsmart's 3.2" display. It's nice but I can't adjust the backlight with code, only manually with the trimmer pot, that is located on the "adapter shield".

The backlight is made of 5 (not sure) LEDs which are controlled by the trimmer pot, which is wired on the 3.3v pin of the Arduino Mega. I have no idea about current required for those LEDs (I have a multimeter, but can't measure because I can't place the sensors, I first need some male-female wires...) but it shouldn't be more than 40mA since it's the max current that can be drawn from the 3.3v pin.

So I thought I could maybe desolder and remove the trimmer pot, and solder a wire where the trimmer pot's output was (the middle pad), to the Arduino pin 8 (or any other PWM pin), with maybe a resistor in between. So I could control the brightness with analogWrite. A picture is worth 100 words:

So before I try and fry my Arduino or the display, or both...few questions :slight_smile:

  1. Will it work at all? If not, please tell me why.

  2. Do I really need a resistor, if I use this code (obviously not tested, and I'm planning to use the SoftPWM library anyway):

#define PIN_BACKLIGHT 8

void SetBacklightPercent(int percent)
{
	if (percent > 100)
		percent = 100;

	else if (percent < 0)
		percent = 0;

	//(3.3v/5v) * 255 = 168.3
	analogWrite(PIN_BACKLIGHT, (int) round(168.3 * (percent/100.0)));
}


void setup()
{                
	pinMode(PIN_BACKLIGHT, OUTPUT);     
}
 
void loop()
{
	SetBacklightPercent(100);
	delay(1000);

	SetBacklightPercent(50);
	delay(1000);

	SetBacklightPercent(0);
	delay(1000);
}
  1. Do you have a better solution, which could possibly avoid to desolder the trimmer pot?

Thanks in advance!

Having a datasheet to the display would help you tremendously.

dhenry:
Having a datasheet to the display would help you tremendously.

Help me for what? And there is no datasheet. The display use a SSD1289 controller, which doesn't control the backlight, that's all I know about it.

Help me for what? ..., that's all I know about it.

To know more about how to use your devices?

Your replies doesn't help... Of course I have looked for a datasheet, can't find any, else I wouldn't ask myself how much current are required by the LEDs.

I think I know how to use my device :). There is no backlight control other than the trimmer pot, so I have to find a solution, which wouldn't be written in the datasheet, if there was any...

There is no backlight control other than the trimmer pot, so I have to find a solution

With out understanding of what the trimmer does, you cannot have a solution: the trimmer could be outputting a signal that the display uses to change backlight, or it could be the resistance in the backlighting leds....

Getting the datasheet or the schematic is your quickest and surest solution.

Short of that, trace the pcb and experiment.

Your replies doesn't help...

He is trying to help. He is attempting to teach you how to fish.

Don

or it could be the resistance in the backlighting leds....

Yes this, I'm pretty sure: the trimmer's input is 3.3V, output is LED-A pin, which probably stand for LED Anode. If I put a wire between LED-A (pin19) and GND (pin 1), the backlights turns OFF.

And to add to that: in the datasheet of the SSD1289 controller, there is not a single word about backlight, however there is code to turn ON/OFF the display, I tried it and does what it says, turn ON/OFF the display, but doesn't have any effect on the backlight.

void UTFT::lcdOff()
{
	cbi(P_CS, B_CS);
	switch (display_model)
	{
		case PCF8833:
			LCD_Write_COM(0x28);
			break;

		//I added this ------------------------
		case SSD1289:
			//turn OFF
			LCD_Write_COM_DATA(0x07,0x0000);
			LCD_Write_COM_DATA(0x00,0x0000);
			LCD_Write_COM_DATA(0x10,0x0001);
			
			//only standby mode ON: no visible difference?
			//LCD_Write_COM_DATA(0x10,0x0001);
			break;
		//-------------------------------------
	}
	sbi(P_CS, B_CS);
}

void UTFT::lcdOn()
{
	cbi(P_CS, B_CS);
	switch (display_model)
	{
		case PCF8833:
			LCD_Write_COM(0x29);
			break;

		//I added this ------------------------
		case SSD1289:
			//turn ON
			LCD_Write_COM_DATA(0x07,0x0021);
			LCD_Write_COM_DATA(0x00,0x0001);
			LCD_Write_COM_DATA(0x07,0x0023);
			LCD_Write_COM_DATA(0x10,0x0000);
			delay(30); 
			LCD_Write_COM_DATA(0x07,0x0033);
			LCD_Write_COM_DATA(0x11,0x60B0);
			LCD_Write_COM_DATA(0x02,0x0600);
			LCD_Write_COM(0x22);
		
			//only standby mode OFF: no visible difference?
			//LCD_Write_COM_DATA(0x10,0x0000);
			break;
		//-------------------------------------
	}
	sbi(P_CS, B_CS);
}

So... If I just replace the trimmer by something else that does basically the same thing (analogWrite), isn't that OK? Then, you could reply to my questions :slight_smile:

Yes this, I'm pretty sure: the trimmer's input is 3.3V, output is LED-A pin, which probably stand for LED Anode.

So the trimmer is essentially a voltage divider feeding the backlight - not a particularly good technique for implementing an LED.

If I put a wire between LED-A (pin19) and GND (pin 1), the backlights turns OFF.

This is not a good practice, especially for some settings of the trimmer.

And to add to that: in the datasheet of the SSD1289 controller, there is not a single word about backlight...

That is because the controller is designed to deal with the presentation of information on the LCD itself and the backlight is more or less an add-on to the LCD to make that information more legible.

The trimmer is part of the shield that goes between the display and the Arduino and the apparently non-existent documentation for that shield should explain its operation and perhaps other options. By now you should have figured out why the distributors that provide good support seem to charge more for their products than those who provide minimal support.

Don

Yes this, I'm pretty sure: the trimmer's input is 3.3V, output is LED-A pin,

I agree with the other poster that this is a terrible design. The LED(s) probably suck in a lot of current. For the trimmer approach to work, its resistance has to be fairly small.

Do you know if the wiper goes to the LED or one of the terminals goes to the LED? Essentially you want to know if the trimmer is used as a variable resistor.

which probably stand for LED Anode.

Yes. That's correct.

If I put a wire between LED-A (pin19) and GND (pin 1), the backlights turns OFF.

If the trimmer is used as a divider and the wiper is at the top, you have just shorted the power supply.

I think you can use a pwm pin to power the led and software control the duty cycle. That requires some resistance on the led, and some limit on how much current the led can draw. If the timmer is wired in right, you can use it. Otherwise, you can cut the trace and wire in a resistor.

Do you know if the wiper goes to the LED or one of the terminals goes to the LED? Essentially you want to know if the trimmer is used as a variable resistor.

The wiper goes to the LED. It's shown right there in his original post.

If the trimmer is used as a divider and the wiper is at the top, you have just shorted the power supply.

And you probably burned out the trimmer just before you got to the top. But it does indeed turn the backlight off, either way!

That requires some resistance on the led ...

Which should be present in any design including one using the unmodified shield. There may be one on the PC board that holds the LCD, but don't count on it.

If the timmer is wired in right, you can use it. Otherwise, you can cut the trace and wire in a resistor.

That is essentially what he proposed in his original post except he planned to remove the trimmer instead of cutting traces.

Don

EDIT: Wouldn't he be better off leaving the trimmer in place, cutting the trace between the top (right hand end) of the trimmer and the 3.3v pin, and moving his resistor connection over from the wiper to the top of the trimmer?

Wouldn't he be better off leaving the trimmer in place, cutting the trace between the top (right hand end) of the trimmer and the 3.3v pin, and moving his resistor connection over from the wiper to the top of the trimmer?

I would actually cut the trace and put in a resistor.

Another approach that requires minimum pcb work is to lift the underside of that trimmer, and connect it to the pwm output. The led is the dimmest when the trimmer is in the middle. This approach may not work if the trimmer's value is too small.

OK guys I think I understood what you said :slight_smile: I think I will just remove the trimmer anyway, since I don't need both PWM and manual control.

But I'm confused: do I really need a resistor if I limit the PWM output to 3.3v (as in my code) ? Knowing that:

  • The 3.3V pin is rated 40mA max, same as the PWM outputs,
  • When the trimmer is "fully open", there is no resistor between the 3.3V pin and LED-A pin.

So I think I don't even need to add a resistor!

Sorry, I'm still newb to electronics :slight_smile:

do I really need a resistor if I limit the PWM output to 3.3v (as in my code)

You can't limit the output to 3V3 in software. PWM is always a 5V signal, it is just the on / off ratio that changes.
See this for how it works:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

You always need a current limiting device when using an LED and a resistor is the simplest one you can have. Anyone who tells you different is wrong.

The 3.3V pin is rated 40mA max, same as the PWM outputs

That is a the absolute maximum permitted value and you really shouldn't operate there. There are other restrictions as well depending on what is going on at the other port pins.

When the trimmer is "fully open", there is no resistor between the 3.3V pin and LED-A pin.

That is a poor design especially if there is no current limiting resistor on the display PC board.

So I think I don't even need to add a resistor!

It's your display and Arduino that are at risk. I wouldn't do it.

Don

You always need a current limiting device when using an LED and a resistor is the simplest one you can have. Anyone who tells you different is wrong.

I was going to say the same thing but then I figured that someone would point out the exception, which would be if one happened to be using a current limiting supply. Even then the resistor wouldn't hurt anything.

I agree - you should always use a current limiting resistor.

Don

which would be if one happened to be using a current limiting supply.

This is covered by the "current limiting device " part of my statement. :slight_smile:

Oops - I missed that.

Don

But I'm confused: do I really need a resistor if I limit the PWM output to 3.3v (as in my code) ?

PWM 3.3v only means that the arduino is outputing 5v 3.3v/5v = 66% of the time, and 0v 33% of the time.

However, the answer to your question is yes and no.

Yes, you need a resistor for a proper design.

No, you don't need a resistor as the pin's internal limitations in its current capabilities serve as a "resistor", and the diodes are one of those electronic devices that can take a lot of abuses temporarily.

I would put one in myself. But I would encourage you to experiment by not putting one in just to see for yourself.

In case you are asking, I have shorted avr's output pins (when outputting a logic 1) without damaging any.

guix:
So I think I don't even need to add a resistor!
Sorry, I'm still newb to electronics :slight_smile:

Why do they always fight "the resistor"?
Why resist?
Is it "the expense"?