My LCD I2C doesnt show any text.. please help

Hi

I am trying to use a Ardouino Nano 3.0, a two line LCD display (using the I2C board) and a soil humidity sensor. The problem is that the display only highlights all the pixels in the first line… no “text” is displayed… Could anyone please take a look at my code?

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

int i;
int soilsensor = A0; //Soil sensor
int sensorValue = 0;

#define ONE_WIRE_BUS 7
#define I2C_ADDR 0x27
#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 ledred 2
#define ledgreen 3
#define ledblue 4
#define powerPin 7

//LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup() {

Serial.begin(9600);

pinMode(ledred, OUTPUT);
pinMode(ledgreen, OUTPUT);
pinMode(ledblue, OUTPUT);
pinMode(powerPin, OUTPUT);

lcd.begin(16, 2);

for(int i = 0; i< 3; i++){
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight();

lcd.setCursor(0, 0);
lcd.print(“Humidity”);

delay(1000);

Wire.begin();

//lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
//lcd.setBacklight(HIGH);

//lcd.home ();

}

void loop() {

digitalWrite(ledred, HIGH);
digitalWrite(ledblue, HIGH);
digitalWrite(powerPin, HIGH);

delay(30);

int soil = analogRead(powerPin);
soil = constrain(soil, 400, 1000); // We get the values between 400 and 1000, thats why we need to map the values
soil = map(soil, 400, 1000, 100, 0); // to make lower numbers a bigger percent, and to map them im range of 1 to 100.
lcd.setCursor(12, 0); // Set Curson to line 0, column 12
lcd.print(soil); // display final percentage
lcd.print("%"); // print the percent symbol at the end

}

Double check the i2C wiring connections, please see below...

Please try to reduce the frequency to the lowest possible value.

Wire.setclock(31000L);

That means 32kbit/s.

It must be called after the init() and can be set between slow mode (31kbit/s, 31000L) and full speed (400 kbit/s, 400000L). The standard is 100kbit/s.

I had similar problems, caused by to long wires on my breadbord and/or bad connections.

Use a proper constructor for the lcd, use lcd.init() not lcd.begin()

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

int i;
int soilsensor = A0;       //Soil sensor
int sensorValue = 0;

#define ONE_WIRE_BUS 7
#define I2C_ADDR 0x27
#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 ledred 2
#define ledgreen 3
#define ledblue 4
#define powerPin 7

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {

  Serial.begin(115200);

  pinMode(ledred, OUTPUT);
  pinMode(ledgreen, OUTPUT);
  pinMode(ledblue, OUTPUT);
  pinMode(powerPin, OUTPUT);

  lcd.init();

  for (int i = 0; i < 3; i++) {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Humidity");
  delay(1000);
}

void loop() {
  digitalWrite(ledred, HIGH);
  digitalWrite(ledblue, HIGH);
  digitalWrite(powerPin, HIGH);
  delay(30);
  int soil = analogRead(powerPin);
  soil = constrain(soil, 400, 1000);                                                   // We get the values between 400 and 1000, thats why we need to map the values
  soil = map(soil, 400, 1000, 100, 0);                                                 // to make lower numbers a bigger percent, and to map them im range of 1 to 100.
  lcd.setCursor(12, 0);                                                                // Set Curson to line 0, column 12
  lcd.print(soil);                                                                     // display final percentage
  lcd.print("%");                                                                      // print the percent symbol at the end
}

Be sure you turn the pot back and forth to set the contrast. They are often delivered so far off there is nothing showing.

Whandall:
Use a proper constructor for the lcd, use lcd.init() not lcd.begin()

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

int i;
int soilsensor = A0;      //Soil sensor
int sensorValue = 0;

#define ONE_WIRE_BUS 7
#define I2C_ADDR 0x27
#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 ledred 2
#define ledgreen 3
#define ledblue 4
#define powerPin 7

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {

Serial.begin(115200);

pinMode(ledred, OUTPUT);
  pinMode(ledgreen, OUTPUT);
  pinMode(ledblue, OUTPUT);
  pinMode(powerPin, OUTPUT);

lcd.init();

for (int i = 0; i < 3; i++) {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print(“Humidity”);
  delay(1000);
}

void loop() {
  digitalWrite(ledred, HIGH);
  digitalWrite(ledblue, HIGH);
  digitalWrite(powerPin, HIGH);
  delay(30);
  int soil = analogRead(powerPin);
  soil = constrain(soil, 400, 1000);                                                  // We get the values between 400 and 1000, thats why we need to map the values
  soil = map(soil, 400, 1000, 100, 0);                                                // to make lower numbers a bigger percent, and to map them im range of 1 to 100.
  lcd.setCursor(12, 0);                                                                // Set Curson to line 0, column 12
  lcd.print(soil);                                                                    // display final percentage
  lcd.print("%");                                                                      // print the percent symbol at the end
}

Thanks… I tried your code, but the lcd.init should be lcd.int, right?
Also when I try to compile the code I get “expected unqualified-id before ‘int’” at the “lcd.init” / “lcd.int” part…

No. the code works as posted.

If you change other things, you can generate other errors.

Try this sample code :

/*IIC LCD 16X2 test example
 * Connect the IIC LCD as follows
 * IIC LCD      ARDUINO
 * +5V            +5V
 * GND            GND
 * SCL            SCL
 * SDA            SDA
 * 
 * by Malhar Deshmukh
 * 11APR2016
 */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR    0x27 // <<-- Add your address here.Find it from I2C Scanner
#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
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); //  LCD is 16 characters x 2 lines
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);  // Switch on the backlight
  lcd.home();
  lcd.write("1");
}

