SOLVED I2C module board software not working

I wanted to run various boards from one UNO so I am looking at running a 1602 display with a
Board Module Port IIC/I2C/TWI/SP??I Serial Interface For Arduino 1602 LCD. from ebay.
Connected, the display shows the dark blocks where it should so I loaded software supplied from sainsmart :-

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

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

void setup()
{
  lcd.init();                      // initialize the lcd 
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Hello, world!");
  lcd.setCursor(2,1);
  lcd.print("SainSmart for UNO");
   lcd.setCursor(2,2);
  lcd.print("SainSmart LCM IIC");
   lcd.setCursor(1,3);
  lcd.print("Design By SainSmart");
}

void loop()
{
}

and when compiled it said there was a problem with Liquidcrystal_I2C, I forget the actual wording.
AH... no Liquidcrystal_I2C library... so I loaded that into my libraries. When I try to compile now I get errors.
I just get 'error compiling' on the orange line and

In file included from I2cdisplay.ino:3:
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:81: error: conflicting return type specified for 'virtual void LiquidCrystal_I2C::write(uint8_t)'
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'

in the box below.
Can anyone see what I am doing wrong?
The sketch is from the liquidcrystal_I2C library examples.
Thanks.
mat.

I have been looking at the options and decided to include the
LCD_I2C library and the example from the arduino playground

http://playground.arduino.cc/Main/LCDI2C

this one compiles and loads into the UNO but it has

LCD_I2C lcd(0x00, 4, 20);

as the initial line. with this in place the display stays with just dark squares so I changed it to

LCD_I2C lcd(0x3f, 2, 16);

this made no difference to the display.
Any ideas?

thanks.

Any ideas?

Try putting LCD I2C into the search box in the upper right part of this page and see if any of the 12,400 results (you may get a different number in the UK) give you any ideas.

The underlying theme is that there are several available libraries, the one by 'fm' is currently the recommended one, and you have to avoid conflicts between multiple available libraries.

Don

Thanks floresta.
I am slowly working through the other threads on here .
I have found that some I2c units work on 0x27 and some on 0x3f but putting these into that top line seems to make no difference. I am reluctant at this point to add another library and another sketch, surely both the ones I have tried have been tested and work for someone.
I have noticed I am using a single line display but changing the line to
LCD_I2C lcd(0x27, 1, 16); or LCD_I2C lcd(0x3f, 1, 16);
has made no difference,
I know there is an odd way of addressing the single line displays could this be part of the problem? if so I haven't yet found a way round it.

I have now removed all the lcd libraries, installed fm's library and run Nick Gammons i2c tester, this showed my i2c unit to be working and using address 0x27.
I have tried to run the following prog

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

LiquidCrystal_I2C lcd(0x27);  // 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(8,2);               // initialize the lcd 

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

void loop()
{

}

the programme compiles which looks as if I have done the right thing with the library but all I get still is the faint boxes that I can alter the brightness of with the pot on the i2c unit.
My lcd display is a single row display that works if I connect it direct to the arduino. I tell the software the display is a 8 column 2 row as in "lcd.begin(8,2);" as this correctly feeds info to the single line display.
Does anyone know what I am doing wrong?

I tell the software the display is a 8 column 2 row as in "lcd.begin(8,2);" as this correctly feeds info to the single line display.

This is the correct way to deal with the majority of the 16x1 displays.

Does anyone know what I am doing wrong?

Nothing wrong yet, just incomplete. You still have to establish and inform the library about the connections between the I/O pins on the adapter chip and the I/O pins on the adapter board. You do this with the I2C guesser by bperrybap. --> [SOLVED] MJKDZ brand I2C Controller working with 1602 LCD - Displays - Arduino Forum

Don

thanks,
I have downloaded the file you show, uploaded it to the UNO and run it. I get the warning when I open the monitor and a request to press enter or click on the send button. If I do either, that is load the file and do one or reload the file and do the other nothing happens, there is no change on the screen as if I have done nothing. It says not to leave the test for too long but is 30 seconds enough to wait for some indication?
If I load Nick Gammon's I2C tester file it gives me the address of the I2C unit as 0x27 and says the unit is ok.
I changed the lines
#define LCD_COLS 16
#define LCD_ROWS 2 to
#define LCD_COLS 8
#define LCD_ROWS 2
how do I "establish and inform the library"? Do I have to add more lines to the program below?

