Our team is currently trying to get the REV Color Sensor V2 to communicate with the RoboRIO. Currently, we’re just trying to verify that the sensor and the RoboRIO are able to communicate. We’ve tried doing this two ways so far.
- Used addressOnly() to verify that the device exists. The RoboRIO returned true, which meant that the sensor and RoboRIO weren’t communicating.
- Used a read() function that read the 0x12 address, which should return the ID. It returned true again, which I can only presume means that, again, the two weren’t communicating.
The sensor itself is on. There’s an LED shining, so we don’t think it’s a wiring issue. That said, we’re not entirely sure why the sensor isn’t communicating with the RoboRIO.
The following is our code:
package frc.robot.subsystems;
import edu.wpi.first.wpilibj.I2C;
import java.nio.ByteBuffer;
public class ColorSensor {
protected final static int COMMAND_REGISTER_BIT = 0x80;
I2C sensor;
public ColorSensor() {
sensor = new I2C(I2C.Port.kOnboard, 0x39);
sensor.write(COMMAND_REGISTER_BIT | 0x00, 0b00000011);
}
public void update(){
System.out.println(sensor.read(0x60, 7, ByteBuffer.allocate(7)));
}
}
After setting the sensor itself as an instance variable, we’re calling ColorSensor.update() in RobotPeriodic, which runs continuously. The System.out.println() is meant to return false if the device can be connected to properly, and true if it “aborts” before finding it. For us, is always returns true.
We also have a coprocessor (Raspberry Pi). If it’s easier to do this entire process through the Pi, then if anyone has any examples on that that would be great.