I2C slave not showing data on serial monitor

Hey guys. Pleasure interacting with all of you again. I would like to ask how to convert value of byte(double) to variable(double) back as the master is now working fine thanks to mr.johnwasser addition of conversion from variable to byte. My purpose is I want to write lat & lng variables from master to slave(receiver) so the slave can output to serial monitor. I have done my research but came up confused. Appreciate it someone can give a go at it. Thanks.

Master code(writer)

// Include Arduino Wire library for I2C
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include "TinyGPS++.h"
#include "SoftwareSerial.h"

int pinCS = 53;// pin 10 on uno

File myFile;
TinyGPSPlus gps;//This is the GPS object that will pretty much do all the grunt work with the NMEA data
SoftwareSerial serial_connection(62, 63);


#define SLAVE_ADDR 9 // Define Slave I2C Address


void setup() {

 // Initialize I2C communications as Master
 Wire.begin();
 Serial.begin(9600);
 serial_connection.begin(9600);//This opens up communications to the GPS
 pinMode(pinCS, OUTPUT); 
}

void loop()
{
  while(serial_connection.available())//While there are characters to come from the GPS
       {
         gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
       }
       if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
       {
          myFile = SD.open("xtracker.txt", FILE_WRITE);  // Create/Open file
          myFile.print("Latitude:");
          myFile.print(gps.location.lat(), 6);// Latitude in degrees (double)
          myFile.print(",");
          myFile.print("Longitude:");
          myFile.print(gps.location.lng(), 6);// Longitude in degrees (double)
          myFile.println();
          myFile.close();
       }


     double lat = gps.location.lat();
     double lng = gps.location.lng();


 // Send the two 'double' values to the Slave
 Wire.beginTransmission(SLAVE_ADDR);
 Wire.write((byte *)&lat, sizeof lat);
 Wire.write((byte *)&lng, sizeof lng);
 Wire.endTransmission();
 delay(500);


}// end loop()

Slave code(receiver)

// Include Arduino Wire library for I2C
#include <Wire.h>

// Define Slave I2C Address
#define SLAVE_ADDR 9


// Variable for received data
int double lat;
int double lng;

void setup() {

 // Initialize I2C communications as Slave
 Wire.begin(SLAVE_ADDR);
  
 // Function to run when data received from master
 Wire.onReceive(receiveEvent);


 // Setup Serial Monitor
 Serial.begin(9600);
 Serial.println("I2C Slave Demonstration");
}


void receiveEvent() 
{

//Not sure how the conversion goes to achieve wire.read// 

}

void loop()
{
  delay(50);
}

code-button

I want to write some basic information. You should follow some rules to get better help.

If you want to post code use the insert code-Button. This button looks like this: <|>. You can find this button if you use the reply-function instead of the quick-reply function. If you click on reply you get a menu right above the textinput-field
at the left end of this menu you wil find the <|>-Button.

Code in such a code-section is written in a constant-distance-font which will show all the indentions the same way as in the IDE. And with a simple click the users can put the whole code into the clipboard.

best regards Stefan

If you want to post code use the insert code-Button.

Even easier is to select the code to be posted in the IDE, right click, select Copy for Forum then paste into the forum. The code tags will be added automatically. If you want to post a complete sketch then there is no need to even select it, just right click in the IDE and Copy for Forum

You can find this button if you use the reply-function instead of the quick-reply function

Or enable the full editor in Quick Reply in your profile

Hi Bob,

this right-click is very comfortable. Thank you for pointing on this.
I will modify my standard-text-block to this version.
That's what programming is for: If something has a regular pattern go write a program for it.

best regards Stefan

The right click/Copy for Forum is a long standing function of the IDE but it was never used because it used to copy a whole raft of HTML into the post which made copying and downloading it just about impossible. At some point in time it was fixed but I have seen no mention of it and I only discover that it had been fixed by accident. It possibly got a mention in the Release notes for the IDE version in which it was fixed

Thanks for heads up to both(StefanL38) & (UKHeliBob). I've made changes so you can look at it now much easier :smiley: