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.