Basic LCD to PCF8574N library problem

I am running the Arduino IDE 1.6.4. I have deleted the LiquidCrystal library, downloaded FM's library (LiquidCrystal_V1.2.1.zip), placed it in the /Arduino/libraries folder then selected Sketch-Include Library-add .zip library.

Then the problem arises. I try to run Gammons I2C scanner and it just hangs with line 0 on the LCD all black boxes. Further digging got it working, briefly. Now nothing. Searching internet it seems there are at least 3 different pin configurations just for FM's library. There are multiple LiquidCrystal.h and LiquidCrystal_I2C.h libraries out there, all with different pin configurations that are apparently hard coded in the libraries. Even FM's library with assorted links has different pinouts. I have rebuilt the circuit several times with occasional success only to lose it all after a reboot.

I have talked with some friends in the area that use the Arduino on a regular basis for some years now and when I ask about I2C thire eyes roll. Further inquiry reveals a degree of frustration due to this very issue. None have been able to get a functioning I2c scanner/library combination that would work reliably. Now these guys are not rocket scientist but they are not idiots either so I have volunteered to sort this issue out. There are tons or postings trying to accomplish this and the best answer I have found is "I found a library that worked and didn't look any farther." In other words "good luck".

Please, please, could some kind soul point me to a library BY NAME and a pinout (LCD EN=pin9(P4)PCF8574N, LCD RS=pin11(P6)PCF8574N, etc, and a scanner that should work? To say I have been in tears over the last few days trying to get basic I2C functionality is not an exaggeration and I will eventually find a solution but some help would be appreciated.

The only circuit I am testing is Uno R3 A4,A5 to SDA(pin15),SCL(pin14), power and ground. The address pins are all pulled low (0x20). Thats it, no backlight switching, nothing but SDA/SCL. I do not have any sort of logic/protocol analyzer.

I apologize for my 'tone', little food and less sleep does bad things to ones mindset :frowning:

Problem solved. For those newb's attempting I2C to LCD; Be sure and assign ALL the pins for the LCD when defining Liquid_Crystal_I2c.h (FM's library needs this). For my wiring the line looks like this:

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

My biggest problem however was Windoze itself. I'm running Win7 Pro 64 and a recent update broke something in the USB port dropping it intermittently. Now if there is an issue I have to disable then enable the Com port(3). No solution to that yet but at least I can get on with things.

My thanks to fmalpartida for his library and Mr.Gammon for his scanner. Life is good.

Almost forgot, this is for a naked PCF8574N to LCD, no backpack.

adwsail:
Problem solved. For those newb's attempting I2C to LCD; Be sure and assign ALL the pins for the LCD when defining Liquid_Crystal_I2c.h (FM's library needs this). For my wiring the line looks like this:

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

. . .

My thanks to fmalpartida for his library and Mr.Gammon for his scanner. Life is good.

Why not go one step further. Since you have made the connections between the PCF8574 and the LCD yourself (no backpack) this would be a good opportunity to present your circuit diagram and then, on the basis of that diagram, explain how you came up with the values in the constructor.

Don

Good idea and glad to help floresta.

You will need to be ABSOLUTELY sure you have moved or deleted any library that says I2C, LiquidCrystal, LiquidCrystal_I2C, etc, and put the FM library (download from https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/LiquidCrystal_V1.2.1.zip) in /Arduino/libraries. Change the name to LiquidCrystal.zip and start the Arduino IDE. Go to Sketch-Include Library-Add .ZIP Library and select your renamed LiquidCrystal.zip library.

The LCD I am using (LCM-S01602DTR/M, $8.38 Mouser) does not have a backlight but its cheap enough and apparently HD44780 compliant. That said the pin to function numbering is standard. The numbering ON THE LCD is NOT standard. It is 14,13,12,…3,2,1,16,15. I have another LCD that is a straight 1-16 so ALWAYS check the data sheet for the device in hand.

First we will setup the I2C device, a PCF8574N from Mouser ($2.06)

Arduino Uno R3 A4 → PCF8574N SDA(pin15)
Arduino Uno R3 A5 → PCF8574N SCL(pin4)

Place +5VDC on pin 16 of the PCF8574N and tie pins 1,2,3,8 to ground. Grab Nick Gammons I2C Scanner, found at http://playground.arduino.cc/Main/I2cScanner, and run it.

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, 20 May 2015
//     Added on board visual LED check for hung state after 'endTransmission'.
//     By Dale Ward
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
 