void loop() {
  for (int i = 0; i <= 10; i++) {
    if (i == 10) {
      i = 0;
    }
    lcd.home();
    lcd.print(i);//lcd.print("hh");
    delay(500);

  }
}

-Malhar

Whandall:
No. the code works as posted.

If you change other things, you can generate other errors.

Post error messages, not partial pictures of them.

Use the "Kopier . . . " control, it's what it is there for.

The code I am using

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

const byte SoilSensorPin = A0;
const byte powerPin = 7;

const byte I2CAddr = 0x27;

LiquidCrystal_I2C lcd(I2CAddr, 16, 2);

void setup() {
  pinMode(powerPin, OUTPUT);

  lcd.init();
  lcd.setCursor(0, 0);
  lcd.print(F("starting"));

  for (int i = 0; i < 3; i++) {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print(F("Humidity"));
}

const unsigned long MeasurementInterval = 2000;
const unsigned long PowerOnTime = 30;
bool measure = false;
unsigned long topLoop;
unsigned long lastMeasurement;
bool backOn = false;
byte offCyc = 2;

void loop() {
  topLoop = millis();
  if (measure) {
    if (topLoop - lastMeasurement > PowerOnTime) {
      byte humPercent = humidityPercent(analogRead(SoilSensorPin));
      digitalWrite(powerPin, LOW);
      printPercentAt(12, 0, humPercent);
      measure = false;
    }
  } else if (topLoop - lastMeasurement > MeasurementInterval) {
    measure = true;
    lastMeasurement = topLoop;
    digitalWrite(powerPin, HIGH);
  }
}

void printPercentAt(byte col, byte row, byte percent) {
  lcd.setCursor(col, row);
  if (percent < 100) {
    lcd.print(' ');
  }
  if (percent < 10) {
    lcd.print(' ');
  }
  lcd.print(percent);
  lcd.print('%');
}

byte humidityPercent(int anaVal) {
  int value = constrain(anaVal, 400, 1000);
  return map(value, 400, 1000, 100, 0);
}
Der Sketch verwendet 4.440 Bytes (14%) des Programmspeicherplatzes. Das Maximum sind 30.720 Bytes.
Globale Variablen verwenden 260 Bytes (12%) des dynamischen Speichers, 1.788 Bytes für lokale Variablen verbleiben. Das Maximum sind 2.048 Bytes.


Your screenshot shows that you did not change the constructur.

Whandall:
The code I am using

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

const byte SoilSensorPin = A0;
const byte powerPin = 7;

const byte I2CAddr = 0x27;

LiquidCrystal_I2C lcd(I2CAddr, 16, 2);

void setup() {
  pinMode(powerPin, OUTPUT);

lcd.init();
  lcd.setCursor(0, 0);
  lcd.print(F(“starting”));

for (int i = 0; i < 3; i++) {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print(F(“Humidity”));
}

const unsigned long MeasurementInterval = 2000;
const unsigned long PowerOnTime = 30;
bool measure = false;
unsigned long topLoop;
unsigned long lastMeasurement;
bool backOn = false;
byte offCyc = 2;

void loop() {
  topLoop = millis();
  if (measure) {
    if (topLoop - lastMeasurement > PowerOnTime) {
      byte humPercent = humidityPercent(analogRead(SoilSensorPin));
      digitalWrite(powerPin, LOW);
      printPercentAt(12, 0, humPercent);
      measure = false;
    }
  } else if (topLoop - lastMeasurement > MeasurementInterval) {
    measure = true;
    lastMeasurement = topLoop;
    digitalWrite(powerPin, HIGH);
  }
}

void printPercentAt(byte col, byte row, byte percent) {
  lcd.setCursor(col, row);
  if (percent < 100) {
    lcd.print(’ ‘);
  }
  if (percent < 10) {
    lcd.print(’ ‘);
  }
  lcd.print(percent);
  lcd.print(’%’);
}

byte humidityPercent(int anaVal) {
  int value = constrain(anaVal, 400, 1000);
  return map(value, 400, 1000, 100, 0);
}





Der Sketch verwendet 4.440 Bytes (14%) des Programmspeicherplatzes. Das Maximum sind 30.720 Bytes.
Globale Variablen verwenden 260 Bytes (12%) des dynamischen Speichers, 1.788 Bytes für lokale Variablen verbleiben. Das Maximum sind 2.048 Bytes.



![|500x271](http://img.image-storage.com/2600012101/a9688e70d12d4.jpg)
Your screenshot shows that you did **not** change the constructur.

Thanks… when I try your code I get this error message:

Arduino:1.6.7 (Windows 10), Kort"Arduino Nano, ATmega328"

sketch_apr11a:9: error: invalid conversion from ‘int’ to ‘t_backlighPol’ [-fpermissive]

LiquidCrystal_I2C lcd(I2CAddr, 16, 2);

^

In file included from C:\Users\Hans-Magnus\Documents\Arduino\sketch_apr11a\sketch_apr11a.ino:1:0:

C:\Users\Hans-Magnus\Documents\Arduino\libraries\NewliquidCrystal/LiquidCrystal_I2C.h:53:4: error: initializing argument 3 of ‘LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, t_backlighPol)’ [-fpermissive]

LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol);

^

C:\Users\Hans-Magnus\Documents\Arduino\libraries\NewliquidCrystal/LiquidCrystal_I2C.h: In function ‘void setup()’:

C:\Users\Hans-Magnus\Documents\Arduino\libraries\NewliquidCrystal/LiquidCrystal_I2C.h:154:9: error: ‘int LiquidCrystal_I2C::init()’ is private

int init();

^

sketch_apr11a:14: error: within this context

lcd.init();

^

exit status 1
invalid conversion from ‘int’ to ‘t_backlighPol’ [-fpermissive]

Denne rapporten vil inkludere mer informasjon med
“Vis detaljert informasjon under kompilering”
skrudd på i Fil > Innstillnger

My code works now btw, but the humidity is at 100% all the time.. Do I need to calibrate the sensor then?
Im sorry, but this arduino programming is new to me

So you are using a different libraryC:\Users\Hans-Magnus\Documents\Arduino\libraries\NewliquidCrystal/LiquidCrystal_I2C.h
I use

D:\Work\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.h

I think I got it from DFRobot.com, I attach it if you want to try.

LiquidI2c.zip (19.8 KB)

Whandall:
So you are using a different libraryC:\Users\Hans-Magnus\Documents\Arduino\libraries\NewliquidCrystal/LiquidCrystal_I2C.h
I use

D:\Work\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.h

I think I got it from DFRobot.com, I attach it if you want to try.

Thanks, I tried to change the libray, but now I get this error code:

"sketch_apr10a:25: error: 'POSITIVE' was not declared in this scope

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);"

