Hi,
I am trying to connect 5 arduinos & and OrangePi with I2C
in my current tests I am facing 2 issues
- when compiling I get the following warning
C:\Users\Antony\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.14\libraries\Wire\src/Wire.h:73:10: note: initializing argument 1 of 'void TwoWire::onRequest(void ()())'
void onRequest( void ()(void) );
^
2) and second and maybe relevant with the warning, Code in side 1
#include <Wire.h>
String msg = "";
int num =10000;
void setup() {
Serial.begin(9600); // start serial for output
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
Wire.beginTransmission(10);
Wire.write("Hello from loop");
Wire.endTransmission();
delay(2000);
}
void requestEvent(int howMany) {
Serial.print("I was requested to send");
Serial.println(howMany);
num = num +1;
Serial.print("num value is:");
Serial.println(num);
String numfromstring = String(num);
Wire.write(numfromstring.c_str());
}
I get random number on serial monitor i.e.:
I was requested to send-26108
I was requested to send772
I was requested to send-6396
I was requested to send-2812
I was requested to send1028
and on the other side ....
#include <Wire.h>
void setup() {
Wire.begin(10); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Wire.onRequest(requestEvent); // register event
Wire.onReceive(dataReceive);
}
void loop() {
Wire.requestFrom(8, 5); // request 5 bytes from slave device #8
Serial.print("I received:");
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
Serial.println("");
delay(3500);
}
void requestEvent(int howMany) {
Wire.write("Yo"); // respond with message of 6 bytes
}
void dataReceive(int byteCount) {
Serial.print("I received:");
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
Serial.println("_");
}
any ideas?
I was expecting Serial.println(howMany); to print the number 5 to serial