#include <Wire.h>
 
 
void setup()
{
  Wire.begin();

  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);

  Serial.begin(115200);
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
  
 digitalWrite(13, HIGH);   // turn the on board LED on 
  //delay(1000);              // wait for a second
    
  
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 2; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    
    
    error = Wire.endTransmission();
 
 digitalWrite(13, LOW);    // turn the LED off 
    
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
      
 
  //delay(1000); 
  
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknow error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

You should see a result exactly like this:


Scanning…
I2C device found at address 0x20 !
done

If you do not see the above place a 4.7k resistor on the PCF8574N pin15 to +5VDC. That should make it work. If it doesn’t work check to be sure Windows has not dropped the Com port and double check your wiring. You CAN NOT proceed with the LCD until you have a recognized I2C device out there.

Next we will add our 16x2 LCD. On all HD44780 compliant LCD’s connect pin 1 and pin 16 to ground. Connect pin 2 and pin 15 to +5VDC. The rest of the pins can be connected many different ways but this definitely works:

LCD En (pin6) to P2(pin6) on PCF8574N
LCD RW (pin5) to P1(pin5) on PCF8574N
LCD RS (pin4) to P0(pin4) on PCF8574N
LCD D4 (pin11) to P4(pin9) on PCF8574N
LCD D5 (pin12) to P5(pin10) on PCF8574N
LCD D6 (pin13) to P6(pin11) on PCF8574N
LCD D7 (pin14) to P7(pin12) on PCF8574N

using the following test program:

/* This is a simple I2C to LCD test program using the fm library, LiquidCrystal_V1.2.1.zip.
Proper removal of any existing I2C or LiquidCrystal libraries prior to installing this library is absolutely essential.
All code here is open to the public to use as they see fit but no guarantees are stated or implied.


Code modified by Dale Ward, 20 May 2015.

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

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

void setup()
{
  lcd.begin(16,2);               // initialize the lcd 
  lcd.home ();                   // go home
   lcd.print("Hello, ARDUINO ");      
}

void loop()
{
 lcd.clear ();
  lcd.setCursor (3,0);
 lcd.print ("Have Fun!");
  lcd.setCursor ( 5, 1 );  // go to the next line
 lcd.print ("WORLD!");
 delay(1000);
}

That’s it!

This, like many hardware/software examples is quite simple IN HINDSIGHT. I am a 62 year old newb that believes in helping when you can but believe me when I say it took me DAYS to get to this ‘simple’ and effective solution for using an Arduino Uno Rev3 with a PCF8574N to talk to a 16x2 LCD via I2c. The key is the proper library installation. Good luck!!!

That said the pin to function numbering is standard. The numbering ON THE LCD is NOT standard. It is 14,13,12,...3,2,1,16,15.

Just to clarify things a bit...

As you said in the first sentence quoted above, the numbering of the pins on your LCD module is standard. On your LCD module it is the location of the pins, not their numbering, that that is not standard.

In general the LCD modules that have a single row of pins above and to the left of the display are the most common and on all of them that I am familiar with the pins are numbered sequentially starting with pin 1 nearest the edge of the pc board.

On the other hand there is no standard whatsoever for the LCD modules that have a single row of pins below and to the left of the display. Although the pin numbers typically match those of the other modules the pin locations follow several different patterns.

Don

Here is some more emphasis on the key point:

It is the I/O numbers 0 - 7 (given the symbols 'P0' - 'P7' on the datasheet) of the PCF8574N that are entered into the corresponding locations in the constructor. So extracting the key values from the list above we get:

LCD [b]En[/b] (pin6)  to P[b]2[/b] (pin6)  on PCF8574N 
LCD [b]RW[/b] (pin5)  to P[b]1[/b] (pin5)  on PCF8574N
LCD [b]RS[/b] (pin4)  to P[b]0[/b] (pin4)  on PCF8574N
LCD [b]D4[/b] (pin11) to P[b]4[/b] (pin9)  on PCF8574N
LCD [b]D5[/b] (pin12) to P[b]5[/b] (pin10) on PCF8574N
LCD [b]D6[/b] (pin13) to P6 (pin11) on PCF8574N
LCD [b]D7[/b] (pin14) to P[b]7[/b] (pin12) on PCF8574N

or:

En --> 2 
RW --> 1 
RS --> 0 
D4 --> 4 
D5 --> 5 
D6 --> 6 
D7 --> 7

and thus:

//LiquidCrystal_I2C lcd(I2C address,En,RW,RS,D4,D5,D6,D7,Backlight,BL polarity);

LiquidCrystal_I2C lcd(0x20,[b]2,1,0,4,5,6,7[/b],3,POSITIVE);

Don

Nicely put Don, thank you!