US Digital E4P Encoder Not Giving Pulse Data

Here is the problem: after connecting a US Digital Encoder, it doesn’t seem to be returning any pulse data.

I wired it up by attaching Ground, 5V, and Channel A to the three prongs at Digital IO port 5 on the digital sidecar, and then connected Channel B to the signal prong at Digital IO port 6.

Here is the code I used:

#include "WPILib.h"

Encoder *myEncoder;
myEncoder = new Encoder(5,6);
myEncoder->SetDistancePerPulse(1); // Just something for testing.

//To print on the NetConsole Screen:
printf("Speed: %f
", myEncoder->GetRate());

Is there anything wrong with either the wiring or the code? Thanks!

How are you turning the shaft the encoder is on? How long are you waiting between calling Start() and calling GetRate()? The rate might be slow enough that it’s effectively zero. What does it return for the distance?

Similar to Alan’s comment - but if not obvious…you need to call “GetRate()” again and again in your OperatorControl() loop. Are you able to get printf() data via NetConsole? Or are you using SmartDashboard? If so, make sure you print out these items so you can get a sense of whether or not it is working properly. Also, if GetRate() is returning nothing of interest, I’d suggest calling GetRAW() and printing that out or plotting it on SmartDashboard. GetRAW should be an ever-increasing counter.

Now, if you’re doing all that and it’s not working, here’s what we did to diagnose a bad hardware situation…

If your inputs from the Encoder are on digital IO’s 5 and 6, plot the values of those digital inputs on 5 and 6 to ensure they are both changing when the shaft is spun. We found that one of our inputs was bad from the encoder and threw it in the trashcan.

// Testing encoder digital IO's without actually using the encoder class...
// This is a 'substitute diagnosis' for...
// Encoder enc(5, 6); which seems to be not working.
DigitalInput in1(5);
DigitalInput in2(6);
SmartDashboard* smarty = SmartDashboard::GetInstance();
int in1value, in2value;

while (IsOperatorControl())
  in1value = in1.Get();
  in2value = in2.Get();

  smarty->PutInt("In1", in1value);
  smarty->PutInt("In2", in2value);

If you don’t get a text box (which can be turned into a plot/chart for easier viewing) which is changing from ones to zeros and back over and over again, then your encoder is hooked up wrong, plugged into the wrong slots/IOs, or dead/broken.

bob - Team 1967 - The Janksters