Reading Arduino through I2C (Java)

Hey, I’m trying to read byte[] from the PixyCam that is connected to the arduino through SPI and the arduino will write data to the roboRio through I2C. I’m quite new to this, so I’ll take anything :slight_smile: Thanks!



I don’t have much experience with the Pixy through SPI, but the team I mentor is currently using Pixy2 cameras with Arduinos.

They are using the Pixy ribbon cable that connects directly to the Arduino. On the Arduino, they use the Pixy library API. A link to instructions for both is below:

If don’t have a strong reason to use SPI as the Arduino-to-Pixy interface, then I suggest using the above approach.

From the Arduino, the students are using I2C (though they are connecting to another Arduino via I2C, not the RoboRio, long story). Below is example code that shows how to set your Arduino up as a slave on the I2C network. You’ll want to use the second set of code on that page (the code for Slave Sender) since the RoboRio will be the master.

Also, one last thing. The students noticed that the Pixy does not like other devices holding up the processor. They had to put ultrasonic sensors on a separate Arduino because the waiting for the echo caused “weird” stuff to happen on the Arduino when it was also running the Pixy interface. They haven’t seen an issue with delay() or the I2C interface on the same Arduino as the Pixy.

I hope this helps, feel free to let me know if you want more info on any of this.

1 Like

If you’re using the Pixy2, you don’t even need an arduino. You can connect it directly to the i2c port on the rio via custom cable. There are directions for this on the official documentation. After connecting it, simply create an i2c object in code and use the methods writeBulk() and readOnly() to read/write packets. My team has already accomplished this and it can be found here:

Take a look at the Pixy2Handler class. I’d also be happy to explain any of the specifics if you have any questions.


Thank you 7157 for this. We’d been trying some other libraries that teams had published but weren’t getting results - yours worked without any fuss.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.