I2C_readAnything passing more than one parameter?

Hi. Does anybody know how to pass more than one parameter via I2C?

Have someone tried to use this before?

I need to pass a float value and one more int value.

any help will be apreciated.

Tks!

I like to make a package of the data with a structure.

struct package_t 
{
  float f;
  int i;
} package;

Hi.. First of all, thank you very much for your help. I really apreciate it!

Could you please give me an example, I have never used struct package_t .

Could you give-me an example?

Tks a lot

The name 'package' is just what I made up. The "-t" is for "template", you don't need it.

struct 
{
  int apple;
  int toast;
  float milk;
  char name[16];
} lunchbox;

lunchbox.apple = 2;
lunchbox.toast = 0;
lunchbox.milk = 1.5;
strcpy (lunchbox.name, "Hello World");

Serial.print ("There is ");
Serial.print (lunchbox.milk);
Serial.println (" gallons of milk in my lunchbox");

When a pointer to the structure is used, things do change.
In that case you do have to declare the "struct lunchbox_t ...", because the template is needed to create a pointer to it.
With a pointer the dot is no longer used, but the '->'.

struct lunchbox_t
{
  int apple;
  int toast;
  float milk;
  char name[16];
} ;

struct lunchbox_t* plunchbox;
plunchbox->milk = 0.1;

The pointer is handy when a buffer is received. Let the pointer point to the beginning of the buffer, and it is possible to use the elements of the structure.

hi.. First of all, thank youu for your great explanation.....

Can I ask you how to use this struct to pass a float and a integer to another arduino using I2C ?

thank you veeery much

:slight_smile:

The same as you would pass a float or an integer.
But instead you use the structure.

Your question is about readAnything, and I don't know how you do that.
Give the structure a try and show the sketch (between code tags, use the '#'-button).

Ok, Caltoa. thank you very much.

absolutely yes, I will give a try and let you know about my progress..
but I liked the struct idea... Perfect...
Thank you again!!!!