[SOLVED] "LCM1602 IIC A0 A1 A2" (+OTHERS) I2C Controller working with 20x4 LCD

The big takeaway from this is that hd44780 displays do not perform line wrapping
like a terminal. The hd44780 interface does not understand control characters like
carriage return and new line.
Each time a character is sent to it, the memory address location advances
(or decrements if the text direction is right to left) and the memory is not
mapped sequentially across the lines of the display.

While a library can be written to handle control characters and perform line wrapping,
I've only ever seen 1 arduino hd44780 library do it.

--- bill

Hello,

i also have a LCM1602 IIC A0 A1 A2 from e..y and it works perfectly. But i can´t dim the backlight. When i set a Value between 1 - 255 nothing happend.

lcd.setBacklight(50);

The controller is using a PCF8574T. The only different what i used ist the 16x2 Display. Not the 20x4 (but also it works not with 20x4 LCD)

Whats going wrong? Or what to do?

The PCF8574 is a i2c 8bit i/o expander that has an 8 pin port i/o control.
The chip only offers very simple i/o control. The 8 pins can be read
or the 8 pins can be written to to set them to low or high.
See the datasheet for more details.
When hooked up to a hd44780 interface and a backlight circuit:

4 pins are used for LCD data
1 pin for RW (sometimes)
1 pin for RS
1 pin for E
That only leaves 1 pin for backlight control.
The remaining pin can be hooked up to a transistor for backlight control.
With only one pin you only get on or off for backlight control
and cannot support dimming.

The function setBacklight(dimvalue) does the best it can given the underlying
hardware. With only on/off control any value other than 0 results in the backlight
full on.

--- bill

Hi,

thanks for your reply. Ok, i dont understand the matter....

On the board is a transistor near the black jumper. I have understand that the 1 pin () is connected to this transistor on the base. So for my understanding i make the PWM on this pin by software with lcd.setBacklight(50) and this is going to this transistor.....

How i make an circuit to do some PWM for backlight? Can you give me a hint? Thanks

See my attachment please.

ht81:
How i make an circuit to do some PWM for backlight? Can you give me a hint? Thanks

Like I said before, you can't:

8 pins can be written to to set them to low or high

The PCF8574 is a very simple chip. You can read the 8 pins on the port or
set the any of pins to high or low.
It works like a light switch in your house.
So just like in your house, you can't get dimming on a light bulb when using
an on/off light switch because the switch can only be on or off.

--- bill

One way it could be done is by taking one of the PWM outputs from the processor and driving a npn transistor or FET connected to the backlight LED cathode. The normal backlight control should be turn off for the PWM to work.

It will need an extra wire to the display but only uses one Arduino pin.

Bob

bperrybap:

// set the LCD address to 0x27 for a 20 chars 4 line display

// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

Yep, apart from the disparity between the comment and the constructor, that is the right constructor for the "LCM1602" - in contrast to the mjkdz where it is:

#define lcdAddr 0x20 // set the address of the I2C device the LCD is connected to

// create an lcd instance with correct constructor for how the lcd is wired to the I2C chip
LiquidCrystal_I2C lcd(lcdAddr, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE); // addr, EN, RW, RS, D4, D5, D6, D7, Backlight, POLARITY

Got me up and going just fine. 8)

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

#define lcdAddr 0x27 // set the address of the I2C device the LCD is connected to