The problem you are having is there is no standard way to wire up a PCF8574 to a HCD44780
interface. Because of this the library has to either assume a particular wiring or has to be told.
The first library you had made an assumption, it didn't match your boards wiring.
fm's library will make also an assumption if you don't tell it the pin mapping in the constructor.
When you don't tell it the pin mapping, the assumption is for the wiring that is on the ElectroFun board.
There is no other board that I have seen use the wiring that is used on the ElectroFun backpack, so
again it will not match your wiring and that is why it didn't work when you only filled in the i2c address.
You must fill in the full constructor with all the pin mapping and backlight information.

You can use the guesser sketch to guess the constructor parameters for your board to work with fm's library.
If you use it, make sure to read all the information up to the instruction steps for how
to use it and what it does, then, you must follow all 6 steps. If you don't, it will not work.

I see the same problem over and over again.
People report that the guesser sketch fails to do anything or identify the constructor.
It always goes back to not reading and following all the instructions in the sketch.

Note: If you are unable or unwilling to change your newline ending, then you can
type in a key into the input box before clicking on the [send] button instead of
pressing the key.

--- bill

I have a board similar to the one here it clearly shows the board soldered direct to the back of the display. Does this mean the wiring is correct?

The only line I have concerns with is line 2
2. hookup the i2c backpack and only the i2c backpack to the Arduino

  • (make sure to use the needed pullup resistors -
  • i2c needs them to work correctly)
    I am assuming the i2c board has internal resistors (which I am sure I read somewhere) as there are non on the connection linked above and does 'only the backpack' mean don't connect any other hardware beside the display as the indication from the sketch shows on the display so that must be connected as well?

matelot:
I have a board similar to the one here it clearly shows the board soldered direct to the back of the display. Does this mean the wiring is correct?

Many of these look very similar but are not same.
Did your LCD come with the backpack attached or did you buy them separately and then you solder pins
or a header to it to connect it to the LCD.
Depending on the backpack, the PCF8574 ic chip may go on top or on the bottom when attached to the LCD and the header pins may point out from the edge or twards the center of the LCD.
Because the backlight power and LED backlight pins are symmetric on each end, if the backpack is connected to the LCD upside down, (reversing the pins) the LCD may still light up and show the uninitialised blocks on the display.
The key is look for the pin 1 designator on the backpack. One of the holes will have a square etch or square printed on it like the one in that photo.
Then look for the pin 1 designator on the LCD. Many will have the same square marking or even a "1" on the holes.
If pin 1 of the LCD and pin 1 of the backpack line up you are good to go.

Do you have a link to yours or a photo?

The only line I have concerns with is line 2
2. hookup the i2c backpack and only the i2c backpack to the Arduino

  • (make sure to use the needed pullup resistors -
  • i2c needs them to work correctly)
    I am assuming the i2c board has internal resistors (which I am sure I read somewhere) as there are non on the connection linked above and does 'only the backpack' mean don't connect any other hardware beside the display as the indication from the sketch shows on the display so that must be connected as well?

What I was trying to say is don't have any other i2c devices on the bus because the guesser sketch will probe the i2c bus to locate the address of the backpack and it might get confused if there is more than one i2c device since it jumps on the first i2c address it finds.

As far as pullups go, you can usually see them. Some times you many need a flashlight to peek at the bottom
if the board is soldered to the LCD.

For LCD backpacks when using an AVR, like what is on the UNO, it will usually work even if there are no external pullups since the wires are so short.
Given that the i2c scanner you ran was able to locate the backpack, it appears to be working at least under these conditions.

You should be ok to run the guesser and then tell it to advanced its guesses until it shows the constructor to use on the LCD screen and serial monitor.

--- bill

I have a board similar to the one here it clearly shows the board soldered direct to the back of the display. Does this mean the wiring is correct?

The wiring between the adapter board and the LCD module is always the same and is therefore 'correct' as long as you connect the two as intended (as shown in the photos in your eBay link).

It is the wiring on the adapter board itself, between its IC and its I/O pins that will vary by manufacturer and this is what the guesser is attempting to determine.

Don

Did your LCD come with the backpack attached or did you buy them separately and then you solder pins or a header to it to connect it to the LCD.

The displays are recycled and the i2c board is from ebay.

The key is look for the pin 1 designator on the backpack. One of the holes will have a square etch or square printed on it like the one in that photo.
Then look for the pin 1 designator on the LCD. Many will have the same square marking or even a "1" on the holes.
If pin 1 of the LCD and pin 1 of the backpack line up you are good to go.

The i2c has the square around pin 1 and the display has the number 1. The display has no back light so no pins 15 and 16.

As far as pullups go, you can usually see them. Some times you many need a flashlight to peek at the bottom
if the board is soldered to the LCD.

