Good morning everyone.
I have a problem and I hope someone will come to the rescue.
In my code I need to begin the LCD when a switch is turned on: when i turn on this switch the LCD is connected to Vcc and so i need to begin it to send characters.
The problem is that when I turn it on, my Arduino just freezes and i need to turn off the switch and turn it on again to make it work.
Any idea on how to do it?
Could an interrupt help?
I tried different LCD I2C libraries, but everyone had a flaw.
I'm using now the "Arduino-LiquidCrystal-I2C-library-master".
My project is a solar panel that follows the sun with a switch that, when pressed, turns on the LCD and lets you see some parameters (voltage, current, position, ...).
For efficiency reasons I need to shut down the LCD when it's not in use.
My full circuit is a bit complicated to draw, but if you need i can try!
It has a servo motor, two LDRs, some resistances, a battery, two switches, the LCD and some modules for the powering and recharging.
An LCD uses very little power, far less than an Arduino. It's not worth the trouble to save such a small amount of power, it will make almost zero difference.
It's the backlight in an LCD that uses most of the power. This is what you need to cut power to for efficiency.
The backlight can be switched on and off from your sketch with some types of i²c adapter. So you could wire a button or switch to an Arduino pin, and have your sketch read that pin and turn the backlight on/off.
Other types of i²c adapter have an extra pair of PCB pins to enable/disable the backlight. Normally there is a jumper fitted to these pins and if you remove the jumper, the backlight is disabled. So you could remove that jumper and connect a button or switch directly to those PCB pins. Simple!
Specifically, the backlight takes about 22 mA, while the display itself takes less than 2 mA.
Actually, if would take less than 1 mA if you could correct a silly mistake in the design of the I²C backpack. The contrast (blue) potentiometer is connected to Vcc and should not be - but it is generally not easy to disconnect that.
The point is that whatever the "Arduino" you are using, it will likely draw in the order of 20 to 50 mA, far more than the display.
And that is far less than the servo motor will draw as it may activate simply to hold its position, so completely disabling the servo would be the first priority in power saving. That done, if you are operating from a battery, you do not want to use a UNO (or even Nano) as its USB interface draws power, instead a Pro Mini.
Actually, that is a trifle confusing. The most commonly available I²C backpack actually has both of these.
As does the less common but cheaper "Keyes" Red board.
Of which I have just bought five to investigate how easy it is to correct the bad wiring of the potentiometer. And also because basically, these are a very useful general-purpose PCF8574 adapter board if you want seven "raw" I/O pins and one transistor buffered output.
The red board also allows you with due care, to re-mount the i²c pins on the correct end of the board for use with a LCD display.
Here I am. I tried to add that line of code and...
And... you are a genius. It worked. I can't explain how much i'm grateful.
I was searching all over for a solution to this problem and it was so easy. Thanks, Thanks, Thanks.
And thank you so much for this detailed information for the I2C LCDs. I couldn't imagine a team so large and fast helping me for this problem. And most importantly so prepared.
You are welcome. It was just a suspicion that the I2C connection was the problem. I haven't tried such a construction with the switch on the display myself. So much the better that it actually works :).
But too much honor. I'm certainly not a genius... Then my life would have been different