Interfacing an Arduino UNO to the RobotRIO via I2C, how should I begin approach this?

So, in order to use a PixyCam2 on our robot, we need to connect it first to an Arduino, which in and of itself is not difficult.However, I need the Pixy to pass values to the RobotRIO to be used for line following/autonomous aim. I am attempting to connect the Pixy to the Arduino, then pass values from the camera through the Arduino to the RobotRIO over the I2C bus.I have seen documentation that explains very targeted and specific concepts, however most are in Java or are not applicable. My team uses C++ to program, and I honestly just need a starting point because what they are asking is a little ambitious. Thank you!

Where is the Java documentation? I have not done this particular thing before, but I have experience with both languages and may be able to help you translate the Java instructions to C++.

Are you interfacing with the Pixy over serial? If not, I would recommend using that to interface with the Arduino.

If so, then here are some places I would look:
Arduino slave: https://www.arduino.cc/en/Tutorial/MasterReader
Rio I2C docs: http://first.wpi.edu/FRC/roborio/release/docs/cpp/classfrc_1_1I2C.html

You can use the I2C read method on the rio, the Arduino will be prompted as in the SlaveWriter code in the former link.

I can tell you the Arduino code that works for us. For some reason it only works when the computer is connected to the RoboRio via USB though.
Arduino Code

#include <Wire.h>

void setup() {
  Wire.begin(4);                // join i2c bus with address #8
  Wire.onReceive(receiveData); // register incoming data
  Wire.onRequest(sendData); //register a request for data
  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 receiveData()
{
   while (Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
   }
Serial.println("");
}

// function that executes whenever data is requested from master
// this function is registered as an event, see setup()
void sendData()
{
   Wire.write("From Arduino");
}

The code we used for the robot is below but it is Java. It does work though and it is very little code.

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 = "This text IS the Data".getBytes();
    byte[] receiveData = new byte[12];   //This tells the RoboRio how many characters to receive
    arduino.transaction(sendData, sendData.length, receiveData, receiveData.length);
    System.out.println("Received: " + new String(receiveData, 0, receiveData.length));
  }
}

I don’t know how to make this work in c++ but maybe it will help you in some way.
We did get the Pixy2 and this code merged and working also but like I said it only seems to work via USB and we don’t know why.

Thanks all, I have converted my code into Java and am finding that documentation and readability are both much better now. Thanks for all the help!

In case anyone comes across this in the future I will post what our issue was with only working via USB.
Symptom: We were able to get the Arduino to talk to the RoboRio when the RoboRio was plugged into the computer via USB but not over WiFi.
Solution & Reason: We were powering the Arduino via USB from the computer because we were testing & uploading code. When the RoboRio and Arduino were both plugged into the same computer via USB they must have shared a ground on the USB and the I2C connection worked. Powering the Arduino via the VRM let us get communication working while connected to the RoboRio via Wifi.