Good afternoon, first of all my congratulations to this community.
My problem is this, I bought 2 arduinos, and i wanted to make communication between them by i2c .
I wanted to send one value, and then send the contents of two arrays. For this I followed this link http://arduino.cc/en/Tutorial/MasterReader but not working.
The program is huge so I will only show the Send function, I did.
void setup(){ //in setup i have this, and more other thing, but of communitation i have only this
Wire.begin();
in loop i have this
sender(val, array1, array2, , cont1, cont2); //val is a int val, array1 is a first array, array2 is second array and cont1 is size of first array and cont2 is the size of second array
my function sender is
void enviar(unsigned int nblocos,unsigned int *posicoes, unsigned int *valorespos, unsigned int conter1, unsigned int conter2 ){
Wire.beginTransmission(4); // transmit to device #4
Wire.write(nblocos);
for (int i= 0; i< (conter1); i++){
Wire.write(posicoes*); *
-
}*
-
for (int i= 0; i< (conter2); i++){ *
_ Wire.write(valorespos*); _
_ }*_
* Wire.endTransmission();*
* delay(1000);*
}
and my receiver have this
#include <Wire.h>
void setup()
{
* Wire.begin(4); // join i2c bus with address #4*
* Wire.onReceive(receiveEvent); // register event*
* Serial.begin(9600); // start serial for output*
}
void loop()
{
* delay(100);*
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
* while(1 < Wire.available()) // loop through all but the last*
* {*
* int x = Wire.read(); // receive byte as an integer*
* Serial.println(x); // print the integer*
}
But i dont print anything
the usb is connected in receiver, and i connecter 5v in arduino transmiter to Vin arduino receiver (arduino with usb)
What i make wrong
thanks a lot