Impossible(?) to use wire.h (i2C) with ethernet shield NANO

Hi everyone.
I’m trying to use NANO Ethernet shield to create webserver to put data sensor (temperature and humidity) through the Internet. Classical project .
I successuflly wrote code to controle i2C HIC sensor (using i2c with Wire.h) and successfully write another code to create webserver (UIPEthernet.h + Webserver.ino example from Ethernet library).

To sum up :
Hardware used :
Arduino Nano + Ethernet Shield (with ENC28J60) + HIC i2c sensor + 5V external supply + RJ45 from pc to shield.

Software IDE 1.8.13
Librairies : Wire.h (for sensor) + UIPEthernet.h + SPI.h
The .ino for shield is extremely simple since I changed only 2 code lines from Webserver.h example :

  1. #include <Ethernet.h> to <UIPEthernet.h>
  2. my IP adress.

So, first code for sensor uses Wire.h
Second code for Ethenet Shield uses UIPEthenet.h and SPI.h
Next step is combining sensor.ino with Webserver.ino.

  1. Firstly when I try to just add Wire.h in Webserver.ino code then problems began.
    Code compiled with memory warning.
    “Low memory available, reliability problems may occured”.

Program : 19376 Bytes (63%)
Global Variables : 1622 Bytes (79%)

Anyway, I decide to run code (Webserver.ino with Wire.h).
No problem…

  1. I continued to combine sensor.ino code with Webserver.ino code.
    Still warning during compilation but…
    Impossible to get information from sensor.
    It seems to not communicate with i2C bus.
    I found that program does not execute a certain while loop that normally read byte from sensor.
while (Wire.available()) { // Read Byte from sensor...

So does this confirms i2C problem? I think so.

I read in the forum some kind of problem especially with I2C LCD displays using Ethernet Shield.

Does anyone could help me to solve the problem or bypass it ?

Today, I’ll try to measure electrical signal from I2C SCL and SDA with scope to confirm no I2C communication with sensor.
here is finale code that I would like de run.
Thank you very much
Nice day
Vince.

#include <SPI.h>
#include <UIPEthernet.h>
#include <Wire.h>
#define HIH6020 0x27 // Sensor I2C address


byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 7);
EthernetServer server(80);

//============= Sensor  Global Variables =============
byte   CurrentSensorResponseByte = 0;
byte   SensorResponseBytes[] = { 0,0,0,0 };
float  Humidity = 1;
float  Temperature = 1;
//====================================================
void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
  //Ethernet.init(10);  // Most Arduino shields
  //Ethernet.init(5);   // MKR ETH shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet

  Serial.begin(9600);
  while (!Serial) {
    ; 
  }
  Serial.println("Ethernet WebServer Example");
  Ethernet.begin(mac, ip);
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
      
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    Serial.println("Here are Temperature and Humidity");
    //==== Serial Print Temp and Humidity =====
      ReadSensor(&Humidity, &Temperature, SensorResponseBytes);      
      Serial.print("Temperature : ");
      Serial.print(Temperature);
      Serial.println("°C");
      Serial.print("Humidity    : ");
      Serial.print(Humidity);
      Serial.println(" %\n ");
      delay(100);
 //==========================================
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // 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>");
          
 //=============== output the value of sensor===========
          client.print("Temperature : ");
          client.println(Temperature);
          client.print(" C 
");
          client.print("Humidity : ");
          client.println(Humidity);
          client.print(" % <b>");
          client.println("</html>");
          break;
//=======================================================         
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

//=================== Read i2c sensor =======================
void ReadSensor(float *Humidity, float *Temperature, byte SensorResponseBytes[]) {
   // Here is I2C communication with sensor   
   Wire.beginTransmission(HIH6020); 
   delay(100);
   Wire.write("MR");           
   delay(100);        
   Wire.write("DF");               
   delay(100);
   Wire.requestFrom(HIH6020, 4, 1); 
   delay(100);
   Wire.endTransmission();    
   delay(100);

// While sensor is answering from I2C then read his byte...
// Next "if" are for calculating humidity and temperature from binary byte values.
// Last operation are for sensor calibration (see datasheet of HIC sensor)
   while (Wire.available()) { // Read Byte from sensor...
     for (int i = 0; i < 4; i++) {
       CurrentSensorResponseByte = Wire.read();//...Read Byte from sensor
       if (i == 0) {
         SensorResponseBytes[i] = CurrentSensorResponseByte & 0b00111111;
       }
       if (i == 1) {
         SensorResponseBytes[i] = CurrentSensorResponseByte;
       }
       if (i == 2) {
         SensorResponseBytes[i] = CurrentSensorResponseByte;
       }
       if (i == 3) {
         SensorResponseBytes[i] = CurrentSensorResponseByte >> 2;
       }
     }
     *Humidity = (float)(SensorResponseBytes[0] * 256 + SensorResponseBytes[1]);
     *Humidity = *Humidity / 163.82;
     *Temperature = (float)(SensorResponseBytes[2] * 64 + SensorResponseBytes[3]);
     *Temperature = (*Temperature) / 16382;
     *Temperature = (*Temperature - 0.2686) / 0.00510;
   }
 }

Here is code result :
On server @IP :
Temperature : 1.00 C
Humidity : 1.00 %

On serial bus:

new client
Here are Temperature and Humidity
Temperature : 1.00°C
Humidity : 1.00 %

Thank again to everybody trying to fix my problem.

there is no overlap between I2c and SPI and the two libraries on Nano.

reduce the dynamic memory consumption by using the F macro

where is Wire.begin()?