Trouble with Rev Through Bore encoder

/* I’m moving this topic to programming, it looks like the wiring is okay

Greetings! I feel like as a 2003 rookie year team we should have posted here before, but the programming and electronics team is fairly new, so here goes out first post.

We’re having some trouble getting the Rev through bore encoder reading in either absolute or quadrature modes.

We plugged in a limit switch to the DIO to make sure that the pins were working and everything went swimmingly, but as soon as we try the encoder we get nothing. The programming team is new to encoders (and programming), so any help would be appreciated!

Looking at the SmartDashboard we aren’t even getting values from the encoders, so I want to make sure that we aren’t doing something wrong before sending it back to Rev.

Here is our quadrature wiring and code:
In the picture the motor controller is next to the RoboRio, but the through bore encoder is actually plugged directly in to the RoboRio via the jst->dupont adapter

package frc.robot;

import edu.wpi.first.wpilibj.Encoder;

import edu.wpi.first.wpilibj.TimedRobot;

import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

public class Robot extends TimedRobot {

private static final String kDefaultAuto = “Default”;

private static final String kCustomAuto = “My Auto”;

private String m_autoSelected;

private final SendableChooser m_chooser = new SendableChooser<>();

private Encoder throughBore;

private int ticks;

private int rawTicks;

@Override

public void robotInit() {

m_chooser.setDefaultOption("Default Auto", kDefaultAuto);

m_chooser.addOption("My Auto", kCustomAuto);

SmartDashboard.putData("Auto choices", m_chooser);

throughBore = new Encoder(7, 8, 9);

}

@Override

public void robotPeriodic() {

ticks = throughBore.get();

rawTicks = throughBore.getRaw();

SmartDashboard.putNumber("Encoder value", ticks);

SmartDashboard.putNumber("Raw encoder value", rawTicks);

}
// the rest of the code below is the normal timed robot

I can’t put another picture in, but imagine a pic of the white abs wire plugged into DIO 9 with the other three quad wires unplugged.

package frc.robot;

import edu.wpi.first.wpilibj.DigitalInput;

import edu.wpi.first.wpilibj.DutyCycleEncoder;

import edu.wpi.first.wpilibj.TimedRobot;

import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

public class Robot extends TimedRobot {

private static final String kDefaultAuto = “Default”;

private static final String kCustomAuto = “My Auto”;

private String m_autoSelected;

private final SendableChooser m_chooser = new SendableChooser<>();

private DutyCycleEncoder throughBore;

private double ticks;

private double freq;

private boolean isConn;

private DigitalInput limit;

private Boolean limitGet;

@Override

public void robotInit() {

m_chooser.setDefaultOption("Default Auto", kDefaultAuto);

m_chooser.addOption("My Auto", kCustomAuto);

SmartDashboard.putData("Auto choices", m_chooser);

throughBore = new DutyCycleEncoder(9);

throughBore.setConnectedFrequencyThreshold(900);



limit = new DigitalInput(0);

}

@Override

public void robotPeriodic() {

ticks = throughBore.get();

freq = throughBore.getFrequency();

isConn = throughBore.isConnected();

limitGet = limit.get();

SmartDashboard.putNumber("Encoder value", ticks);

SmartDashboard.putNumber("Encoder frequency", freq);

SmartDashboard.putBoolean("Encoder is connected", isConn);

SmartDashboard.putBoolean("Limit is pressed", limitGet);

}
// The rest of the code below is the normal timed robot

The WPI folks might need to chime in for a code review, but could you make sure that the switch on the side of the Through Bore Encoder is in the “A” position?

Yes sir, I read on the reference material that the S mode is for future use. We have our’s in A mode.

Here is a pic of the absolute wiring going from the DIO on the RoboRio through the jst->dupont adapter to the encoder.

Did you double-check that the JST end of the cable is fully inserted into the encoder?

All connections are tight, I am mostly hoping to have someone that has got these working verify that it is wired correctly. If so I will change this over to a coding issue.

The first photo looks mostly right, assuming the green, yellow, and blue wires are your encoder signals (A B Z/index). Red and black are power to the encoder. You only need one pair. Make sure the others are well insulated.

Does anyone know if this encoder needs external pull-up resistors?

I’m not sure what your showing in the second photo…

Everything looks good from a wiring standpoint.

It does not.

The second photo is what we are hoping is the wiring for the absolute mode on the encoder. We got the wiring from the documentation on the Rev website. The top picture is for quadrature mode. We’ve tried the quadrature mode both with and without the index wire to no avail. We aren’t even getting the encoder to show if it is connected on either absolute or quad, so I wanted to have someone verify that we have it wired correctly before we move this thread to programming. Thanks again for all of your help!

Thanks! I’ll push this over to the programming thread and see if it is a coding issue.

Did you post this again in programming? We’re doing the exact same thing and are hoping to get some insight as well.

One thing to check and make sure is that you don’t have a short on the 5v rail (Make sure your power light is green, not red, and the DS would tell you as well). That would cause the sensor to not get power, but a limit switch would still work since the pullup is on the 3.3v rail.

Past that, both modes definitely do work in WPILib, and DutyCycleEncoder was primarily tested with a hex bore encoder.

Programming wise I see a possible problem in how you are instantiating the encoder. We do private final Encoder encoder = new Encoder(0, 1, true, CounterBase.EncodingType.k4X); Can you try this and report back?

Not sure why you are using 3 DIO ports for the encoder. We are using the Rev Throughbore encoder in quadrature mode successfully with just 2 DIO ports. Our code looks like:
throughBore = new Encoder(0, 1);
Only 2 of 3-wire cables (Black-Red-Blue and Black-Red-Yellow) are plugged into the DIO ports, same as what we do for E4T miniature optical encoder.

No luck. Do you call the .get method on the encoder object to get the encoder value? We used ticks = throughBore.get(); in RobotPeriodic to assign the encoder value to a variable.

We put in the index wire and added the third argument to see if it helped us get everything working (it didn’t). We tried it with just the two wires and the code like you had it but that didn’t work either.

Try using the PWM output (just needs a single DIO!) with DutyCycleEncoder.

Just got a new encoder in the mail and boom, this code worked and everything reads just fine. Looks like Rev shipped us a bad encoder the first time. The other two that we got today work in both absolute and quad mode. Thanks for everything!

1 Like

Please send us an email as [email protected] so that we can make it right.

Is it possible that at any point were power and ground reversed? Each encoder is tested and calibrated at the factory, so I’d like to see if we can figure out what happened.

Probably not, we were using the JST to dupont connectors, on the jst side those are keyed so that they can’t go in backwards and the power wire on the dupont is in the middle, so that couldn’t be reversed no matter how you put it in. I just sent an email out to Rev support, I’m sure we’ll get it sorted out- we’ve been buying from them for years and have never had a problem.