Encoder - ArduinoUno - Basic test issues

Hello,

I am struggling with interfacing “Encoder for Pololu Wheel 42x19mm”.
I have Arduino-UNO and I have just have connected encoder.
I have Encoder OutputA connected to Arduino Pin9, OutputB to Arduino 8, and a Ground and power to Encoder.

I have following simple code. It compiles and uploads but Serial monitor prints
"M1 1"
“M2 0”

#include <PololuWheelEncoders.h>
PololuWheelEncoders encoders;
void setup() {
Serial.begin(9600);
encoders_init(PB0, PB1, PB2, PB3);
pinMode(8,INPUT);
pinMode(9,INPUT);
}

I would very much appreciate your help.

Sincerely,

Hi,

I am missing some basic. I would appreciate if you can please point me in right direction.

I am struggling with interfacing “Encoder for Pololu Wheel 42x19mm”.
I have Arduino-UNO and I have just have connected encoder.
I have installed Pololu Arduino Library.
I have an Encoder OutputA connected to Arduino Pin9, OutputB to Arduino 8, and a Ground and power to Encoder.

I have following simple code. It compiles and uploads but Serial monitor prints
"M1 1"
“M2 0”

[code]#include <PololuWheelEncoders.h>
PololuWheelEncoders encoders;
void setup() {
Serial.begin(9600);
encoders_init(PB0, PB1, PB2, PB3);
pinMode(8,INPUT);
pinMode(9,INPUT);
}

void loop() {
int m1 = PololuWheelEncoders::getCountsM1();
Serial.print("M1: ");
Serial.println(m1);

int m2 = PololuWheelEncoders::getCountsM2();
Serial.print("M2: ");
Serial.println(m2);

if (encoders_check_error_m1())
Serial.println(“M1 in error”);

if (encoders_check_error_m2())
Serial.println(“M2 in error”);

delay(1000);
}[/code]

I would very much appreciate your help.

Sincerely,

Hello.

I briefly looked at your code and did not notice anything obviously wrong. It sounds like you only have one encoder connected to your Arduino Uno. If that is the case, you might try passing a non-existent pin number for the extra two pins like 255 (e.g. encoders_init(PB0,PB2, 255, 255)).

Alternatively, you might consider trying an Arduino encoder library like the “Encoder Library”, which supports using a single encoder (instead of two like our library).

- Amanda