// create an lcd instance with correct constructor for how the lcd is wired to the I2C chip
LiquidCrystal_I2C lcd(lcdAddr, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // addr, EN, RW, RS, D4, D5, D6, D7, Backlight, POLARITY

// Creat a set of new characters
const uint8_t charBitmap[][8] = {
   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
   
};

void setup()
{
   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

  lcd.begin(16,2);  // initialize the lcd as 20x4 (16,2 for 16x2)
  
  lcd.setBacklight(1); // switch on the backlight

  for ( int i = 0; i < charBitmapSize; i++ )
   {
      lcd.createChar ( i, (uint8_t *)charBitmap[i] );
   }

  lcd.home ();  // go home to character 0 on line 0 (1st line)
  lcd.print("Hello, ARDUINO ");  
  lcd.setCursor(0,1);  // character 0 on line 1 (2nd line)
  lcd.print (" FORUM - fm   ");
/*
  lcd.setCursor(0,2); // character 0 on line 2 (3rd line)
  lcd.print("This is line 2");
  lcd.setCursor(0,3); // character 0 on line 3 (4th line)
  lcd.print("This is line 3");
*/
delay(4000);
}

void loop()
{
   lcd.clear();
   lcd.home ();
   // Do a little animation by writing to the same location
   for ( int i = 0; i < 2; i++ )
   {
      for ( int j = 0; j < 16; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 1 );
   }
   delay (200);
}

Just to throw a spanner in the works, Arduino 1.5.4

So.. has anybody actually got the LCM1602 IIC with the PCF8574T chip to work correctly with the ATTiny85 through I2C protocol using TinyWireM.h?

I'm stumped.

Thank god.

This is an old thread and deserves a bump even though its very old..

This is still an issue, today i received a I2C module for LCD displays,
exactly like OP has posted, exactly same problems, just blinking backlight.

Using his example and the lib linked, it works like a charm.

Only difference is the I2C address was now for me 0x27

Amazing.

THANK YOU TERRY!

I used NewLiquidCrystal_1.5.1.zip (by F Malaparte) as reccomended.
I bought my LCD+I2C here : LCD Display 1602 verde + adaptor i2c - ARDUSHOP

The supplier says:
pin 1: Vss;
pin 2: Vdd;
pin 3: Vo - contrast LCD (între Vss și Vdd V);
pin 4: RS;
pin 5: R/W;
pin 6: E - enable;
pin 7 - 14: DB0 - DB7;
pin 15: V+ backlight;
pin 16: V- backlight

The pins on the LCD are marked VSS,VDD,Rs,Rw,En,D0,D1,D2,D3,D4,D5,D6,D7,A,K - this is a match.

So I wrote:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define LCD_I2C 0x27
enum LcdPin{VSS,VDD,Rs,Rw,En,D0,D1,D2,D3,D4,D5,D6,D7,Light_A,Light_K};

// hope pin0 is the leftmost (i.e. pin 1)
LiquidCrystal_I2C lcd(LCD_I2C,LcdPin::En,LcdPin::Rw,LcdPin::Rs
,LcdPin::D4,LcdPin::D5,LcdPin::D6,LcdPin::D7
,LcdPin::Light_A,POSITIVE);

/* copied from this topic (above):
I2C Address for the PCF8574T =0x20
---(Following are the PCF8574 pin assignments to LCD connections )----
This are different than earlier/different I2C LCD displays
enum LcdPin{Rs,Rw,En,LIGHT,D4,D5,D6,D7};*/

I compiled with Arduino IDE 1.8.9 and I got the following compilation error twice (it worked the 3rd time):

C:\Users\Mircea\Arduino\libraries\NewLiquidCrystal_lib\LiquidCrystal_I2C.cpp: In member function 'write4bits.constprop':

C:\Users\Mircea\Arduino\libraries\NewLiquidCrystal_lib\LiquidCrystal_I2C.cpp:295:1: internal compiler error: Segmentation fault

}

^

Please submit a full bug report,

with preprocessed source if appropriate.

See http://gcc.gnu.org/bugs.html for instructions.

lto-wrapper.exe: fatal error: C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Eroare de compilare pentru placa Arduino Nano.

The LCD still does not work

fmalpartida's library was until fairly recently, the best available.

Bill Perry has however, written an even more comprehensive version which you install via the IDE itself with no problems or confusion about names, look for the "HD44780" library in the Library Manager.

Once installed, it provides examples for you to use to identify and test your hardware, then you use the HD44780 functionality in your own code.


Also read carefully the guide for posting here.

This thread is over 6 years old. Many things have changed since then.
I'd recommend anyone having issues start their own thread.

-- bill

Nevertheless, you will not dispute my answer to MirceaLutic (since you wrote the library I recommended). :grinning: