I can’t see what I 'm doing wrong…
“MasterBasic”
/*I want this to control slave data sending.
* First the slave will get a request to send data
* and then slave will respond with data
*Thats all for now
*/
#include <Wire.h>
const byte MASTER_ADDRESS = 50;
byte SLAVE_ADDRESS;
byte specArray[]={0};
void setup()
{
SLAVE_ADDRESS = 10;
Wire.begin(MASTER_ADDRESS);
Serial.begin(9600);
Serial.println("Setup OK");
}
void loop()
{
Serial.println("In the Loop");
byte index = 0;
Wire.requestFrom(SLAVE_ADDRESS, 6); //Wire.requestFrom(intAddress, intLength, boolStop)
while(Wire.available() > 0 && index < 6)
{
specArray[index] = Wire.read();
Serial.println(specArray[index]);
index++;
delay(500);
}
}
and here is “SlaveBasic”
#include <Wire.h>
const byte MASTER_ADDRESS = 50;
const byte SLAVE_ADDRESS = 10;
byte specArray[] = {0,0,0,0,0,0};
void setup()
{
Wire.begin(SLAVE_ADDRESS);
Serial.begin(9600);
Wire.onRequest(requestHandler);
Serial.println("Setup OK");
delay(5);
}
void loop()
{
byte specArray[] = {1,2,3,4,5,6}; //test only
Serial.println(specArray[0]);
}
void requestHandler()
{
Wire.beginTransmission(50);
Wire.write(specArray,6);
if (Wire.endTransmission () == 0)
{
// success!
Serial.println("Got Sent");
}
else
{
// failure ... maybe slave wasn't ready or not connected
Serial.print("Failed");
}
}
The goal is to see the array elements appear in the Master serial monitor as it indexes through the wire.read statment. I have read all the examples I can find but this still has me stumped.