i2c code

Hello

I have a couple of ardupilots connected for 2 wire communications but my code seems not to be working properly. Can anyone see a problem?

My slave code is:

#include <Wire.h>

int dataGPS = {0, 0, 0, 0};
int oldGPS = {0, 0, 0, 0};
boolean newGPS = 0;
boolean validGPS = 0;
int alt_MSL = 0;
int lat = 0;
int lon = 0;
int extra = 0; // for debugging

void setup() {
initBoard();
}
void loop() {
getGPS();
if(validGPS) {
Serial.println(" data “);
Serial.print(alt_MSL);
Serial.print(” “);
Serial.print(lat);
Serial.print(” “);
Serial.print(lon);
Serial.print(” ");
Serial.print(extra);

}
}
void receiveEvent(int howMany)
{
byte count = 0;
newGPS = 1; // New data incoming
validGPS = 1; // Possibly valid data
// Read required data
for(int i = 0; i < 4; i++) {
oldGPS = dataGPS*; // Store previous values*
_ dataGPS = Wire.receive();
/if(dataGPS _== oldGPS) // Data invalid if it is unchanged (ASSUME UAV MOVING)*

* count++;*
* if(count == 3)*
_ validGPS = 0;/
}
}
// Obtain the values from the other board*

void getGPS() {
* alt_MSL = dataGPS[0];*
* lat = dataGPS[1];
lon = dataGPS[2];
extra = dataGPS[3];
}
void initBoard() {
Serial.begin(9600); // will be determined by GPS*

* Wire.begin(4); // Join i2c bus with address #4*
* Wire.onReceive(receiveEvent); // Register event*
* pinMode(13, OUTPUT);
Serial.println(“Ready”);
}
/////////////////////////////////////////////////
My master code is:
#include <Wire.h>
// I2C dedicated to sending GPS, this is master which parses GPS*

// Array for altitude, latitude and longitude in this order
int dataGPS1[] = {0, 0, 0, 0};
boolean newGPS1 = 1;
void setup()
{
* Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
}
void loop()
{
Wire.beginTransmission(4); // transmit to device #4*

* setGPSdata();
Wire.endTransmission(); // stop transmitting*

* delay(500);
}
// Acquire data from parsing NMEA*

void setGPSdata() {
* // Wait for new GPS, in reality function will compare previous data values with present ones*
* if(newGPS1) {
dataGPS1[0] = 100;
dataGPS1[1] = 200;
dataGPS1[2] = 300;
dataGPS1[3] = 500;
for(int i = 0; i < 4; i++) {
Wire.send(dataGPS1);
Serial.println(dataGPS1);
delay(50);
}
}
else {}
}*

THANKS
sirk_

In what way does your program not work?

PS. if you want to post code more clearly, use the hash button (#) just above the test box.