Problem with Nano and LiquidCrystal_I2C.h

Hi,
I have a project made with an ETH module, Nomemcu 1.0 (ESP 12-E) module, LCD I2C module all connected to a Nano.
I included:

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

ESP and LCD are connected by I2C in parallel.
The LCD to works well but the ESP not, If I remove LCD libray form sketch ESP restart to work.
I try to connect I2C with pullup resistor and without it but nothing change.

I have to looking for software or hardware connections problems?

Could you post the full sketch which is running on the ESP? Also the connection circuit if possible, please. Otherwise nobody will be able to help you...

And welcome to the forum!

Try NodeMCU as I2C-Master; NANO and LCD as slaves.

Thanks for reply,
the purpose of the project is to send the data detected by some arduino ports to a computer where a program written in C # listens on the IP address set on the Ethernet module or on the ESP in order to choose which type of connection to use. The sketch installed in the ESP module takes care of receiving the commands from the computer, requesting the door data from the Arduino and sending them back to the computer via html. if I choose to use the ethernet connection instead, the html page with the data is generated and sent by the Arduino.
Everything works fine until I load the libraries of the LCD module, then the ESP module stops communicating. I connected the I2C channels in parallel as I have seen on the net.
I am attaching an image of the connections on the breadboard ( hope without error).

and the init part of Arduino sketch (shrinked)

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

String request ;
int LastChar = 0;
unsigned long refreshCounter  = 0;
String PingOk;
int IpPort = 80;
String DatiRx = "";

EthernetServer server(IpPort);

LiquidCrystal_I2C lcd(0x3F, 16, 2);// set the LCD address to 0x27 for a 16 chars and 2 line display

// WIFI
int portSlaveI2C = 8;

String AnaValue = "";
String DigValue = "";
String PortValue = "";
// *****

// ***********************
int sReadInAnalog[] = {14, 15, 16};
int sReadInDigit[] = {3, 4, 5, 6};
// ***********************

// ********************
int Channel = 103; //
// ********************
byte mac [6] = {0, 0, 192, 168, 1, Channel};
String LocalIP = "192.168.1." + String(Channel); // indirizzo della scheda locale

bool LANVersion;

// ********************************
void setup() {
  // *************************
  // HIGH=LAN, LOW=WIFI
  LANVersion = digitalRead(3);
  // *************************

  Serial.begin(115200);

  Serial.println(F(__FILE__ " " __DATE__ " " __TIME__));
  Serial.print(F("IP:"));
  Serial.println(LocalIP);
  Serial.println(F("Start"));

  Serial.println(LANVersion);

  lcd.init();                      // initialize the lcd
  lcd.init();
  lcd.backlight();

  if (LANVersion) {
    // ***************
    // LAN
    // ***************
    Serial.println("ETHERNET VERSION");

    lcd.setCursor(0, 0);
    lcd.print("ETHERNET VERSION");

    IPAddress ip(192, 168, 1, Channel);
    IPAddress gateway(192, 168, 1, 1);
    IPAddress subnet(192, 168, 1, 1);

    //Init W5100
    Ethernet.init(10);
    Ethernet.begin(mac, ip);

    while (!Ethernet.begin(mac)) {
      Serial.println(F("Error. Retry in 5 seconds."));
      delay(5000);
      Serial.print(F("Start W5100 card..."));
    }

    server.begin();

    Serial.println(F("W5100 inizialized"));
    Serial.print(F("IP address: "));

    Ethernet.setLocalIP(ip);
    Serial.println(Ethernet.localIP());

  } else {
    // ***************
    // WIFI
    // ***************
    lcd.setCursor(0, 0);
    lcd.print("WIFI VERSION");

    Serial.println("WIFI VERSION");
    Wire.begin(portSlaveI2C);     // >=8
    Wire.onReceive(CommandReceive); // register receive event
    Wire.onRequest(DataRequest); // register request event
    Serial.println(F("I2C Inizialized"));
  }



  lcd.setCursor(0, 1);
  lcd.print("IP:" + LocalIP);

  pinMode(3, INPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, INPUT);

  pinMode(14, INPUT);
  pinMode(15, INPUT);
  pinMode(16, INPUT);

  delay(1000);  //5000
}

// ********************************
void loop() {

  if (LANVersion) {
    EthernetClient client = server.available();

    if (client) {
      String DataParam = "";
      // an http request ends with a blank line
      boolean currentLineIsBlank = true;

      // reading Arduino port
      String PortValue = PrepareValuesString();
      char c;

      while (client.connected()) {
        if (client.available()) {

          while (client.available()) {
            c = client.read();
            Serial.write(c);
            DataParam += c;

            if (c == '\n') break;
          }

          // remove 'HTTP'
          DataParam.remove(DataParam.indexOf("HTTP"), 8);

          int PosData;
          int nPort;
          int nAction;
          String sPort;
          String sAction;

          // receive command port
          if ((PosData = DataParam.indexOf("/dig")) > 0) { // received digital door command digDnn = 0/1
            // extracts the data of the Channel and on / off
            sPort = DataParam.substring( PosData + 6 , PosData + 8);
            sAction = DataParam.substring( PosData + 9, PosData + 10);

            nPort = sPort.toInt();
            nAction = sAction.toInt();

            // send arduino port command
            digitalWrite(nPort, nAction);

          } else if ((PosData = DataParam.indexOf("/ana")) > 0) { // analog port command received anaAnn = nnnn
            sPort = DataParam.substring( PosData + 6, PosData + 8);
            sAction = DataParam.substring( PosData + 9);

            nPort = sPort.toInt();
            nAction = sAction.toInt();

            // send arduino port command
            analogWrite(nPort, nAction);
          }

          Serial.print(F("Port:")); Serial.println(nPort);
          Serial.print(F("Action:")); Serial.println(nAction);

          DataParam = "";
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");

          // send port values
          client.println(PortValue);

          client.println("</html>");
          break;
        }
      }
      // give the web browser time to receive the data
      delay(1);
      // close the connection:
      client.stop();
      Serial.println("client disconnected");
    }
  }

  delay(100);
}

Thanks in advance.

Thanks for your reply, ill try to prepare more detailed documents.

The ESP is 3v.
If you want to connect the ESP to 5v I2C devices you should use a level shifter.

--- bill

I've just needed some time to understand the theoretical part of your project. So what you want to do, is like this graphic, isn't it?


And now, a few questions:

  1. Why are you doing it so complicated? Why is it necessary to detect the data with the Arduino? Why not with the ESP?
  2. What exactly does the C#-program on the computer? Isn't it possible to do the work on the Arduino or on the ESP?
  3. How is the Arduino communication with the ESP? Serial communication?
  4. Can't you get rid of the C#-program on the computer and/or of the Arduino? Why not?

Your description seems very complicated from my point of view. From your wiring diagram, I see, that the ESP, the Arduino and the LCD Display are connected at the same ports. Maybe displaying the data at the LCD fails because you confuse the 3 components.

Always the most critical question. :+1:

Using two microcontrollers just makes the communication difficult, simplifies nothing and of course the ESP is by far the more capable.

I don't want to waste anyone's time,
my first question was if anyone knew some possible problems between the LiquidCrystal_I2C.h, Ethernet.h and Wire.h libraries and if my I2C hardware connection was correct.
The aim of the project is to build a black box, from 20 to 50, connectable via WiFi or Lan capable of sending / receiving commands to / from a remote computer for set some ports and monitor their status.
I use a nano to limit the size of the hardware, but the memory is not enough, so I have tried Nano each but it seems incompatible with the Lcd library, so now I am trying ESP8266 12-E NodeMCU to eliminate Arduino and have ESP built in.
I will send the working solution as soon as I find it.

Thanks to everybody

You wont waste our time, don't worry! Can I give you an idea, maybe an impulse?

If you just want to control the status of some ports, display them at the lcd display and monitor them via html, I would do the following:
Only use one ESP8266. Connect your components which you want to control to the ports of the ESP. Now connect the lcd display and display the status at the display. At the same time, you build a webserver (example) and display the status of your components on the webserver. Then, you can access the data with your computer by going to the ip-adress of the ESP. If you want to access from all over the world, you can also connect the ESP with a DynDNS service. But, always step-by-step...

Happy Programming!

You are saying exactly what i am trying to do, apart managing both wifi and ethernet connections in the same box switching with a switch.

Thanks

regards

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