Again (for the third time): you have to use a suitable constructor.

LiquidCrystal_I2C lcd(0x27, 16, 2);

Whandall:
Again (for the third time): you have to use a suitable constructor.

LiquidCrystal_I2C lcd(0x27, 16, 2);

Oh… I didnt get that part…
Thanks, the code works, but the screen only says “H” and “1%”

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

int i;
int soilsensor = A0;       //Soil sensor
int sensorValue = 0;

#define ONE_WIRE_BUS 7
#define I2C_ADDR 0x27
#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 ledred 2
#define ledgreen 3
#define ledblue 4
#define powerPin 7

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {

  Serial.begin(115200);

  pinMode(ledred, OUTPUT);
  pinMode(ledgreen, OUTPUT);
  pinMode(ledblue, OUTPUT);
  pinMode(powerPin, OUTPUT);

lcd.init();

  for (int i = 0; i < 3; i++) {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Humidity");
  delay(1000);
}

void loop() {
  digitalWrite(ledred, HIGH);
  digitalWrite(ledblue, HIGH);
  digitalWrite(powerPin, HIGH);
  delay(30);
  int soil = analogRead(powerPin);
  soil = constrain(soil, 400, 1000);                                                   // We get the values between 400 and 1000, thats why we need to map the values
  soil = map(soil, 400, 1000, 100, 0);                                                 // to make lower numbers a bigger percent, and to map them im range of 1 to 100.
  lcd.setCursor(12, 0);                                                                // Set Curson to line 0, column 12
  lcd.print(soil);                                                                     // display final percentage
  lcd.print("%");                                                                      // print the percent symbol at the end
}

Confused. Is your sensor supposed to be on pin A0 (soilsensor), or pin 7 (powerPin)?, or A7 (where analogRead will go when given pin 7)? WTH.

analogRead should read from soilSensor, the powerPin should probably be switched on a couple of microseconds before the measurement and switched off after the measurement. I implemented this in my version.

The above explains the "1%" but not the isolated "H". :frowning:

The above explains the "1%" but not the isolated "H".

I believe that both these problems are caused by a problem with the lcd library you are using and the IDE version. Please read this thread http://forum.arduino.cc/index.php?topic=361411.0

Do a forum search on "i2c lcd prints single character" for other postings on the same issue.