How to display the results on the LCD I2C

Can I ask how to display the results on the LCD I2C? I tested my circuit and code with the serial monitor and it worked fine and got what I wanted with text in the serial monitor, but when I use and replace the serial.print into lcd.print with the LCD I2C nothing appeared. I connected the SDA and SCL of the LCD I2C to the corresponding pins of Arduino Uno.

I'm doing a project on programming ESP-01s with Arduino Uno required by my teacher.



#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <stdlib.h>
#include <ESP8266WiFi.h>        // Include the Wi-Fi library
#include <ESP8266Ping.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(6, 7); // RX, TX


const char* ssid     = "Slapsoil";         // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "polkapol01";     // The password of the Wi-Fi network


int i=15; //15 secs for checking
int sec=1000; //interval second
int x=0;
const int relayPin = 13;
void setup() {
  Serial.begin(115200);
  //mySerial.begin(115200);
  digitalWrite(relayPin, 1);
  lcd.init();
  lcd.clear();
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.println("Open Loop           ");
  lcd.setCursor(2,1);
  lcd.println("Socket is OFF           ");
  pinMode(relayPin, 13);
  delay(5000); //15 secs off
  connecting();
  delay(10000);
}

void loop() {
  digitalWrite(relayPin, 0);
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.println("Socket is ON                              ");
  lcd.setCursor(3,1);
  lcd.print("sec. left:       ");
  for(x=0; x<=i; i--){
  lcd.setCursor(4, 1);
  lcd.setCursor(14, 1);
  lcd.println(i);
  delay(sec);
  }
  bool success = Ping.ping("www.google.com", 3);
  if(!success){
    lcd.clear();
    lcd.println("Ping failed");
    return;
    delay(5000);
  }
  lcd.clear();
  lcd.println("Ping succesful.");
  delay(5000);
  i = i+15;
  }


void connecting() {
  lcd.clear(); 
  delay(1000);
  lcd.print("Connecting to WiFi");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

  delay(2000);
  lcd.print(".");

    }
    lcd.clear(); 
    lcd.println("Wifi Status ");
    lcd.println("CONNECTED ");
}

Try Wire.begin() early in setup(). What voltage are you using to power the LCD ?

...5V lcd and relay. 3.3V for ESP-01s

If this did not help, load an I2C scanner sketch and see if it can find the LCD (backpack) at the address you have specified (0x27)

Yes, I did the scanning and it is (0x27), also included the Wire.begin();. The LCD has a backlight only, no text at all. I already tested the LCD on just printing text through Arduino Uno and it works fine. But in the Generic ESP8266 board or through my posted code nothing appeared.

Hi,
What do you call "Generic ESP8266 "?
In which pins of the Generic ESP8266 are you connecting the I2C of the LCD?

It is the board for ESP-01s to communicate with Arduino Uno. I connected the LCD I2C and Relay to the Arduino Uno and nothing happened to them. For the pins of ESP-01s, GPI0 is used for programming mode and the only available is GPI02.

Here is a project which claims to interface I2C devices to an ESP-01. Interfacing ESP8266 ESP-01 module with I2C LCD - Simple Projects However, I have some difficulty understanding what tasks are going to run on your ESP-01 and what are intended to run on the Uno. Are you intending to (somehow) connect these two devices together ?
Incidentally, the pullup resistors, on your I2C backpack of the LCD, will be connected to +5v and not +3.3 volts. This may cause a problem if you are connecting the LCD to the ESP-01.

Though I posted it as Arduino Uno but we are required to use Atmega 328p, this is my circuit diagram.

JP1 I2C is for my LCD I2C

I got the Open Loop, but Closed Loop I'm struggling.

It sounds like the "closed loop" controls the power socket connected to the relay and something like an internet router is plugged into it. The idea being that the ESP detects a loss of internet connectivity and forces a power cycle of the router (or whatever is plugged in to it).
What part are you having difficulty with ? It appears to be simple timing using millis() and your code appears already to have the ping command in it. You'll have to develop a simple protocol over the serial link, though, so the ATmega328P can query the status of the internet connection via the ESP-01.

EDIT
You should have some basic level shifting between the TX/RX of the ESP-01 and the ATmega328P which you are apparently running at 5volts. Look at the schematic of the Adafruit Huzzah breakout (not Feather) to see a simple approach. You should cross over RX and TX between the two devices.

EDIT 2
The base resistor of the transistor seems to have a very high value. Something like 1k would be better. Also the indicator led looks odd and will come on to show the relay is off. Maybe control it directly with the pin PB5 and increase the resistor to 330 ohms.

I can't speak about the actual project as the descriptions you have provided (and been provided) seem to be so incomplete that it is simply not possible to create a project.
i.e.

I'm doing a project on programming ESP-01s with Arduino Uno required by my teacher.

And the

"Create a system wherein" image of A) to D) list of "requirements"

Are simply missing too much information to be able to even write up a high level description of the project much less be able to define the h/w and user interfaces needed to be able to start coming up with the design, all of which must be done before any code is written.
i.e. I'm a FIRM believer that things should be defined and then designed before any code is written.

My first questions would be why are multiple processors mentioned? i.e. why even use the UNO?, but then this goes back to having such incomplete requirements.

However, in terms of getting an LCD backpack working with an ESP part I can comment on.
I would HIGHLY discourage hooking up a 3v master (ESP) to a 5v signals.
This includes a 5v i2c bus as you are doing.
It can damage the ESP since you are connecting 5v signals to 3v inputs.
When using i2c with a 3v master and 5v slaves on a common bus you really need a level shifter to ensure each device is using the proper voltage levels.
I ALWAYS use a level shifter when hooking ESP parts to any 5v signals. This includes a 5v i2c bus.
There is a way to cheat with i2c signals if you run the i2c bus at 3v even through the slave is 5v. It will be out of spec for the 5v slave but it typically works (at least at typical voltage and temperature conditions). When using a PCF8574 based i2c backpack the backpack typically has the pullups on it which are pulling up the signals to 5v.
To cheat and run the bus at 3v you must remove those by cutting traces on the PCB. Then add pullups to 3v on the bus. This will run the i2c bus at 3v.
Just remember that while this can and typically does work, it is out of spec for the 5v devices so it can potentially have some issues.

In terms of getting the ESP talking to the LCD, I would recommend using the hd44780 library. For a PCF8574 based backpack you will use the hd44780_I2Cexp i/o class. It can auto configure itself.
It includes a diagnostic sketch, I2CexpDiag, that can test the h/w and report any issues that it can detect.
After you install the hd44780 library, the first thing you should do is to run the included diagnostic sketch. The library includes many examples for each i/o class.
Look at the ones for the hd44780_I2Cexp i/o class.
The hd44780 library is available in the IDE library manager so you can install it directly from the library GUI with no messing with downloads or zip files.
Here is link to the hd44780 wiki and the hd44780_I2Cexp wiki:

--- bill

I am assuming from your code that you have a 16 x 4 lcd and to the setCursor function you have, in this case 0; 1; 2; 3. So let's say you want to print something on the second row.

lcd.setCursor(0, 1);
lcd.print("Hello");

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