user30063: I am having some trouble connecting my 2 Arduino Nanos with I2C. I have this configuration:

SLAVE RECEIVER Nano with DS1037 and LCD 16x02 on I2C.
MASTER SENDER Nano.

After some time the Slave receiver prints on LCD random chars. If I delete the line including library RTCLIB.h everything is working except the clock. Thanks for your help :D
Slave receiver code:

#include <Wire.h> // include la libreria
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"

LiquidCrystal_I2C lcd(0x3E, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
RTC_DS1307 RTC; // orologio

static int anno;
static int giorno;
static int mese;
static int ora;
static int secondo;
static int oldSecondo;
static int minuto;
static int oldMinuto;
static int annoGrezzo;

//------------------------------------------------------------
// si ripete la union esattamente come nel master
union Scomp_float {
  // si utilizza union x float
  float temp;
  char byte_s[4];
} S_float;

//------------------------------------------------------------
// si ripete la union esattamente come nel master
union Scomp_long {
  // si utilizza union x long
  long int mioL;
  char byte_sL[4];
} S_long;

//------------------------------------------------------------
//------------- byte temporanei
byte f0 = 0;   // contengono i byte ricevuti
byte f1 = 0;
byte f2 = 0;
byte f3 = 0;
byte a1 = 0;
//-------------------------------------------------------------
//  qui si introdurranno i dati ricomposti dopo la trasmissione
long int masterLong = 0;
float masterFloat = 0;
int masterInt = 0;
//--------------------------------------------------------------

void setup() {
  Wire.begin(80);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  lcd.begin(16, 2);
  Serial.begin(9600);           // start serial for output
  //-----------orologio-----------
  RTC.begin();
  // Check to see if the RTC is keeping time.  If it is, load the time from your computer.
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // This will reflect the time that your sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  //-----------fine orologio-----------
}

void loop() {
  //------------------------------------------------------------
  //   si stampano i dati ricevuti e ricomposti
  //------------------------------------------------------------
  Serial.println(masterInt);
  Serial.println(masterLong);
  Serial.println(masterFloat);
  DateTime now = RTC.now();
  annoGrezzo = now.year();
  anno = ( annoGrezzo % 100);
  mese = now.month();
  giorno = now.day();
  ora = now.hour();
  minuto = now.minute();
  lcd.setCursor(0, 0);
  lcd.print(masterInt);
  lcd.setCursor(0, 1);
  lcd.print(giorno);
  lcd.print(" ");
  lcd.print(mese);
  lcd.print(" ");
  lcd.print(anno);
  lcd.print("  ");
  lcd.print(ora);
  lcd.print(":");
  lcd.print(minuto);
  delay (1000);
  lcd.clear();
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  if (howMany == 2) {
    // se in arrivo due dati
    f0 = Wire.read(); // si leggono i byte
    f1 = Wire.read();
    masterInt =  ((f1 << 8) | f0); // si ricompone l'intero
  }

  if (howMany == 4) {
    // se in arrivo 4 dati è un float
    f0 = Wire.read();  // si leggono i byte
    f1 = Wire.read();
    f2 = Wire.read();
    f3 = Wire.read();
    S_float.byte_s[0] = f0; // si ricompone il float
    S_float.byte_s[1] = f1;
    S_float.byte_s[2] = f2;
    S_float.byte_s[3] = f3;
    masterFloat = S_float.temp;
  }

  if (howMany == 5) {
    // se in arrivo 5 dati è un long
    f0 = Wire.read();  // si leggono i byte
    f1 = Wire.read();
    f2 = Wire.read();
    f3 = Wire.read();
    a1 = Wire.read();
    S_long.byte_sL[0] = f0;  // si ricompone  il long
    S_long.byte_sL[1] = f1;
    S_long.byte_sL[2] = f2;
    S_long.byte_sL[3] = f3;
    masterLong = S_long.mioL;
  }
}

Master sender code:
#include <Wire.h> // si include la libreria
//---------------------------------------------------------
union Scomp_float {
 // si utilizza union x float
  float temp;
  char byte_s[4];
} S_float;
//---------------------------------------------------------
union Scomp_long {
 // si utilizza union x long
  long int mioL;
  char byte_sL[4];
} S_long;
//----------------------------------------------------------
// questi sono i dati che si vogliono trasmettere

long int mioLong = 1234567801;
float mioFlo = 123456.29;
//----------------------------------------------------------
byte a1 = 0; // conterrà i primo byte dell'int
byte a2 = 0; // conterrà il secondo byte dell'int
byte f0 = 0; // contengono i byte del float e del long
byte f1 = 0;
byte f2 = 0;
byte f3 = 0;
void setup() {
  Wire.begin(); // join i2c bus (address optional for master)
}

void loop() {
  int mioInt = random(30000);
 //-----------------------------------------------------
 // trasmissione di un intero ( 2 byte)
 //-----------------------------------------------------
  a1 = byte(mioInt); // si scompone l'intero in 2 byte
  a2 = byte( mioInt >> 8);
  Wire.beginTransmission(80); // inzia trasmissione allo slave

  Wire.write(a1); //  invia un byte
  Wire.write(a2); //  invia il secondo byte
  Wire.endTransmission(); // stop transmitting
 //------------------------------------------------------
  delay (2000);
 //------------------------------------------------------
 // trasmissione intero lungo 4 byte
 //------------------------------------------------------
  S_long.mioL = mioLong; // si scompone in 4 byte
  f0 = S_long.byte_sL[0];
  f1 = S_long.byte_sL[1];
  f2 = S_long.byte_sL[2];
  f3 = S_long.byte_sL[3];
  a1 = 1; // si trasmette questo byte solo per segnalare allo slave
 // che stiamo trasmettendo un long
 // una volta scomposto si trasmettono i 4 byte
  Wire.beginTransmission(80); // trasmette allo slave
  Wire.write(f0); // invia un byte
  Wire.write(f1); //
  Wire.write(f2); //
  Wire.write(f3); //  invia un byte
  Wire.write(a1);
  Wire.endTransmission(); // fine trasmissione
 //-------------------------------------------------------
  delay (2000);
 //------------------------------------------------------
 //   trasmissione di un float 4 byte
 //------------------------------------------------------
  S_float.temp = mioFlo; // si scompone in 4 byte
  f0 = S_float.byte_s[0];
  f1 = S_float.byte_s[1];
  f2 = S_float.byte_s[2];
  f3 = S_float.byte_s[3];
 // una volta scomposto si trasmettono i 4 byte
  Wire.beginTransmission(80); // trasmette allo slave
  Wire.write(f0); // invia un byte
  Wire.write(f1); //
  Wire.write(f2); //
  Wire.write(f3); //  invia un byte
  Wire.endTransmission(); // fine trasmissione
 //-------------------------------------------------------
  delay (3000);
}
//------ end master ----------------------------------


user-1: I don't know what your problem is, but you have a gross error at LiquidCrystal_I2C lcd(0x3E, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);. You have a I2C LCD display but you are using it as an old-style LCD initialization.
The correct initialization for and I2C LCD display is 
LiquidCrystal(0x2A, 16, 2);

You have to replace 0x2A for the correct I2C address of your LCD display (Use a I2C scanner sketch for that).
You have to check the API of your libraries first (usually a .h file):
    /**
     * Constructor
     *
     * @param lcd_addr  I2C slave address of the LCD display. Most likely printed on the
     *                  LCD circuit board, or look in the supplied LCD documentation.
     * @param lcd_cols  Number of columns your LCD display has.
     * @param lcd_rows  Number of rows your LCD display has.
     * @param charsize  The size in dots that the display has, use LCD_5x10DOTS or LCD_5x8DOTS.
     */
LiquidCrystal_I2C(uint8_t lcd_addr, uint8_t lcd_cols, uint8_t lcd_rows, uint8_t charsize = LCD_5x8DOTS);


30063: <p>I am having some trouble connecting my 2 Arduino Nanos with I2C. I have this configuration:</p>

<ul>
<li>SLAVE RECEIVER Nano with DS1037 and LCD 16x02 on I2C.</li>
<li>MASTER SENDER Nano.</li>
</ul>

<p>After some time the Slave receiver prints on LCD random chars. If I delete the line including library RTCLIB.h everything is working except the clock. Thanks for your help :D</p>

<p>Slave receiver code:
</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;Wire.h&gt; // include la libreria
#include &lt;LiquidCrystal_I2C.h&gt;
#include "RTClib.h"

LiquidCrystal_I2C lcd(0x3E, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
RTC_DS1307 RTC; // orologio

static int anno;
static int giorno;
static int mese;
static int ora;
static int secondo;
static int oldSecondo;
static int minuto;
static int oldMinuto;
static int annoGrezzo;

//------------------------------------------------------------
// si ripete la union esattamente come nel master
union Scomp_float {
  // si utilizza union x float
  float temp;
  char byte_s[4];
} S_float;

//------------------------------------------------------------
// si ripete la union esattamente come nel master
union Scomp_long {
  // si utilizza union x long
  long int mioL;
  char byte_sL[4];
} S_long;

//------------------------------------------------------------
//------------- byte temporanei
byte f0 = 0;   // contengono i byte ricevuti
byte f1 = 0;
byte f2 = 0;
byte f3 = 0;
byte a1 = 0;
//-------------------------------------------------------------
//  qui si introdurranno i dati ricomposti dopo la trasmissione
long int masterLong = 0;
float masterFloat = 0;
int masterInt = 0;
//--------------------------------------------------------------

void setup() {
  Wire.begin(80);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  lcd.begin(16, 2);
  Serial.begin(9600);           // start serial for output
  //-----------orologio-----------
  RTC.begin();
  // Check to see if the RTC is keeping time.  If it is, load the time from your computer.
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // This will reflect the time that your sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  //-----------fine orologio-----------
}

void loop() {
  //------------------------------------------------------------
  //   si stampano i dati ricevuti e ricomposti
  //------------------------------------------------------------
  Serial.println(masterInt);
  Serial.println(masterLong);
  Serial.println(masterFloat);
  DateTime now = RTC.now();
  annoGrezzo = now.year();
  anno = ( annoGrezzo % 100);
  mese = now.month();
  giorno = now.day();
  ora = now.hour();
  minuto = now.minute();
  lcd.setCursor(0, 0);
  lcd.print(masterInt);
  lcd.setCursor(0, 1);
  lcd.print(giorno);
  lcd.print(" ");
  lcd.print(mese);
  lcd.print(" ");
  lcd.print(anno);
  lcd.print("  ");
  lcd.print(ora);
  lcd.print(":");
  lcd.print(minuto);
  delay (1000);
  lcd.clear();
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  if (howMany == 2) {
    // se in arrivo due dati
    f0 = Wire.read(); // si leggono i byte
    f1 = Wire.read();
    masterInt =  ((f1 &lt;&lt; 8) | f0); // si ricompone l'intero
  }

  if (howMany == 4) {
    // se in arrivo 4 dati è un float
    f0 = Wire.read();  // si leggono i byte
    f1 = Wire.read();
    f2 = Wire.read();
    f3 = Wire.read();
    S_float.byte_s[0] = f0; // si ricompone il float
    S_float.byte_s[1] = f1;
    S_float.byte_s[2] = f2;
    S_float.byte_s[3] = f3;
    masterFloat = S_float.temp;
  }

  if (howMany == 5) {
    // se in arrivo 5 dati è un long
    f0 = Wire.read();  // si leggono i byte
    f1 = Wire.read();
    f2 = Wire.read();
    f3 = Wire.read();
    a1 = Wire.read();
    S_long.byte_sL[0] = f0;  // si ricompone  il long
    S_long.byte_sL[1] = f1;
    S_long.byte_sL[2] = f2;
    S_long.byte_sL[3] = f3;
    masterLong = S_long.mioL;
  }
}
</code></pre>

<p>Master sender code:</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;Wire.h&gt; // si include la libreria
//---------------------------------------------------------
union Scomp_float {
 // si utilizza union x float
  float temp;
  char byte_s[4];
} S_float;
//---------------------------------------------------------
union Scomp_long {
 // si utilizza union x long
  long int mioL;
  char byte_sL[4];
} S_long;
//----------------------------------------------------------
// questi sono i dati che si vogliono trasmettere

long int mioLong = 1234567801;
float mioFlo = 123456.29;
//----------------------------------------------------------
byte a1 = 0; // conterrà i primo byte dell'int
byte a2 = 0; // conterrà il secondo byte dell'int
byte f0 = 0; // contengono i byte del float e del long
byte f1 = 0;
byte f2 = 0;
byte f3 = 0;
void setup() {
  Wire.begin(); // join i2c bus (address optional for master)
}

void loop() {
  int mioInt = random(30000);
 //-----------------------------------------------------
 // trasmissione di un intero ( 2 byte)
 //-----------------------------------------------------
  a1 = byte(mioInt); // si scompone l'intero in 2 byte
  a2 = byte( mioInt &gt;&gt; 8);
  Wire.beginTransmission(80); // inzia trasmissione allo slave

  Wire.write(a1); //  invia un byte
  Wire.write(a2); //  invia il secondo byte
  Wire.endTransmission(); // stop transmitting
 //------------------------------------------------------
  delay (2000);
 //------------------------------------------------------
 // trasmissione intero lungo 4 byte
 //------------------------------------------------------
  S_long.mioL = mioLong; // si scompone in 4 byte
  f0 = S_long.byte_sL[0];
  f1 = S_long.byte_sL[1];
  f2 = S_long.byte_sL[2];
  f3 = S_long.byte_sL[3];
  a1 = 1; // si trasmette questo byte solo per segnalare allo slave
 // che stiamo trasmettendo un long
 // una volta scomposto si trasmettono i 4 byte
  Wire.beginTransmission(80); // trasmette allo slave
  Wire.write(f0); // invia un byte
  Wire.write(f1); //
  Wire.write(f2); //
  Wire.write(f3); //  invia un byte
  Wire.write(a1);
  Wire.endTransmission(); // fine trasmissione
 //-------------------------------------------------------
  delay (2000);
 //------------------------------------------------------
 //   trasmissione di un float 4 byte
 //------------------------------------------------------
  S_float.temp = mioFlo; // si scompone in 4 byte
  f0 = S_float.byte_s[0];
  f1 = S_float.byte_s[1];
  f2 = S_float.byte_s[2];
  f3 = S_float.byte_s[3];
 // una volta scomposto si trasmettono i 4 byte
  Wire.beginTransmission(80); // trasmette allo slave
  Wire.write(f0); // invia un byte
  Wire.write(f1); //
  Wire.write(f2); //
  Wire.write(f3); //  invia un byte
  Wire.endTransmission(); // fine trasmissione
 //-------------------------------------------------------
  delay (3000);
}
//------ end master ----------------------------------
</code></pre>
 -1: <p>I don't know what your problem is, but you have a gross error at <code>LiquidCrystal_I2C lcd(0x3E, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);</code>. You have a I2C LCD display but you are using it as an old-style LCD initialization.</p>

<p>The correct initialization for and I2C LCD display is </p>

<pre><code>LiquidCrystal(0x2A, 16, 2);
</code></pre>

<p>You have to replace 0x2A for the correct I2C address of your LCD display (Use a I2C scanner sketch for that).</p>

<p>You have to check the API of your libraries first (usually a .h file):</p>

<pre><code>    /**
     * Constructor
     *
     * @param lcd_addr  I2C slave address of the LCD display. Most likely printed on the
     *                  LCD circuit board, or look in the supplied LCD documentation.
     * @param lcd_cols  Number of columns your LCD display has.
     * @param lcd_rows  Number of rows your LCD display has.
     * @param charsize  The size in dots that the display has, use LCD_5x10DOTS or LCD_5x8DOTS.
     */
LiquidCrystal_I2C(uint8_t lcd_addr, uint8_t lcd_cols, uint8_t lcd_rows, uint8_t charsize = LCD_5x8DOTS);
</code></pre>
