I have a contribution re TFT LCD screens whoae backlights can't be dimmed

These are the TFT LCD screens available on ebay.

Basically I plugged the LCD screen into an Arduino Uno prototyping shield:

Then I bent all the GND pins of the protyping shield. and plugged the shield onto a Arduino Mega - these are more convenient because you then still have easy access to all the additional Mega pins that are not covered or used by the shields.

Then I simply connected the bent GND pins on the shield to the GND pins on the Mega via a relay:

Thus you can now easily turn the LCD screen on an off to save power.
Add a push button to another of the Mega's digital pins for runtime turning on and off the the LCD screen.

I looked at using FET but it is rather difficult to find through hole FET that are adequately turned on by 5V. You might have more luck with surface mount devices but most of them seem to be tiny and more trouble than necessary to solder. The single relay is far more convenient, doesn't drop any voltage and does not add that much to size of the project.

I found that the Adfruit_TFTLCD library has parts of the initialisation sequence split between the constructor, init() function and begin() function.

So I have modified the library so that the digital pin modes are set in the init() function and that the init() function is only called at the top of the begin function.

Also I have re-located this code, that was located in the setup() function of each example sketch to the bottom of the library begin() function.

tft.reset();

  uint16_t identifier = tft.readID();

if(identifier == 0x9325) {
#ifdef DEBUG
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {

    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {

    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {

    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {

    Serial.println(F("Found HX8357D LCD driver"));
#endif // DEBUG
    } else {
    #ifdef DEBUG
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.print(F("I try use ILI9341 LCD driver "));
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    #endif // DEBUG
    identifier = 0x9341;
  }

So in other words, to initialise the tft object completely you only need tft.begin() in your sketch.

It also means that if you turn the LCD screen off while the arduino is still running then you only need call tft.begin() again to correctly re-initialise it.

Adafruit_TFTLCD.cpp (30.1 KB)

Adafruit_TFTLCD.h (3.33 KB)

Modified examples.

graphicstest.ino (10.9 KB)

rotationtest.ino (6.97 KB)

tftpaint2.ino (10.1 KB)

I am fascinated. You read the ID. Ignore it. Then just call tft.begin() which will assume you have an ILI9325.

There seem to be at least 30 different controllers on the Red 2.4" Shields in your photo.
ILI9325 was certainly very common a few years ago. Did you buy your Shield recently?

David.

@boylesg

You also need to switch off all the digital output pins connected to the display driver before the display's GND connection is broken by the relay. You can do this making them all inputs (or at least make sure they are all set high) otherwise the poor Arduino will be powering the display driver (but not the backlight LEDs) via any logic low lines. Your Arduino will probably survive overloading the pins like this but it is very bad design practice and the power consumption will not be as low as it could be.

david_prentice:
I am fascinated. You read the ID. Ignore it. Then just call tft.begin() which will assume you have an ILI9325.

There seem to be at least 30 different controllers on the Red 2.4" Shields in your photo.
ILI9325 was certainly very common a few years ago. Did you buy your Shield recently?

David.

I bought the shields not all that long ago, perhaps 6 months or so.

One of the example sketches passes in an explicit chip ID so I changed the parameter of the begin(...) function to a default of 0.
Then inside the begin(...) function, if the value of the parameter is 0, then that is where I call readID().
Otherwise the explicit passed in value is left alone.

I had to add some class data members to save the values passed in to the constructor for _cs, _cd, _wr, _rd, _reset, i.e. so that their pinMode(...) could be set and reset in the init() function from begin(...)

Also there is an added data member and access function for the chip ID value so that it can be retrieved if necessary.

bodmer:
@boylesg

You also need to switch off all the digital output pins connected to the display driver before the display's GND connection is broken by the relay. You can do this making them all inputs (or at least make sure they are all set high) otherwise the poor Arduino will be powering the display driver (but not the backlight LEDs) via any logic low lines. Your Arduino will probably survive overloading the pins like this but it is very bad design practice and the power consumption will not be as low as it could be.

I realise that but that is done in a function in my sketch along with the relay pin.
I suppose I could equally as well create other functions e.g. screenOff() in the TFTLCD and TouchScreen libraries to change all the relevant pins to INPUTS.

boylesg:
I realise that but that is done in a function in my sketch along with the relay pin.
I suppose I could equally as well create other functions e.g. screenOff() in the TFTLCD and TouchScreen libraries to change all the relevant pins to INPUTS.

Which of the examples you have posted here is this done?

Since this is important you need to provide an example and state that it is necessary to include this in a users sketch.

Most of the Red 2.4" Shields use the 5V pin to power the onboard LDO regulator. This is only used for the backlight LED.

If you think it is important to switch off the backlight, you could use a PNP transistor to switch the 5V power to the AMS1117 on or off. Make sure that you saturate the transistor by using sufficient Base current. PNP typically have low hFE. The backlight on a 2.4" will take about 100mA - 200mA. If your PNP has hFE=50, you might use iBase= 10mA e.g. 430R Base resistor. If the PNP has a VCEsat of 0.2V with a 200mA LED, it will dissipate 40mW.

The controller is powered by the 3.3V pin. You can give the controller a Sleep command. This reduces power dramatically e.g. from 20mA to a few uA.

Since you want to use a MEGA2560, I do not understand why you are worried about Power consumption. The ATmega2560 only operates at 5V.

Not all 2.4" are the same. It is your job to trace the schematic and mount any electonics. Cutting the 5V trace and gluing a TO92 transistor + 430R to the Display pcb is fairly easy. You could use the A5 pin to switch the PNP.

Untested. This is your project.

David.

bodmer:
Which of the examples you have posted here is this done?

Since this is important you need to provide an example and state that it is necessary to include this in a users sketch.

The examples are exactly a they came with the original version of the library - all I did to them was the necessary code changes to make them compile.

This is the code I am using to turn the screen on an off but it is part of my sketch and not part of the modified library. I also found that you have to call SD.end() so that the SD library properly re-initialises after turn on.

void CTFTLCDScreen::turnOff()
{
	const uint8_t nMode = INPUT;

  SD.end();

	pinMode(2, nMode);
	pinMode(3, nMode);
	pinMode(4, nMode);
	pinMode(5, nMode);
	pinMode(6, nMode);
	pinMode(7, nMode);
	pinMode(8, nMode);
	pinMode(9, nMode);
	pinMode(10, nMode);
	pinMode(11, nMode);
	pinMode(12, nMode);
	pinMode(13, nMode);

  pinMode(A0, nMode);
  pinMode(A1, nMode);
	pinMode(A2, nMode);
	pinMode(A3, nMode);
	pinMode(A4, nMode);
	pinMode(A5, nMode);
	pinMode(A6, nMode);

	digitalWrite(m_nRelayPin, LOW);
}

void CTFTLCDScreen::turnOn()
{
	digitalWrite(m_nRelayPin, HIGH);
	if (!begin())
		debug.logRuntimeError(F("TFTLCDShield.cpp"), __LINE__);
  else if (m_pTurnonCallback)
    (*m_pTurnonCallback)();
}
bool CTFTLCDScreen::beginSD()
{
	bool bResult = false;

	debug.log(F("Initializing SD card..."), false);
  pinMode(m_nSD_SCK, OUTPUT);

	if (!SD.begin(m_nSD_CS, m_nSD_MOSI, m_nSD_MISO, m_nSD_SCK))
		debug.log(F("failed!"));
	else
	{
		debug.log(F("done!"));
		bResult = true;
	}
	return bResult;
}

bool CTFTLCDScreen::begin()
{
	bool bResult = false;
 
	if (beginSD())
    bResult = true;
  else
		debug.logRuntimeError(F("TFTLCDShield.cpp"), __LINE__);

	m_LCD.begin();

	return bResult;
}

david_prentice:
Most of the Red 2.4" Shields use the 5V pin to power the onboard LDO regulator. This is only used for the backlight LED.

If you think it is important to switch off the backlight, you could use a PNP transistor to switch the 5V power to the AMS1117 on or off. Make sure that you saturate the transistor by using sufficient Base current. PNP typically have low hFE. The backlight on a 2.4" will take about 100mA - 200mA. If your PNP has hFE=50, you might use iBase= 10mA e.g. 430R Base resistor. If the PNP has a VCEsat of 0.2V with a 200mA LED, it will dissipate 40mW.

The controller is powered by the 3.3V pin. You can give the controller a Sleep command. This reduces power dramatically e.g. from 20mA to a few uA.

Since you want to use a MEGA2560, I do not understand why you are worried about Power consumption. The ATmega2560 only operates at 5V.

Not all 2.4" are the same. It is your job to trace the schematic and mount any electonics. Cutting the 5V trace and gluing a TO92 transistor + 430R to the Display pcb is fairly easy. You could use the A5 pin to switch the PNP.

Untested. This is your project.

David.

As far as I can tell the shields I have do not have this feature - there is no pin labelled as being about the backlight.

But I just got the impression you are suggesting that you can PWM the actual 5V pin on the LCD shield?

As an additional thought, if I did swap my relay to the 5V pin rather than the ground pins, then I could probably retain the functionality of the SD card reader while the LCD screen is off? SD card readers are 3.3V if remember correctly.

No, I was suggesting that you cut the track between 5V and the AMS1117 chip.
You just switch it on or off. You would never use PWM on the input side of the AMS1117.

Hey-ho, I am curious why you would want to switch the backlight off when you have a MEGA2560.

I suppose that you could attempt to switch the output side of the AMS1117 but I don't think you can access the tracks easily. You would need a smaller Base resistor to ensure PNP saturation.

These shields are designed to just work reliably. I do not advise hacking them. But you can do whatever you want. Switching the 0V line with a relay is a bad idea (tm).

If you really want to have PWM control, look at the schematics of proven designs. I think you would have to dismantle the pcb to get at the LED pins on the bare 3.3V module.

David.

david_prentice:
No, I was suggesting that you cut the track between 5V and the AMS1117 chip.
You just switch it on or off. You would never use PWM on the input side of the AMS1117.

Hey-ho, I am curious why you would want to switch the backlight off when you have a MEGA2560.

I suppose that you could attempt to switch the output side of the AMS1117 but I don't think you can access the tracks easily. You would need a smaller Base resistor to ensure PNP saturation.

These shields are designed to just work reliably. I do not advise hacking them. But you can do whatever you want. Switching the 0V line with a relay is a bad idea (tm).

If you really want to have PWM control, look at the schematics of proven designs. I think you would have to dismantle the pcb to get at the LED pins on the bare 3.3V module.

David.

This particular project is a wireless soil moisture probe that measures soil conductivity (moisture) and raises an alarm at the parent irrigation controller if the soil is dry for more than a specified amount of time.

So it will be battery powered and I cannot have the LCD screen on all the time.

I tried allowing the SD card reader to remain on, i.e. refrained from changing its 4 pins to INPUTs, but sadly the LCD screen does not turn completely off if I do that.

So I will have to turn both the SD card reader and the screen on briefly if I need to access files on the SD card.

I also changed my protype shield so that the 5V is broken by the relay rather than the GND.

If you are battery powered, why not use a Uno?

Why not use LCD instead of TFT?

TFTs can give a nice display but the backlight is power hungry.
You can't see anything without the backlight.

David.

david_prentice:
If you are battery powered, why not use a Uno?

Why not use LCD instead of TFT?

TFTs can give a nice display but the backlight is power hungry.
You can't see anything without the backlight.

David.

Because I need the touch functionality for user input.

Well, that is a very good reason.

3.3V operation would be a better reason for avoiding the 2560.

Anyway, Lithium or AA cells will give you a reasonable life if you put AVR and TFT controller to sleep.

David.

david_prentice:
Well, that is a very good reason.

3.3V operation would be a better reason for avoiding the 2560.

Anyway, Lithium or AA cells will give you a reasonable life if you put AVR and TFT controller to sleep.

David.

I was thinking more in terms of small gel cell or LIPO.

The device is going to sit in a garden bed so if it is a reasonable size then it is less likely to get lost or kicked.

boylesg:
...
So it will be battery powered and I cannot have the LCD screen on all the time.

I tried allowing the SD card reader to remain on, i.e. refrained from changing its 4 pins to INPUTs, but sadly the LCD screen does not turn completely off if I do that.

So I will have to turn both the SD card reader and the screen on briefly if I need to access files on the SD card.

I also changed my protype shield so that the 5V is broken by the relay rather than the GND.

I'm not surprised that an increasing number of problems is being encountered, without detailed knowledge of the schematic of the display the results of removing the GND are unpredictable, for example this removed the reference point for any 3.3V regulators in the circuit so you may find there is a parasitic path taking the 3.3V rail up to near 5V, depending on the circuit this could destroy or stress some other component. Switching 5V is OK as long as there is not a 3.3V regulator attached as you might get parasitic power paths from logic lines powering the 3.3V line instead.

Moving to breaking 5V is easier to manage though. You may find the SD card gets corrupted occasionally due to power surges when the relay contacts bounce.

Re. battery power. A Mega typically consumes 80mA when running a sketch even with no display connected as LEDs and the USB interface are all active, this means it is not a good choice for battery powered applications. If you try a pack of AA cells for power then they typically have a capacity of 2800mAh, this means they will power a Mega for about 56 hours at best (just over 2 days). You could make them rechargeable of course and attach a solar panel. A better solution would be to go for a minimalist third party Arduino board that is designed for low power and put the micro-controller to sleep, waking it periodically to check the soil using the built-in watchdog. I would expect that with very very careful design it would be possible to get 12 months from a set of AA cells, but the entire circuit would, on average, need to consume less than one tenth the power of just one little LED on the Mega board.

Re. Code in post #9, this won't be much help to a newbie unless you include the debug class code and how to setup the call-back function to avoid confusing compilation errors. Newbies need complete and explicit detailed instructions, without that they waste time and effort as they do not realise pieces of the jigsaw puzzle are missing!

As David say's it is your project but I think that the power saving from switching off the display (they do take about 200mA) will probably not give the consumption savings needed for a battery powered application.

Here is my whole user interface system for this project. It, along with the rest of my sketch, takes up only 38% global memory on a mega.

CMainMenu is the launcher and you call CMainMenu::pollTouch() in loop()to kick it all off.

Thus far I have an push button, check box, text field (and a popup keyboard thing similar to the android widgets), text labels and dialog boxes.

You can freely nest dialog boxes within dialog boxes but subject to memory restrictions.

See what you make of it.

I have included some of my project specific dialog boxes as examples (CControllerSettings)

Base.cpp (764 Bytes)

Base.h (655 Bytes)

Button.h (5.44 KB)

CheckBox.h (6.65 KB)

Common.cpp (5.42 KB)

Common.h (1.74 KB)

Control.cpp (6.33 KB)

Control.h (2.24 KB)

ControllerSettings.cpp (5.87 KB)

ControllerSettings.h (862 Bytes)

CString.cpp (20 KB)

CString.h (8.25 KB)

Debug.cpp (15.2 KB)

Debug.h (4.11 KB)

DialogBox.cpp (4.89 KB)

DialogBox.h (1.97 KB)

Keyboard.h (9.22 KB)

Label.h (4.87 KB)

MainMenu.cpp (4.45 KB)

MainMenu.h (1.02 KB)

boylesg:
I was thinking more in terms of small gel cell or LIPO.

The device is going to sit in a garden bed so if it is a reasonable size then it is less likely to get lost or kicked.

OK, lets do the sums, Mega takes 0.08A. Say you want it to run for a month (30 days):

Running hours = 30 x 24 = 720 hours
Mega consumption = 0.08 x 720 = 57.6 Ah

So 12 off 6V 5Ah SLA batteries wired in parallel will last 1 month.

Now assume we add a solar panel, Ah needed in 1 day is:

Ah = 0.08 x 24 = 1.92 Ah

Say 8 hours of full sunshine. solar panel must supply at least 0.24A so a 5W 12V panel might be OK if there are no cloudy days.

To save money a better approach would be to find a Arduino board that can be put into a much lower power consumption state.