Why is it that getting a simple LCD 1602 is so much easier that one with a i2c adapter

Hi
First an admission. I am far too old to be doing this stuff but it is much more fun than playing computer games!
I have read quite a number "cries for help" about 16,2 LCDs. Thanks to Paul McWhorter I have managed to get one functioning as I want. I have a very specific need for one in a project I am building. so you could say I have solved my problem.
But it seemed obvious that using and 12c adapter would be a neater solution and I thought that simply adapting the software in Drone.Bot would be worthwhile. But like so many others on this forum I to the "Positive was not declared in this scope" message. I have version 1.1.2 of the Liquid Crystal but that does not help.
I admit be being confused about some of the solutions I read so I spent some time wandering through the Liquid Crystal libraries including those incorporating the 44780 Hitachi version but so far nothing has worked.
At the end of the day I can simply stick with the version that does not use the adapter and that I have working even though it requires a lot more wires, but if there is a solution an old bloke is likely to be able to understand I would appreciate the information.
Incidentally, I was not kidding when I said too old to be doing this, I was bornin 1937.
regards
Woodie

disagree. after pain to connect LCD directly, setting contrast with additional potentiometer the LCD with i2c backpack work like a charm and only 4 wires, and same connection for next i2c device, like RTC.

1 Like

... and use the hd44780 library by bperrybap, flawless combination.

3 Likes

85 :person_white_hair:
:open_mouth:

You were a teenager when I was born :woozy_face:


I2C is much easier to use !

Past experiences have shown me that I2C LCDs seem to be less susceptible to problems with electrical noise too.

1 Like

Agree.. that is the best LCD library, and I expect most of the problems you are having is using libraries that don't quite match your code examples. I2C is easy to connect up, and once you get it working you won't go back.

Bloody legend still coding at 85.

I think (may be wrong) that there's more than one library with the same name. If so, it's possible that the actual library installed is not the right one for the code.

Thanks for the quick responses. I have included hd44780 version 1.3.2. but the little orange line persists.

I absolutely agree that the i2c is a better solution but only if I can get it to function. It should not be an issue because I am using Drone Bot code.
I have the latest versions of the libraries as far as I can tell. There is another hd44780 library which I will try.

Bill's example only lists the Wire.h and LiquidCrystal_12c.h libraries.

It is probably time for a reboot I fancy!

But I don't want to waste any more of your time. I will opt to use the simpler version of the 16x 2 because it is just a matter of soldering a few wires. This is a one-off and I know I can include the message I want to highlight in the contraption I am building.
Regards

Woodie

Most people that help on this forum are here because they enjoy helping other people, so I don't think you'd be wasting anyone's time that had anything better to do... :slight_smile:

If you post your code, I'm sure someone here will be able to assist.

1 Like

The problems is that there are a number of LiquidCrystal_I2C libraries and they are not compatible. You will have to look at the examples that come with the library that you installed how to use it. Alernatively find and install the correct library.

If you include that library, you will have to rewrite your code to use that library. Just including it does not solve the problem.

This is the code I copied from Drone.Bot. "POSITIVE" was not declared in this scope appears over the line
LiquidCrystal_IC2 lcd( lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);
/*
LCD Display with I2C Interface Demo
lcd-i2c-demo.ino
Use NewLiquidCrystal Library
DroneBot Workshop 2018
https://dronebotworkshop.com
*/

// Include Wire Library for I2C
#include <Wire.h>
// Include NewLiquidCrystal Library for I2C
#include <LiquidCrystal_I2C.h>

// Define LCD pinout
const int en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3;

// Define I2C Address - change if reqiuired
const int i2c_addr = 0x3F;

LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);

void setup()
{

// Set display type as 16 char, 2 rows
lcd.begin(16,2);

// Print on first row
lcd.setCursor(0,0);
lcd.print("Hello world!");

// Wait 1 second
delay(1000);

// Print on second row
lcd.setCursor(0,1);
lcd.print("How are you?");

// Wait 8 seconds
delay(8000);

// Clear the display
lcd.clear();

}

void loop()
{

// Demo 1 - flash backlight
lcd.setCursor(0,0);
lcd.print("Backlight demo");
lcd.setCursor(0,1);
lcd.print("Flash 4 times");

delay(3000);
lcd.clear();

// Flash backlight 4 times
for(int i = 0; i< 4; i++)
{
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}

// Turn backlight back on
lcd.backlight();

// Demo 2 - scroll
lcd.setCursor(0,0);
lcd.print("Scroll demo - ");
delay(1500);
// set the display to automatically scroll:
lcd.autoscroll();
// print from 0 to 9:
for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(thisChar);
delay(500);
}
// turn off automatic scrolling
lcd.noAutoscroll();

// clear screen
lcd.clear();

//Delay
delay(1000);

}

Thanks
Woodie

That's why I like LCD modules that use a serial backpack.

Ok so definitely a mismatch between your example sketch and the library you are using.

This Dronebot page about using LCD

...now has broken links to the library, so maybe it no longer exists.

