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!