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