Try the example LCD I2C sketch in the Arduino IDE.

File > Examples > Liquid Crystal I2C > Hello World

NewLiquidCrystal library with I2C LCD - Using Arduino / Displays - Arduino Forum

// Include NewLiquidCrystal Library for I2C
LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);

Dump that library.

1. Fig-1 depicts the connection among UNO, I2C adapter, and LCD.
lcdi2cx
Figure-1:

2. Upload the following sketch and check that your LCD is working showing the message on Topline. If not, try by slowly adjusting the R1 pot and then changing the I2C address from 0x27 to 0x3F.

#include<Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); //or LiquidCrystal_I2C lcd(0x3F, 16, 2); 

void setup()
{
  Wire.begin();
  lcd.begin();//or lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);  //arg1 = DisplayPos (0-15), arg2 = LinePos (0-1)
  //------------diagnostic message-----------------
  Wire.beginTransmission(0x27); // or 0x3F
  byte busStatus = Wire.endTransmission();
  if (busStatus != 0)
  {
    Serial.print("I2CLCD is not found!");
    while (1); //wait for ever
  }
  Serial.print("I2CLCD is found!");
  //---------------------
  lcd.print("Forum"); //show message
}

void loop() {}
1 Like

He doesn't have that library... BUT... he has an old example sketch that is trying to use it.

Is that "Bill" you refer to, me?
If so the hd44780 library examples never reference "LiquidCrystal_I2C.h" (I assume you misspelled your header file name in your comment)
The hd44780 library for your type of device will use
Wire.h
hd44780.h
hd44780ioClass/hd44780_I2Cexp.h

If you get an error reporting something about "POSITIVE" missing / undeclared, it means your code is attempting use the LiquidCrystal_I2C i/o class of FM's newLiquidCrystal library but the IDE is pulling in a different library.

This is caused by having a "LiquidCrystal_I2C" library installed (there are several of those BTW) and either not having newLiquidCrystal library installed or having both LiquidCrystal_I2C and newLiquidCrystal installed.
This is because both LiquidCrystal_I2C and newLiquidCrystal both have a header file named LiquidCrystal_I2C.h
This means that even if you have newLiquidCrystal installed, you can still end up using the LiquidCrystal_I2C.h header file from the LiquidCrystal_I2C library instead of the one from newLiquidCrystal since the IDE will prefer to use a header file from a library in a directory name whose basename matches the name of the header file.

My suggestion is to install the hd44780 library and use the hd44780_I2Cexp i/o class. The library will give you a "plug and play" "it just works" out of the box experience since it can auto locate the i2c address and auto detect the pin mappings used between PCF8574 chip and hd44780 LCD.
It is faster with more features and better documented than any of the other lcd libraries.
It also includes a diagnostic sketch to test hd44780 LCDs that use i2c backpacks and will not have any library compatibility issues regardless of any other libraries that may be installed on your system.

--- bill

1 Like

Thanks, I really appreciate the feedback and, to be absolutely honest, was not expecting much help.
But it is going to take a little while to absorb the advice and I will have go through it a bit at a time. The Bill I was referring to was the bloke who runs dronebotworkshop which, as I said is where the software came from.
regards and thanks again
Woodie

There's not much to it.

  • Install Bill (bperrybap) Perry's hd44780 library from the library manager by going:
    Sketch
    -Include Library
    --Manage Libraries..
    (or control- shift -i)

image

  • Then run the Hello World example for the hd44780_I2Cexp class to check all is good by following the path:
    File
    -Examples
    --hd44780
    ---ioClass
    ----hd44780_I2Cexp
    -----HelloWorld
  • Then in a copy of your actual sketch, comment out (or remove) the lines that establish the LCD the "old" way and copy in from the tested example, the lines to establish it the "new" way.
  • If you originally called your LCD "lcd" (and it seems you did) then that's all you need to do: the example calls it "lcd" as well. If not, and let's say you called it "mylcd" or something, then you need to get that all to match through the sketch where you do for example an lcd.print() or whatever.
  • The partial code below is based on something I posted for another user a few days ago, where I helped them with some stuff but preferred to use the hd44780 library so I changed their code as I have just explained to you. You can see I commented out the "old" and added some "new":
// how to convert "non-bperrybap lcd code" to "bperrybap lcd code"
// ymmv

// replaced #include <LiquidCrystal_I2C.h> // Library for LCD... with:
#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config exapander chip
// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
// end of stuff for bperrybap library

// not used LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x3F, 16 column and 2 rows

void setup()
{
  // not used lcd.init();               // initialize the lcd
  // not used  lcd.backlight();          // open the backlight
  lcd.begin(LCD_COLS, LCD_ROWS); //new
  lcd.print("  blah blah"); // so these lcd.whatever() lines stay the same
  lcd.setCursor(0, 1);      // so these lcd.whatever() lines stay the same

  // rest of setup()
  
}//setup

void loop()
{
  // existing loop() stuff
}//loop

Told ya you would.

How much help has dronebotworkshop been?