Hi everyone,
I tried to send char array from one Arduino to next via I2C communication. My sending sketch is,
#include <Wire.h>
const int16_t I2C_MASTER = 0x42;
const int16_t I2C_SLAVE = 0x08;
char Data1[54] = "$GNSS,0,0,0,0000000000,0000000000,0000000,00,********";
char Data2[54] = "$ECEF,0000000000,0000000000,000000000,00000000,000000";
void setup()
{
Serial.begin(115200);
Wire.begin();
}
void loop() {
Serial.println(Data1);
Serial.println(Data2);
Wire.beginTransmission(8);
Wire.write(Data1);
Wire.endTransmission();
delay(100);
Wire.beginTransmission(8);
Wire.write(Data2);
Wire.endTransmission();
delay(500);
}
And my receiver sketch is,
#include <Wire.h>
void setup() {
Wire.begin(8);
Serial.begin(115200);
}
void loop() {
Wire.onReceive(receiveEvent);
delay(100);
}
void receiveEvent(int howMany) {
while (1 < Wire.available()) {
char c = Wire.read();
Serial.print(c);
}
int x = Wire.read();
Serial.println(x);
}
My sender side Serial monitor is OK. But my receiver side is showing like this,
$GNSS,0,0,0,0000000000,0000000048
$ECEF,0000000000,0000000000,00048
How can I pass whole array via I2C. I tried using Wire.write(Data1, sizeof Data1); but gives same result. I hope to pass some sensor data from one Arduino to next and doing calculation in my second Arduino. Please help me to fix this problem.