Optical encoding with Sabertooth 2x25 broken

The encoder readings are fine when the wheel is turned manually.

But when the Sabertooth drives the wheels via R/C controller mode, they increase at a random, high rate.

Should I ground the Arduino to the batteries?

Sketch on a mega

volatile int state = LOW;
int clicks = 0;
void setup()
{
  
  Serial.begin(115200);
  attachInterrupt(5, wheel_tic, RISING);
}

void loop()
{
  //digitalWrite(pin, state);
   Serial.print("CLICKS: ");
  Serial.println(clicks);
  delay(1000);
}

void wheel_tic()
{
  clicks++;  
}

Output:

CLICKS: 0
CLICKS: 0
CLICKS: 0
CLICKS: 0
CLICKS: 0
CLICKS: 0
CLICKS: 0
CLICKS: 0
CLICKS: 0
CLICKS: 0
CLICKS: 0
CLICKS: 1 # Manually turning the wheel
CLICKS: 1
CLICKS: 2
CLICKS: 3
CLICKS: 4
CLICKS: 4
CLICKS: 5
CLICKS: 6
CLICKS: 7
CLICKS: 8
CLICKS: 9
CLICKS: 9
CLICKS: 10
CLICKS: 10
CLICKS: 1371 #Using the Sabertooth
CLICKS: 2798
CLICKS: 4397
CLICKS: 6562
CLICKS: 7711
CLICKS: 9414
CLICKS: 11096
CLICKS: 12130
CLICKS: 12130
CLICKS: 12130
CLICKS: 12130
CLICKS: 12130
CLICKS: 12130
CLICKS: 12130

Should I ground the Arduino to the batteries?

That question in particular makes me go hmm. Are you using multiple power sources (batteries, power supplies, whatever)? If so, you have to make sure you have a common ground for everything to work properly together. On the flip side, you don't want to get carried away with tying all sorts of grounds together or you could create a ground loop that will also be a source of noise.

If you're using two batteries, tie their grounds together, then send this common ground to each device that needs power, and of course tie the positive of the appropriate battery to each device as well. One battery will power the Sabertooth motor controller, and the other will power the Arduino and encoder. Do not tie grounds together between devices though.

Thanks for your reply.

Yes, I have 2 12v batteries wired in series powering the sabertooth. The arduino that listens to the optical encoders are powered by the usb voltage coming from the laptop. I was afraid of wiring the ground on the arduino to the 12v ground. But it sounds like that is the right thing to do?

Thanks again for your help.

I was afraid of wiring the ground on the arduino to the 12v ground. But it sounds like that is the right thing to do?

Nothing to be afraid of there. It is the right thing to do and it is necessary to do. So long as you keep the positive lines separate, you will be fine.

I plan on making the common ground connection this weekend. I really appreciate the assistance.

I'm not familiar with the sabertooth, but in general DC motors create a lot of EMI with their brushes.
Probably you're reading the PWM signals-echo?
Therefore they need ceramic capacitors between plus/minus and the housing as well.

Uploaded with ImageShack.us

good luck
olaf

I am doing a big bot project with the sabertooth 2X60 but I got the Kangaroo X2 also, It does all the encoder work for me. leaves the Arduino free for more important tasks like speed, distance, and direction...