Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Wheel encoder with Raspberry Pi 3


I am planning to use the magnetic wheel encoders, product ID, 1523 with Raspberry Pi 3.

Do you have any example code to read the encoder counts with Raspberry Pi 3?

Thank you.



We do not have any example code specifically for the reading those magnetic wheel encoders directly from a Raspberry Pi (3). I do not expect the Raspberry Pi to be able to reliably read quadrature encoder signals, since it does not have a real-time operating system. You will probably need to use another device to read those signals. To read the encoder values you might consider using one of our A-Star 32U4 Robot Controllers or the Romi 32U4 Control Board, which are designed to work with the Raspberry Pi. We have a code example for the Romi 32U4 for reading quadrature encoders. You can see that example under the “examples” folder on its GitHub page.

- Amanda


Thank you for the reply. I am planning to use Sub-Micro Plastic Planetary Gear motors (136:1) with Raspberry Pi 3.

Wheel encoders:
Due to space constraints, will it be OK to use A-Star 32U4 Micro for wheel encoders?

Motor control:
I initially thought of using DRV8835 Dual Motor Driver Carrier, with Raspberry Pi.
Can A-star also drive the motors through this motor driver?

If micro-controller drives both motors and encoders, is it possible to use Baby Orangutan which also has small size motor driver.

Thank you for your support.


Any of the A-Star 32U4 programmable controllers will work with our magnetic wheel encoders and DRV8835 Dual Motor Driver Carrier, and yes, the Baby Orangutan could work for you, but to program it you will need to use an AVR programmer like our USB AVR programmer or USB AVR programmer v2 (which is a newer version).

It sounds like you are still planning to use the Raspberry Pi 3 in your setup. If so, the A-Star 32U4 robot controller still seems like the most appropriate choice, since it already includes dual motor drivers and the ATmega32U4 microcontroller and is specifically designed to work with the Raspberry Pi. The picture below should give some perspective of the amount of space the A-Star 32U4 robot controller would take when connected to a Raspberry Pi:

- Amanda


Hello Amanda,

I will go ahead with A* as suggested by you. Will the encoder example code in the example of Romi work for A* too?

Thank you.


The encoders example in the Romi 32U4 Arduino library will not work as is, because the Romi 32U4 robot uses XOR gates to combine the channels (A and B) of each encoder to use only one interrupt, which the A-Star 32U4 robot controllers do not. You would need to modify the Romi32U4Encoders library or add XOR gates between the pins you plan to use for each encoder to get that example to work with the A-Star 32U4 robot controller.

It would probably be easier to use one of the Arduino libraries for quadrature encoders. You can find those libraries on the “Reading Rotary Encoders” page on the Arduino website.

By the way, you might find this thread about using the Zumo32U4Encoders library for the A-Star 32U4 SV robot controller helpful.

- Amanda


Thank you for sharing the information. It was quite helpful to understand.