Hi all,
We are beginners and struggle into the wiring of our absolute external SRX MAG encoder. As far as I understand, it seems we cannot easily use the alternate encoder mode and plug our Mag encoder directly to the data port on the top of the Spark unless we build some adapter cable or board…tricky …
I read as well in GitHub - Jagwires7443/SwerveSensorInterfaceBoard: Board to Interface an SRX MAG ENCODER to a SPARK MAX and a roboRIO
that a simpler way to handle this is to leave the SPARK MAX out of things and to simply connect pins 2 (+5V), 9 (PWM), and 10 (GND) from the SRX MAG ENCODER to a roboRIO digital input. …but the post is not too recent so I would hope that things have evolved…
what would be the easiest and more straightforward option?
If you already have the SRX mag hardware and are okay with running control loops on the RoboRIO, that is the easiest. CTREsells breakout boards for the little IDC cables-- I wouldn’t recommend trying to pry the wires apart otherwise.
You can also use two of those breakout boards in series (SparkMax → IDC → breakout board → soldered jumpers → breakout board → IDC → SRX mag) if you want the onboard control loops.
Those PCBs also work well, I made a different version a few months ago that fits onto the SparkMAX better.
If you don’t already have the SRX mag hardware, get these. They’re a really good product.
There are alternative ways: the way we have done it is to the Sparkmax data port, but as you said it is a little tricky - you take the 5V power and the ground Pins 2 & 9 and connect them to pins 2 & 10, but you need to take the PWM output from the mag encoder pin 9 and connect it to pin 6 on the Sparkmax data port - this can be done either by intricate splicing of a ribbon wire or using either CTRE or REV breakout boards.
To the RoboRio I believe you would take the PWM output and connect it to a PWM input tot he roborio, along with the 5V and gnd. Alternatively you may be able to take the analog output from the mag encoder and plug it into the analog input on the RoboRio, but we have not personally done either of these.
We have been using these two parts, from Adafruit:
We place these fairly close to the encoders and run a PWM-style cable back to the roboRIO. This set-up works very well for us. We put heat-shrink over the completed assembly to relive strain on the wires and keep the PWM cables from flexing right where they are soldered to the board. The board is labeled for a different application, so pay attention to the pin numbers and not the labels on the board.
I personally like this combo pack if you’re more inclined to buy from Amazon — two cables and two breakouts for slightly cheaper. Just keep in mind, of course, the silkscreens don’t correspond to the IDC pinouts of FRC products.
As for programming PWM encoders that are attached to the Spark MAX data port, keep in mind you’ll want to use getAbsoluteEncoder and SparkMaxAbsoluteEncoder rather than the alternate or analog encoders. Since the product I work on happens to be intended to be used in this application, we have a short guide on programming PWM encoders with the Spark MAX here.