Need HELP ! with LiquidCrystal_I2C

Hello, Working on a code for my solarheating panel, but i cant get the LCD to work. The program is working but nothing i the LCD. Can someone help me with the code for the LCD?
I'm old, wearing reading glasses, and new on programming :grinning:
Desperate for some help.

//Differential Temperature Controller

#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

//----DS18B20 definitions (temperature sensors)
  #define ONE_WIRE_BUS 2

//----LCD definitions
  #define I2C_ADDR    0x3F //LCD device I2C address.
  #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
  
  //other constants
  #define pumpPin 3     //Named for clarity.  Pump signal output at digital pin 3 (see setup)
  #define ledPin 4
  LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
  
  OneWire oneWire(ONE_WIRE_BUS); //Refer oneWire to Bus for DS18B20 sensor communication
  
  DallasTemperature sensors(&oneWire);

//----variables

  int tankLimit = 180;  //set tank overtemp protection
  int startDT = 10;     //set differential temperature to start pump
  int stopDT = 3;       //set differential temperature to stop pump

void setup(void)
{
 sensors.begin(); //start up the sensors
 
 lcd.begin (16,2); //start up the LCD
 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); 
 lcd.setBacklight(HIGH); // Switch on the backlight

 pinMode(pumpPin, OUTPUT); //set digital pin for pump to output type
 pinMode(ledPin, OUTPUT);
 digitalWrite(pumpPin, HIGH); //starts with pump off (HIGH = relay off)
 lcd.setCursor(9,0);  //go to pump status line
 lcd.print("Pmp:Off"); //Initial until pump loop changes state
}

void loop(void)
{ 
  sensors.requestTemperatures(); //get current values from sensors
  float tankT = sensors.getTempFByIndex(0);  
  float collT = sensors.getTempFByIndex(1); 
 
//display System Status on LCD.  Pump status prints under pump control loop below.
  lcd.home ();             
  lcd.print("Tank:");
  lcd.print(round(tankT));  
  lcd.print("F ");          //"F_" eliminates bug that would display "FF" sometimes.
  lcd.setCursor(0,1);       
  lcd.print("Collector:");
  lcd.print(round(collT));  
  lcd.print("F "); 
  

//Pump control loop
/*This loop uses three scenarios to control the pump, always with a qualifier that tank limit temp is not exceeded.
 * 1) dT higher than startDT  (turn on pump)
 * 2) dT between stopDT and start dT (keep pump in current state)
 * 3) dT below stopDT (turn off pump)
 */

    if (  ( (collT - startDT) > tankT ) && ( tankT < tankLimit ) ) //if the measured dT is bigger than startDT, turn on the pump
    {
          digitalWrite (pumpPin, LOW); //LOW signal turns relay on
          digitalWrite (ledPin, HIGH);
          lcd.setCursor(9,0);          //go to pump status line on LCD
          lcd.print("Pmp:On ");        //extra space clears "f" from "off" state.
    }
    else 
    {
        if ( ( (collT - stopDT) >= tankT) && (tankT < tankLimit) ) //if the dT is between stopDT and startDT, don't change anything
            {
            //do nothing (keep current pump state)
            }
            else
            {
              digitalWrite (pumpPin, HIGH); //turn the pump off (HIGH signal is off)
              digitalWrite (ledPin, LOW);
              lcd.setCursor(9,0);  //go to pump status line on LCD
              lcd.print("Pmp:Off");
             }           
    }
  
  delay(1000);
}


To rule out mechanical and electrical issues, have you tried the examples from the LiquidCrystal_I2C library? Did they work?

I recommend that you first run the I2C scanner to make sure that the communication between the Arduino and the LCD I2C module is ok.

And then run a basic example from the IDE's example library to make sure that data appears on the LCD screen.

Then tell us the result.

Yes Helo world does work !

I run the hello world from the LiquidCrystal_I2C library and it is working.

The constructor for the LiquidCrystal_I2C class only takes 3 arguments. You have too many, it shouldn't even compile.

Do you have 2 types of LCD in your project?

#include <LCD.h>
#include <LiquidCrystal_I2C.h>

This is the code that the guy suggested to use to check if the LCD is working, ( from the same guy ) When i try this there is no errors but nothing on the LCD.

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR    0x3F //here’s where you might need to change the address
#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
int n = 1;
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup()
{
lcd.begin (16,2); //here’s where you input the rows x lines of your LCD
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home ();     //move the cursor to home
lcd.print("Hello, world!");  //Here’s where the magic happens!
}
void loop()
{
}

No, only one

Post a link where you get the LCD I2C library.
This ( #include <LiquidCrystal_I2C.h> )

This is your code:

This is from the library example:

LiquidCrystal_I2C lcd(0x27,20,4);

Do you see the difference?

Also, don't use quotes for posting code!!! Use Code Tags.

I see the difference, Any suggestions how i can change the code?

posting in the forum or in the program. As i mentioned i`m a beginner.

Thanks for helping me

I installed if from the library of IDE.

Use this code at simulator:

This is the setup im looking for but i can`t get it going properly.

For those of you saying that the constructor and code for "LiquidCrystal_I2C" is incorrect, keep in mind that there are multiple libraries out there that have a LiquidCrystal_I2C class.
The header files and constructor for LiquidCrystal_I2C class and code API calls appear to be from fm's newLiquidCrystal library not the LiquidCrystal_I2C library available from the IDE library manager.

Because there are multiple libraries out there with a LiquidCrystal_I2C class, and they work differently and have different capabilities, it can be quite confusing.

The advantage of newLiquidCrystal LiquidCrystal_I2C is it works with any I2C backpack,
The disadvantage of the newLiquidCrystal is the pin mappings specified must match the backpack you have, if not, nothing works.
The advantage of LiquidCrystal_I2C LiquidCrystal_I2C is that it is simpler,
the disadvantage is it only works with 1 of the backpack designs and can not be configured.
If the backpack uses a different pin mapping than the library was hard coded for, it won't work unless code changes are made to match the backpack.

To add to the mix of confusion, there are multiple LiquidCrytsal_I2C libraries out there in addition to the one available in the IDE library manager.

Also, if you install both newLiquidCrystal and LiquidCrystal_I2C the IDE can get can get confused and can potentially not pull in the one you want depending on what other header files you include in your sketch.

At this point, neither the newLIquidCrystal nor the LiquidCrystal_I2C available in the IDE library manager are maintained.

In years past, I was involved with and worked on the code in both libraries.

Because of this confusion,
I created the hd44780 library make things simpler.

It is available in the IDE library manager and offers a plug an play experience as it can auto locate the I2C address and auto detect the pin mapping used between the PCF8574 chip and LCD pins.
i.e. it should "just work" without having to configure anything
The hd44780 library hd44780_I2Cexp i/o class also includes a diagnostic tool to verify the h/w and connections.

My suggestion would be to switch over to using the hd44780 library and the hd44780_I2Cexp i/o class.
The library has a wiki and even includes information about how to modify sketch code from other LCD libraries like newLiquidCrystal and LiquidCrystal_I2C to work with the hd44780_I2Cexp i/o class.

Before using the hd44780 library, I would highly recommended having
a read of the documentation which explains how the library is composed as it is different from other libraries.
Then have a look at the hd44780_I2Cexp i/o class as that is the one you will use for a i2c backpack based hd44780 LCD.
https://github.com/duinoWitchery/hd44780/wiki
https://github.com/duinoWitchery/hd44780/wiki/ioClass:-hd44780_I2Cexp

--- bill

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.