There are a number of surface mount resistors on the i2c board I assume are the pullup resistors.

Right! Now I am getting somewhere. I set everything up to take a photo as requested here and decided to just try it a last time.
With the guesser program installed I opened the monitor.
If I press or click the send button on the monitor nothing happens, even with the cursor flashing in the box at the top of the monitor, if, however, I put the letter a in the box and then press the monitor screen adds the chip I am using (PCF8574) and the fact that its address is 0x27.
If I put ‘a’ in the box again and press I get

Trying: lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE)
<Press or click [Send] to Continue>

After a few moments I get
0x27,2,15,6,7,3, on the screen.

A careful look at this shows I am getting the first 8 symbols of the above ‘trying’ line, missing the next 4 and then getting the last 8 i.e.
0x27,2,1………5,6,7,3,
There are six different options the guesser checks and this is the only one that shows anything on the screen.
This is the indication I get on two of my displays (I removed them from old printers) so I assume the displays are ok and this is because I am not addressing the single line LCD properly.

How and where do I now enter this information and do I then just write a program as if I am using the LCD library normally?

Looking at the guesser program I am assuming the numbers
0x27,2,1,0,4,5,6,7,3
refer to the i2c address, en, rw, rs, data, data, data, data, backlight
does this mean that with the pin that has the square line around it is referred to as '0' this needs to connect to the rs pin on the display, in my case pin 4 of the display......... no it can't, can it? pin 1 of the i2c (with the square around it) is 0v?

I have bent the pins on another display so that it will plug straight into the digital side of an UNO with 0v in the pin next to d13, a wire across to 5v to pin 2, pin 3 has a pot connected for the brightness, pin 4 goes into d12, pin5 to 0v, pin 6 into d11 and then pins 11,12,13 and 14 to d6,d5,d4,d3. This works fine but I am wanting to try to run a display with 2 wires.
I then put

LiquidCrystal lcd(12, 11, 6, 5, 4, 3);

as one of the lines in the program, that is (rs,en,data,data,data,data).
Do I do something similar adding

LiquidCrystal_I2C lcd(0x27);

to my program? Will the library then convert this to send the info down the SCL and SCA lines a4 and a5?

Looking at the guesser program I am assuming the numbers
0x27,2,1,0,4,5,6,7,3
refer to the i2c address, en, rw, rs, data, data, data, data, backlight ...

This much is correct.

... does this mean that with the pin that has the square line around it is referred to as '0' this needs to connect to the rs pin on the display, in my case pin 4 of the display......... no it can't, can it? pin 1 of the i2c (with the square around it) is 0v?

This part is not correct. The numbers correspond with the I/O pin numbers on the PCF8574 chip that is on the I2C adapter. All you have to do is let the library know about those relationships, via the constructor, so it can send the correct information to the appropriate I/O pins of the PCF8574. You do not have to do anything out of the ordinary with the pins that connect your display to the adapter.

Don

I don't understand where I am to put the information the guesser has given me and I can't find any sketch that does this for me to use.
would you mind just writing the bare bones of a sketch that would put a word on the lcd that I could then experiment with and alter as my understanding grows?

update
I found a program and have altered it to fit my situation 1 row 16 columns and it works fine.

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library


#define I2C_ADDR    0x27  // Define I2C Address for controller
#define BACKLIGHT_PIN  3
#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

#define  LED_OFF  0
#define  LED_ON  1
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() 
{
  lcd.begin (8,2);  // initialize the lcd
// Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
  lcd.setBacklight(LED_ON);
}

void loop()  
{

// Reset the display 
  lcd.clear();
  delay(1000);
  lcd.home();
 
// Print on the LCD
  lcd.backlight();  
  lcd.setCursor(0,0); 
  lcd.print("Hello, w");
  lcd.setCursor(0,1); 
  lcd.print("orld!");
  delay(8000);
}

Thanks for the help guys

matelot:
would you mind just writing the bare bones of a sketch that would put a word on the lcd that I could then experiment with and alter as my understanding grows?

Unfortunately, as I said in post #7 that is simply not possible.
(There are 40,320 possible permutations of how the PCF8574 output port pins could be wired up to the LCD)
It is the equivalent of you wiring up a LCD directly to Arduino pins and now asking for someone to provide a sample bare bones sketch that uses the LiquidCrystal IDE library without telling how you wired up the pins. It simply is not possible. The LiquidCrystal library needs to know how the LCD pins were wired up to the Arduino pins; that is what the pin numbers in the constructor are telling it.

