I2c over USB works but not over WIFI or Network Cable

We figured out how to get an Arduino and RoboRio to send and receive over I2C.
Everything works great while the computer is connected to the RoboRio via USB.
When we connect via WIFI or Network Cable to the RoboRio we get nothing received on either device.

Robot Code

package frc.robot;

import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.TimedRobot;

public class Robot extends TimedRobot {

  public static I2C arduino;
   
  @Override
  public void robotInit() {
    arduino = new I2C(I2C.Port.kOnboard, 8);
  }

  @Override
  public void testInit() {
  }

  @Override
  public void testPeriodic() {
    byte[] sendData = "Gimme my data".getBytes();
    byte[] receiveData = new byte[12];
    arduino.transaction(sendData, sendData.length, receiveData, receiveData.length);
    System.out.println("Received: " + new String(receiveData, 0, receiveData.length));
  }
}

Arduino Code

#include <Wire.h>

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Wire.onRequest(requestEvent);
  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()
{
  Serial.print("Received: ");
  while (Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
    
}
Serial.println("");
}

void requestEvent()
{
   Wire.write("From Arduino");
}

Why would this work over USB and not WIFI or Network Cable?

I’m not sure but try unchecking the “Enable Console Out” checkbox on the roboRIO Imaging tool.
This might be interfering with the I2C port when the robotRIO turns on.

First, that checkbox is unchecked by default. Secondly, that option utilizes the RS-232 serial port and doesn’t affect the I2C port at all.

I tried that anyway and we still get the same thing. No communication between RoboRio and Arduino over Wifi.
I think my next step is trying on another RoboRio.
This is our first time trying anything over I2c and we have a pixy2 working decent via the Arduino.
If we can’t get this to work over WiFi then we have to scrap everything we just spent a week figuring out and go another route.

We had this issue for a bit. If you’re not already doing it, plugging the microcontroller/whatever into its own separate power source in the VRM fixed it for us.

2 Likes

And we have a winner!!!
We had been powering the Arduino from the PC USB as we were uploading code a lot.
Now it makes sense that the RobioRio and Arduino being plugged into the Laptop via USB were sharing a common ground or something. Powering the Arduino from the VRM fixed the issue. Hadn’t tried it as this is still on a bench and because it had worked for all of our testing until we went over WiFi it never even crossed my mind.

Thank you!