Turning I2C 1602 LCD Display on with MOSFET using Atmega 2560

Hello Arduino community,

I have been currently stuck on a problem that I cannot seem to surpass for a few days now. Hoping I can get some advice.

My project is dealing with a security system operating on a rechargeable battery bank, so I would like to have the battery life as long as possible. Understanding that an LCD display draws up a lot of current, I decided to use a N-channel MOSFET to turn on and off the LCD display so there is no current being drawn when powered off. So far, I have been able to display "hello world" properly without using the MOSFET switching.(so hooking up the LCD directly to the mega 2560). However, when powering on the LCD using the MOSFET only the backlight appears and white squares across the first row.

I have just been using a simple blink function to turn on the MOSFET and see if hello world would appear. I believe it has something to do with the SDA and SCL pins not in sync with the power. (according to another post)

This is the code I have so far:

//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight(); // initialize backlight
lcd.setCursor(3,0);
lcd.print("Hello, world!");

pinMode(24, OUTPUT); // Digital pin used to turn on MOSFET
}

void loop()
{

digitalWrite(24, HIGH); // blink function
delay(5000);
digitalWrite(24, LOW);
delay(5000);
}

@johnnychew

By far, the greatest current draw, on an LCD, is the backlight.
If you remove Vcc, to turn the BL off, you would have to reinit it when you turn it on again.
At the start of setup(), you have

lcd.backlight();             // initialize backlight

This command is the one you use to turn the BL on. There will be another command which turns the BL off. Try
lcd.noBacklight();.

Fof

hey IamFof,

Thank you for the response, I will look into it soon. I still want the back light for users to see in the dark. Are you recommending me to get rid of the MOSFET all together and to just use the commands lcd.noBacklight(); and lcd.Backlight option to achieve the best battery consumption?

Johnnychew

You could continue to use the MOSFET, but that will entail having to re-initialise the LCD, every time you want the BL on.
Much better to turn it on/off using the software commands. Use a button which when pressed, executes lcd.backlight(), then after a predetermined time, using millis(), execute lcd.noBacklight().
One thing I forgot to mention. In your sketch

lcd.backlight();             // initialize backlight

This code does not initialise the backlight, it turns it on. The initialisation is done by the previous line.
The reason you are getting "white squares across the first row" is because the lcd needs to re-initialised.

Fof

Some lcd libraries, like my hd44780 library, also have on() and off() methods. These not only turn off the backlight but also turn off the display. This will be the lowest power consumption possible without cutting off the power.
Cutting off the power will be lower since when "off" the display will still consume around 1ma and then there can be some additional draw from the pullup resistors.
Best thing to do would be to actually measure it and decide if it is low enough for your needs. If not, you will need to turn off the power and reinitislize the display. If you have the pins, you could run the display in 8 bit mode and then you wouldn't need to reinitialize the display as that is the default mode so you should be able to just turn the power off and back on.

... and then you wouldn't need to reinitialize the display as that is the default mode ...

I think you might have to (partly) re-initailize it since the internal code leaves it OFF and in the 1-line configuration. I'm not sure about your library, hopefully you have taken care of that.

Don

floresta:
I think you might have to (partly) re-initailize it since the internal code leaves it OFF and in the 1-line configuration. I'm not sure about your library, hopefully you have taken care of that.

Don

I forgot about that.
Since the display is off and in 1 line mode on power up, it won't work without re-initializing a few things.
The only place that does the needed function set to set 2 line mode is in begin() so that would need to be called if there is more than a single line.
If there was only a single line you might be able to get away with only calling display() and backlight() or on() which does both if using 8 bit mode.

Calling begin() to reinitalize everything should work on all interfaces. (pin control, shift registers, i2c etc...)
begin() is not particularly fast, as many libraries have a blind wait of 50ms (hd44780 does 100ms)
and then there is about 20ms or so of other overhead to reinitialize everything including the clear screen.

--- bill