i2c problem

Hi,
i have a communication problem between two arduino in i2c.

i must transfer the values of a matrix from the master to the slave.
With the array I did, but not with the matrix. Then, another problem is that I do not read numbers above 255, after 255 starts by 0.

can someone help me?

this is the master

#include <Wire.h>

int num =250;
int num1 =280;
byte long stepsMatrix[15][6] = {
{1, 12, 15, 000, 000, 000},
{2, 34, 10, 000, 000, 000},
{3, 50, 17, 000, 000, 000},

{1, 35, 10, 000, 000, 000},
{2, 36, 15, 000, 000, 000},
{3, 100, 12, 000, 000, 000},

{1, 2048, 15, 000, 000, 000},
{2, 2048, 10, 000, 000, 000},
{3, 150, 15, 000, 000, 000},

{1, 0, 25, 000, 000, 000},
{2, 0, 25, 000, 000, 000},
{3, 122, 15, 000, 000, 000},

{1, 0, 10, 000, 000, 000},
{2, 0, 10, 000, 000, 000},
{3, 33, 15, 000, 000, 000},

};

 byte array2[] = {200, 250, 500, 000, 000, 000};


int long NEWPASSO;
int CONT_POSIZIONE=1;
int  TOT_RIGA=0;

void setup() {
  
Wire.begin();
Serial.begin(9600);
}
  
  void loop() {
Wire.beginTransmission(3);


for(CONT_POSIZIONE =1; CONT_POSIZIONE <4; CONT_POSIZIONE++){

   NEWPASSO =stepsMatrix[TOT_RIGA*3][1]; // passaggio contatore posizione in matrice a  motore PASSO


    Wire.write(NEWPASSO;


Serial.println( NEWPASSO);
   TOT_RIGA = TOT_RIGA+1;
    
   Wire.endTransmission();


    
  }
  }

and this is the slave

#include <Wire.h>



void setup() {
  

Serial.begin(9600);
Wire.begin(3);
Wire.onReceive(ricevi);
}
  
  void loop() {
  
    delay(100);
  }

  void ricevi(){
 while(Wire.available()>0){
    int long a = Wire.read();
    Serial.println(a);
 }


  }

I would send the matrix data to the slave, but the slave reads random numbers, while with array reads them right (except 500).

Thanks for your help!

(deleted)

I knew this, but is there a way to transfer more than one byte each time?

Miky:
I knew this, but is there a way to transfer more than one byte each time?

Yes, send both bytes sequentially each time.

sorry I explained to you badly, I wanted to know if i can send a single bit instead of a single byte and as far possible?

however the problem remains, how can i send the matrix data?

for example

byte long stepsMatrix[3][6] = {
{1, 10, 15, 000, 000, 000},
{2, 34, 10, 000, 000, 000},
{3, 50, 17, 000, 000, 000},

{1, 20, 10, 000, 000, 000},
{2, 36, 15, 000, 000, 000},
{3, 100, 12, 000, 000, 000},

{1, 30, 15, 000, 000, 000},
{2, 2048, 10, 000, 000, 000},
{3, 150, 15, 000, 000, 000},

};

i want send the 10, 20 and 30, how can i do?

thank you

Miky:
sorry I explained to you badly, I wanted to know if i can send a single bit instead of a single byte and as far possible?

however the problem remains, how can i send the matrix data?

for example

byte long stepsMatrix[3][6] = {
{1, 10, 15, 000, 000, 000},
{2, 34, 10, 000, 000, 000},
{3, 50, 17, 000, 000, 000},

{1, 20, 10, 000, 000, 000},
{2, 36, 15, 000, 000, 000},
{3, 100, 12, 000, 000, 000},

{1, 30, 15, 000, 000, 000},
{2, 2048, 10, 000, 000, 000},
{3, 150, 15, 000, 000, 000},

};

i want send the 10, 20 and 30, how can i do?

thank you

No, you can not send a single bit. Look up the I2C specification, it deals with bytes. The 10,20,and 30 are all less than 255. On the other hand, 2048 will not fit.

But 2048 can be split into two bytes. It is 0x800, so you can send 0x08 0x00 and reassemble it on the other end.

The "byte long" type you've invented is fishy. I doubt that it is what you think it is. Does it even compile? "byte" is defined as "unsigned char" so you have a "unsigned char long".

thank you so much for your answer

yes, I was wrong to write long bytes though in compiling did not make me mistake.
I did not understand 2048 as it is 0x800 and send it at 0x08 and 0x00 at the same time

update:

i understand that it is in hex, but I do not know how to send them separately and recapture them in the slave.

is there a special function?

These functions can split an int data type into the high and low bytes to send and reassemble the int at the other end.

https://www.arduino.cc/en/Reference/LowByte
https://www.arduino.cc/en/Reference/HighByte

and this post may be of interest.

I finally solved the problems (for now :D)

Thanks a lot to everyone, really!