Pixy2 SPI communication problems?

Hi all, head programmer for Apex 5803 here. We’re trying to use a Pixy2 to track and follow power cells. The code builds and deploys to the robot properly with no errors until I try to fetch values from the Pixy, at which point we get a nullPointerException at whichever line tries to access those values and the code crashes. If anyone has any tips on using the Pixy or insight into our issue, it would be greatly appreciated.

We’re using this library and our code closely matches the example code found here.
Our Pixy is plugged into the RoboRio’s onboard SPI port (no Arduino or Raspberry Pi to process separately)
We’ve updated the Pixy to the latest firmware and configured it with signatures and set it to use SPI for communication.
I can post our code if it would be helpful, but I’m not used to text formatting on Chief Delphi and decided to omit it from this post.

As I’m writing this, I remember that we named signature 1 on the Pixy (the one we trained for the power cell) “PowerCell.” Could that be throwing things off and be responsible for the nullPointerException?
Also, I’m having trouble getting the Pixy to configure the Color Connected Components signatures inside of PixyMon; could that be responsible? If anyone could tell us how to do that it would be very helpful.

Edit: if it’s important, the Pixy if configured to communicate using the “SPI with SS” protocol instead of the Arduino SPI (if you’ve used PixyMon you’ll know what I mean)

1 Like

Try using the UART or I2C link. Even using fully functional Pixy code from last year, we were unable to get a SPI link to the Pixy working at all. My suspicion is that a bug in WPILIB is impacting the SPI communication somehow, but don’t have the capability to properly debug or assess this claim.

no errors until I try to fetch values from the Pixy, at which point we get a nullPointerException

This is unrelated to the above issue, but is due to trying to access information about a power cell location when no power cells were detected. Usually you get around this by checking the size of the returned array of detected objects, and if there’s more than zero, you can access information about them.

Alright, I’ll try the I2C. We went with SPI because the Pixy comes with SPI, but no I2C and we didn’t want to order cables. I guess that’ll change

I believe we’re already checking array length, but I’ll test that next meeting just to be sure. Thank you for your help and I’ll update the thread if either of those works.

1 Like

Can you clarify this? AFAIK, the 10-pin to 6 pin cable that comes with the Pixy is SPI, but usable only for wiring to the Arduino ISCP header. The Arduino ISCP header has no SS GPIO pin (it only has a reset pin), and as a result there’s no GPIO for SS on this cable. The upshot is that if you’re using this cable, you would need to configure the Pixy to SPI with No SS mode.

If you’re wiring up via custom cabling, then you can intentionally wire in the SS pin, which would enable SPI with SS to work.

With regards to posting code, if you wish to do that just use a line with 3 backtick characters, paste your code, and add another line of 3 backticks.
```
/*code*/
```

If done right, the preview field should show highlighted java rather than a giant mess.

AFAIK, the 10-pin to 6 pin cable that comes with the Pixy is SPI, but usable only for wiring to the Arduino ISCP header. The Arduino ISCP header has no SS GPIO pin (it only has a reset pin), and as a result there’s no GPIO for SS on this cable.

Ah. We’ve never really used any kind of serial before, so that escaped us. Not having programming or electrical mentors kinda messes things up for us a lot. I’ll pull up the pin diagram and get that resolved, hopefully that fixes it.

Does anyone know where I can get a Pixy2 to roborio cable? We got one and I can’t find another one anywhere. I believe we are using the SPI port on the roborio