Go Down

Topic: fm's New LiquidCrystal library & el-cheapo I2C adapter backlight question (Read 785 times) previous topic - next topic

OldSalt1945


*********   P R O B L E M    S O L V E D  *******  T H A N K S   F O R   Y O U R    H E L P   ************


Newbie, but did my homework.  Using Arduino Uno R3 2012 & 4x20 LCD w Backlight & cheap I2C adapter.

Kudos to fm on her marvelous library and to bperrybap for his contributions to it.

Is it possible to get a "sticky" attached to the subject of "New LiquidCrystal Library"  that will make reference to this library more convenient?
Can someone of influence lobby for fm's library to replace the standard library?

Now to my problem:
I bought 3 I2C adapters for $2.29 each on ebay.   (See attached photo).  

They work great with fm's library using the following constructor:
Code: [Select]
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7);

No other libraries worked (I tried all that I could find).  Learned a lot in the process, so it was worth the effort.

The only examples I could find for turning on the backlight involved using Arduino pin D13.  I tried to understand what was being done, but I couldn't see how the backlight() command was doing anything but using an additional wire to control the backlight by means of Arduino pin D13.  My major concern is that I don't want to create a dead-nuts short that burns out equipment.

How is it done using the built-in commands and the I2C buss alone?

Currently, I just bent pins 15 & 16 of the adapter out of the way before plugging it into the 4x20 LCD board.  I soldered  wires directly to pins 15 and 16 of the LCD board  and attached those to pins D13 and GND of the Arduino board.  Ugly, but it works.  

I have another problem, but will make a seperate post to avoid confusion.

Any help will be greatly............etc.            John
Always keep the shower curtain INSIDE the tub.

Paul__B

I don't follow.

When you used bperrybap's guesser to obtain the constructor, the backlight flashed on and off.  What is the problem with using the lcd.setBacklight() command?

OldSalt1945

I wasn't aware of his guesser.  I used one by "Krodal".  It found the address.

I used a multimeter to divine the pinouts.  Couldn't figure out how to modify the various I2C libraries.  Discovered the 10-page discussion of fm's building of her New LiquidCrystal library.  Monkeyed around for a couple of days figuring out how to successfully install it.  Yea, it worked.  Read and reread and reread the backlight discussions and in a state of confusion, forgive me, I'm old, gave up and installed the hack.

What I'm hoping for is that some kind soul will take pity and just tell me what to do so I can stop wandering in this forrest of desperation.  (I hope this causes you to feel sorry for me and you will give me a list entitled "OK, dummy, do this and then you can bask the world of the knowledge with us. :P"). 

Begging for help,        John
Always keep the shower curtain INSIDE the tub.

raschemmel

Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

OldSalt1945

Paul__B

I just followed the link you gave me and downloaded Bill's guesser.  When I looked at his code, I think I found the answer to my question.  I will have to monkey around with it for a while, but I suspect it will work.

Thanks.     John
Always keep the shower curtain INSIDE the tub.

bperrybap

Everything that you needed was in the threads you were reading
including links to a site with i2c examples,
and the link to my guesser sketch - which has also been provided above.

If you look at your backpack,
See that 3 pin part over labeled J3Y over by the jumper?

That is a NPN transistor used to turn the backlight on/off.

Since you have not filled in the constructor with the backlight control information,
the library does not know how to turn on/off the backlight using that transistor.
If you will enter the full/proper constructor for the backpack, you will be able to control
it by using the backlight() and noBacklight() API functions.

You don't need to modify fm's library.
Just fill in the rest of the constructor with the backlight information and then
you can control the backlight in s/w.
The full constructor includes 2 more parameters, a PCF8574 pin number
used to drive the backlight circuit and the polarity of the signal.
You only have 1 pin that you haven't used, and the polarity is either POSITIVE
or NEGATIVE.

See the referenced i2c examples, or use the guesser sketch.

Note: you may have to play with the jumper as different boards have different circuits
and use it differently.
Here are some of the different combinations I've seen for the jumper:

- Jumper on:  backlight permanently on, Jumper out: s/w control
- Jumper on:  s/w control, Jumper out: backlight permanently off.
- jumper on: backlight permanently on, jumper out: backlight permanently off
(This last case is not your board since you have a transistor on your board)

--- bill

bperrybap


Paul__B

