Parse multiple data types between Arduinos

Hi,

I am struggling to understand from the tutorials (MasterWrite/SlaveReciever) how to communicate data between two Arduino Megas.

I would like to be able to parse 14 float data points and 1 int data point. I would prefer I2C communication but I am flexible. I would also prefer to parse these points as an array or something similar so that it is easier to read.

I am quite inexperienced with this so any help would be much appreciated!

Thanks,
Paul

Since you have Megas, I would use one of the extra Serial ports for communication. Serial is easier to program for, can be as fast as I2C and will work over a greater distance. I2C is for inter-board communication. It will not work over about 1 meter without extra work.

See the excellent serial input basics tutorial for information about sending and receiving null terminated character arrays (strings) reliably to/from serial ports in a non blocking fashion. Example #5 shows how to parse data from the received strings.

@OP

Try the following codes for the I2C Master to send 8 float numbers and one integer number. Write the codes for the I2C Slave to read the data items sent by the Master. (not fully tested).

#include <Wire.h>
#include<I2C_Anything.h>

float myfloat[] = {1.23, 4.56, 7.89, 12.45, 624.75, 11.23, 74.12, 0.07};
int x = 0x1235;
void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  Wire.beginTransmission(0x08);
  I2C_writeAnything(x);
  for (int i = 0; i < 8; i++)
  {
    I2C_writeAnything(myfloat[i]);
  }
  Wire.endTransmission();
  delay(1000);
}