With fm's LiquidCrystal_I2C library class, it is the same.
In this case, the "pin" numbers in the LiquidCrystal_I2C constuctor are telling fm's library how the LCD pins are wired up to the PCF8574 output port pins.
Even though you didn't do any of wiring, and the wiring is hard-coded in PCB etch in the backpack, you still must tell the library how it is wired, because not all backpacks wire up the LCD pins to the same PCF8574 port pins and there no way to determine the wiring from s/w.

Until you get the constructor correct, which defines how the LCD is wired up the PCF8574 port pins, there is no way to put anything on display since the constructor tells the library how the LCD pins are wired up the PCF8574 port pins.
The library must know which PCF8574 output pin to wiggle to control each LCD pin function to be able to talk to the LCD.

In the ideal case the etch traces on the PCB between the PCF8574 and the LCD are closely examined or an ohm meter is used to determine how the PCF8574 pins are connected to the LCD pins to determine the pin numbers to fill into the constructor. Normally this only takes a few minutes.

Without knowing the proper pin information the odds of randomly determining it through trial and error are VERY low.
Consider this: there are 8 signals that could be wired up in any order. This gives 40,320 permutations of the wiring and then there are 2 possibilities for the backlight polarity giving a total of 80,640 possible different constructors.
Not something that could be tried at random since the odds of randomly picking the correct information is very low and when the constructor is filled in with the wrong pin mapping information nothing can be displayed on the LCD.

So as as an alternative to requiring people to have the skills to properly analyze their backpack, I wrote the guesser to try to help them by being smarter about how to "guess" at how the wires are connected. After examining many of the backpacks on the market, it turns out that there are only about 4 different pin wirings that all the backpacks are using.
It still requires guessing because there is no way for the s/w to know when the mapping is correct because the HD44780 interface to the LCD is being used in a write only mode.
i.e. the backpack will attempt to write to the display but it has now idea if the display is able to understand the signals - which it won't if the signal information is being put on the wrong signals from being told incorrect pin mapping information.

A human must be involved to look at the display to see if the guess was correct. When it isn't the human tells the guesser to advance to the next guess.

The potential issue with guessing pin mapping is when the guess is wrong, the signals are not talking correctly and depending on several factors, it is possibility that there could be situation where both the LCD and the PCF8574 are fighting each other to control the level a signal line. In this case, it is possible that it could cause damage to either the backpack or the LCD. In real world experience most backpacks don't wire up the r/w signal the PCF8574, but rather directly to ground. For those backpacks there is no issue. Even on the others, the signal levels don't seem to have any fatal issues at least not during short periods of time while testing.

The point of the guesser sketch is to give you the exact information to put into the LiquidCrystal_I2C constructor.
Run the guesser, look at the LCD and when the guesser guesses the constructor correctly, it will show you what you what you need to put in the constructor. If the guess is incorrect, tell the guesser to guess again.
It really is just that simple.

With respect to this sample code:

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() 
{
  lcd.begin (8,2);  // initialize the lcd
// Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
  lcd.setBacklight(LED_ON);
}

That example is using the old version of the constructor and also using some deprecated API functions.

It would be better to use the full constructor which tells the library how the backlight is wired up.
example:

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin, BACKLIGHT_PIN, NEGATIVE);

void setup()
{
lcd.begin (8,2); // initialize the lcd, which turns on the backlight
}

The reason to use the full constructor is that it makes changing between interfaces easier.
Say you wanted to change from an i2c backpack to directly connected wires, then if you use the full constructor, all you have to do is define a different lcd object and fill in the full constructor for the class. The rest of the sketch code will "just work" with no changes.

--- bill

OK Bill thanks for that.

Quote from: matelot on Mar 20, 2015, 04:05 pm

would you mind just writing the bare bones of a sketch that would put a word on the lcd that I could then experiment with and alter as my understanding grows?

Unfortunately, as I said in post #7 that is simply not possible.
(There are 40,320 possible permutations of how the PCF8574 output port pins could be wired up to the LCD)
It is the equivalent of you wiring up a LCD directly to Arduino pins and now asking for someone to provide a sample bare bones sketch that uses the LiquidCrystal IDE library without telling how you wired up the pins. It simply is not possible. The LiquidCrystal library needs to know how the LCD pins were wired up to the Arduino pins; that is what the pin numbers in the constructor are telling it.

In post #12 I said what the reading from your guesser where I just didn't know how to write them into a program so I was just asking you to show me how that was done. I found a similar program and realised I just needed to add them as

#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

....full program in #16
So the program is sending to the lcd and working fine now thanks for your input and information.
Bob.