I just followed the link you gave me and downloaded Bill's guesser.  When I looked at his code, I think I found the answer to my question.  I will have to monkey around with it for a while, but I suspect it will work.

Thanks.     John

You shouldn't have to monkey around with anything.
Just use the constructor parameters that the guesser sketch reported and it should work.

--- bill

OldSalt1945

The change to the constructor worked perfectly.  Now that I know about the transistor driver of pin 13, I can unbend the pins on the adapter and toss the extra wires.  Good news is: I learned a bunch about a bunch of stuff.
Thank you.

The example code I was working from is an example included with the download of LCD Library 1.2.1.
Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x38);  // Set the LCD I2C address

#define BACKLIGHT_PIN     13

void setup()
{
  // Switch on the backlight
  pinMode ( BACKLIGHT_PIN, OUTPUT );
  digitalWrite ( BACKLIGHT_PIN, HIGH );
 
  lcd.begin(16,2);               // initialize the lcd

  lcd.home ();                   // go home
  lcd.print("Hello, ARDUINO "); 
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print (" WORLD!  ");     
}

void loop()
{

}


Since the example used Arduino pin D13, I became unsure what to do next. 


Everything that you needed was in the threads you were reading
including links to a site with i2c examples,
and the link to my guesser sketch - which has also been provided above.

I sure would appreciate a link into some of these examples you mention. 
The example I used came from https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

Thanks again, gentlemen.

John
Always keep the shower curtain INSIDE the tub.

bperrybap

Unfortunately, that example is a poor example of how to use the library.
It is for fm's Electro Fun Extra i/o board.
fms' extra i/o board doesn't have backlight control circuitry so the example uses a separate arduino pin
to control the backlight. (It uses I2C and extra Arduino pins for backlight and constrast control)
It also doesn't specify the pins so it uses a default wiring which is for fm's board.

So unfortunately, it  is not the way the i2c interface works on all the other
i2c backpacks out there with backlight control.

As far as examples go, I had assumed you read the full [SOLVED] MJKDZ thread, which is the
same thread where I posted the guesser sketch.
In the very first post of that thread,
Step #3  has the link to a site ( LCD-Blue-I2C page) which has information on
how to get the backpacks working and the i2c examples that use the full constructor.

Once fm's  library added support for backlight control, the sketch should no longer
have to use pinMode(), digitalWrite(), or setBacklightPin() with the backlight pin.
Essentially setBacklightPin() became obsolete once the constructor was extended
to support backlight control information.

And if using I2C, you must use the full extender to tell the library how to use an
i/o expander pin to control the backlight circuit since the backlight circuit is not being
controlled by a pin directly connected to the Arduino.

The examples on the LCD-Blue-I2C page use the full LiquidCrystal_I2C constructor and the backlight
api functions.

--- bill

Rokkit

I just got some cheapo LCD displays from China, and like you, I had a hard time getting the backlight to work.  I came up with the following which may help:

Code: [Select]

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

void setup()
{

  lcd.begin(20,4);               // initialize the lcd
  lcd.noBacklight();             // turns backlight off
  lcd.home ();                   // go home
  lcd.print("Screaming Baby"); 
  lcd.setCursor (0, 1 );        // go to the next line
  lcd.print ("You Drive Me CRAZY!  ");
 
}

void loop()
{
  lcd.backlight();               // turns backlight on
  delay(1000);                    // wait 1 second
  lcd.noBacklight();             // turns backlight off
  delay(1000);                    // wait 1 second
}
"Every day is a good day, some are just gooder than others."   D. Fowler

Rokkit

Actually John, I just looked at my interface board and it is identical.  Since the backlight is driven from the interface board, I think that code should work for you.  If not, let me know and I will point you in the right direction of the library I used.

The jumper should be left on.
"Every day is a good day, some are just gooder than others."   D. Fowler

OldSalt1945

The answer was:

Use the full constructor

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

lcd.noBacklight();             // turns backlight off

lcd.backlight();               // turns backlight on

Thanks for all the help, folks.

John
Always keep the shower curtain INSIDE the tub.

raschemmel

Now that you have your backlight working you can add a backlight delayed turn off (see attached file).
You'll have to replace the constructor with yours. It takes two push button switches; one is a sensor, the other starts the 10 second
delayed turn off. 
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Go Up