I see. Try this
roboRIO:
Code:
static I2C arduino = new I2C(Port.kOnboard, 42);
@Override
public void teleopPeriodic() {
byte[] sendData = "sample text".getBytes();
byte[] receiveData = new byte[sendData.length];
boolean failed = arduino.transaction(sendData, sendData.length, receiveData, receiveData.length);
if(!failed) {
System.out.println("Got data: " + new String(receiveData, 0, receiveData.length);
}
}
Arduino:
Code:
#include <Wire.h>
void setup() {
Wire.begin(42);
Wire.onRequest(requestEvent);
Serial.begin(9600);
}
void loop() {
delay(100);
}
// send back the same data as we receive
void requestEvent() {
Serial.println("Got request:");
while (Wire.available()) {
char c = Wire.read();
Serial.print(c);
Wire.write(c);
}
}