Using an Arduino with Roborio for pixy cam

Hi. This is my first year in programming and I have no idea how to even import code in roborio. I have a bit of experience with Arduino and pixy cam. I need help with operating my motors which is connected to roborio using the Arduino which reads the the pixy cam. It would be very helpful if I get some sample code to start basic communication between Arduino and roborio. Thanks in advance!

What language are you using (on the rio)?

Are you specifically looking for advice on interface between Arduino -> Roborio? I have used I2C to send data from Roborio to Arduino (RIODuino on MXP port) with consistent success in previous years. It sounds like you want to do the opposite. You need to declare an I2C object in your code and listen to the Arduino on the I2C wire. Here is a discussion about this (in Java): https://forums.usfirst.org/forum/general-discussions/first-programs/first-robotics-competition/competition-discussion/programming-aa/java-ad/14687-using-i2c-on-the-roborio-for-sensors

In your case, you probably want the Pixy to send coordinates to the Roborio or something like that. There are other ways to do this, but I have had decent luck with I2C.

This thread is about your exact question, I believe: Pixy I2C

Thanks for replying but the problem is that I have no idea how to even upload this to roborio because this is java and I am guessing this is going to go to eclipse. I have 0 experience with roborio. Can roborio take different codes like one for driving and one for pixy. Also I was using Arduino so I can make a macro to make the robot automatically do something I want.

Java is the one I programmed my drive system. So I would prefer using java to stay consistant.

    const int buttonPin = 7;
int buttonState = 0;
void setup()
{
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop()
{
  
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
    digitalWrite(4, HIGH);
    delay(10000);
  }
}

So kind of like this if I press the button I need some sort of code so Arduino which is connected to roborio using I2c send signal to victor motor controller to spin cim motors even better if I can use a potentiometer.

OK. Sounds like you have a lot going on. I would recommend reading through the WPILIB Java tutorial https://wpilib.screenstepslive.com/s/currentCS/m/java.

If you still really are trying to send commands from Arduino to RoboRIO, you need to setup both the RoboRIO code and the arduino for I2C. The Arduino wire.h library can be used to send data to RoboRIO which then listens to that I2C address and can use that data for any action of the robot. The example I posted above shows Java RoboRIO code listening for I2C commands of 3 numbers and uses those to drive the robot.

Alternatively, you can use the RS232 port on the rio to talk Serial with the Arduino (RX goes to TX and TX to RX and make sure to match baud rates).

Note that if going this route, you will need to disable “Console Out” on the rio (either through the re-imaging tool or the web interface). (I think this is the right class: http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/hal/SerialPortJNI.html)

1 Like

After doing a lot of research, now I understand what to do. Thanks By the way!

If you are just wanting to read all your data from the pixy on the Arduino and then send the results to the RoboRIO, then we have a GitHub repo that is just that. It has code for getting data on the Arduino from the pixy, although it’s a pixy 1. And then it has a java file for reading the data on the RoboRIO from the Arduino using I2C.