The Wire lib derives from the Print library, you can use:
Wire.write( angFeed, 8 );
This implies angFeed is an array of bytes/char if not (is larger like int/long), you'll have to multiply the number of elements to send by the size of one element.
pYro_65:
The Wire lib derives from the Print library, you can use:
Wire.write( angFeed, 8 );
This implies angFeed is an array of bytes/char if not (is larger like int/long), you'll have to multiply the number of elements to send by the size of one element.
I still need help on the slave end of the program however. I edited the example sketch for the slave reader to the following
#include <Wire.h>
int angFeed[8];
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent);
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
{
angFeed[8] = Wire.read();
Serial.print(angFeed[0]);
Serial.print(",");
Serial.print(angFeed[1]);
Serial.print(",");
Serial.print(angFeed[2]);
Serial.print(",");
Serial.print(angFeed[3]);
Serial.print(",");
Serial.print(angFeed[4]);
Serial.print(",");
Serial.print(angFeed[5]);
Serial.print(",");
Serial.print(angFeed[6]);
Serial.print(",");
Serial.println(angFeed[7]);
}
}
It compiles just fine but prints out only zeros. I'm suspecting that angFeed[8] = Wire.read(); isn't correct.
You cannot simple write the hole array at once. Also, Wire.read() just gives you the next available byte, to all received bytes. So just loop over them:
#include <Wire.h>
int angFeed[8];
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent);
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){
for(howMany; howMany > 0; howMany--){
angFeed[howMany - 1] = Wire.read();
Serial.print(angFeed[howMany - 1]);
if(howMany != 1){
Serial.print(",");
}
else{
Serial.println();
}
}
}
septillion:
You cannot simple write the hole array at once. Also, Wire.read() just gives you the next available byte, to all received bytes. So just loop over them:
#include <Wire.h>
int angFeed[8];
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent);
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){
for(howMany; howMany > 0; howMany--){
angFeed[howMany - 1] = Wire.read();
Serial.print(angFeed[howMany - 1]);
if(howMany != 1){
Serial.print(",");
}
else{
Serial.println();
}
}
}
This worked like a charm! Thanks you're a life saver!