Serial.print to lcd.print

I really need help.. my problem is when i change serial.print to lcd.print the text is not displaying on lcd..


#include <DHT.h>
#include <SoftwareSerial.h>
#include <ArduinoJson.h>

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

//Initialise Arduino to NodeMCU (5=Rx & 6=Tx)
SoftwareSerial nodemcu(5, 6);

//Initialisation of DHT11 Sensor
#define DHTPIN 7
DHT dht(DHTPIN, DHT11);
float current;                                                                     
float voltage;  
float temp;
float hum;
int r;

void setup() {
  Serial.begin(9600);
  dht.begin();
  nodemcu.begin(9600);
  delay(1000);
  lcd.init();
  lcd.backlight();
}

void loop() {
  StaticJsonBuffer<1000> jsonBuffer;
  JsonObject& data = jsonBuffer.createObject();
  dht11_func();
  //Assign collected data to JSON Object
  data["humidity"] = hum;
  data["temperature"] = temp; 
  data["irradiance"] = r;
  data["voltage"] = voltage;
  data["current"] = current;
  //Send data to NodeMCU
  data.printTo(nodemcu);
  jsonBuffer.clear();
  delay(2000);
}


void dht11_func() {

  //lcd.print("Hello world");  -- displaying in lcd when i run it..

  int value = analogRead(A0); 
  const float vpp = 4.8828125;                                                                           
  value = value - 509.3;
  voltage = value*vpp;
  current = voltage/100;
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  r = analogRead(A1); 
   
   //lcd.print("Hello world");  -- Not displaying on lcd when i run it

  Serial.print("Humidity: ");
  Serial.println(hum);
  Serial.print("Temperature: ");
  Serial.println(temp);
  Serial.print("Irradiance: ");
  Serial.println(r);
  Serial.print("Voltage: ");
  Serial.println(voltage);
  Serial.print("Current: ");
  Serial.println(current);
  Serial.print("Current: ");
  Serial.println(current);
}



Sorry my English is not so good..

There is no way to help with just that program snippet.

Please post the entire program.

Please include a schematic showing the wiring.

Include photos that clearly show the wiring and solder joints on the LCD header.

Check out a DHT-11 tutorial:
Arduino - Temperature Humidity Sensor - LCD | Arduino Tutorial (arduinogetstarted.com)

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-temperature-humidity-sensor-lcd
 */

#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11

LiquidCrystal_I2C lcd(0x3F, 16, 2);  // I2C address 0x3F, 16 column and 2 rows
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  dht.begin();     // initialize the sensor
  lcd.init();      // initialize the lcd
  lcd.backlight(); // open the backlight 
}

void loop()
{
  delay(2000); // wait a few seconds between measurements

  float humi  = dht.readHumidity();    // read humidity
  float tempC = dht.readTemperature(); // read temperature

  lcd.clear();
  // check if any reads failed
  if (isnan(humi) || isnan(tempC)) {
    lcd.setCursor(0, 0);
    lcd.print("Failed");
  } else {
    lcd.setCursor(0, 0);  // start to print at the first row
    lcd.print("Temp: ");
    lcd.print(tempC);     // print the temperature
    lcd.print((char)223); // print ° character
    lcd.print("C");

    lcd.setCursor(0, 1);  // start to print at the second row
    lcd.print("Humi: ");
    lcd.print(humi);      // print the humidity
    lcd.print("%");
  }
}

If you are using a GLCD (ILI934x similar) the concept is still the same:

  • #include the display library
  • instantiate the display object
  • do any display settings required
  • call the display correctly
1 Like

i hope you can help me in .. void dht11_func()

there is no error on my code.. i just cannot display the text on the lcd
..

i hope you can help me in .. void dht11_func()

There must be if it is not working :thinking:

Did you verify the hardware using the "Hello World" (or similar) example from the LCD library?

there is no error...

When in times of trouble, reduce everything to just two items: your Arduino and your errant device; in your case the display. Then find a working example that uses your Arduino model & your LCD model.

Examples:

Uno + 1602 LCD
Arduino Uno + 1602 LCD + "example" at DuckDuckGo

Nano Every + ILI9241
Arduino "Nano Every" + ILI9341 LCD + "example" at DuckDuckGo

Limit everything to 2 components, do not change example code. Try more than 1 example if necessary.

There are no compilation errors. It could be rife with programming, logic, and other types of errors.

Let it Be

:nerd_face:

3 Likes

There are several libraries with the name LiquidCrystal_I2C. The are not all the same and code from 1 may not run in another. Those LiquidCrystal_I2C libraries are old and most are not maintained. The newest and best library for I2C LCD with the hd44780 controller (1602, 2004) is the hd44780 library by Bill Perry. The library is available via the IDE library manager.

For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.

To install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.

The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results. Also documentation in folder in the red box.

thank you so much guys for your answers... :slightly_smiling_face: i solved my problem Alhamdulillah..
i wil post this program soon..

1 Like

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