Wheel encoder kit with Raspberry Pi

I am attempting to use the magnetic rotary encoder ROB-12629 on a standard yellow robot motor for a small 4WD vehicle.

I’ve mounted the hall effect sensor and the magnetic disk as described.

In Raspbian I have a .py file which I’ve attached an interrupt to the GPIO pin and am logging the total number of changes to the pin.

So, for one revolution of the outer wheel I should see something like 384 counts.

Problem is: I’m seeing THOUSANDS of counts per outer wheel revolution.

It seems to be the interrupt pin is logging changes in state induced by noise.

Question is: how do you (Sparkfun) wire up these encoders such that EMI induced when the motor itself is spinning does not trigger the GPIO pin state change, i.e. the state only changes based on the magnetic disk changing pole state?

All feedback encouraged! I’ve been dead in the water on this for 2 weeks now.

Steve

Hi Steve.

Are you using a pullup resistor on the output pin? If you’re not, try a 1K resistor and see if that helps.

Chris - thanks for your feedback. I have setup the GPIO pin with a pull-up resistor, so I think I am ok there.

I’ve been spending a considerable amount of time debugging this issue, and I think I may have a larger problem. Which I would really appreciate your thoughts on:

I am using the Sparkfun magentic rotary encoders on this 4-wheeled robotic platform: https://www.seeedstudio.com/4WD-Arduino … p-658.html

If I manually spin the wheel upon which I have mounted one of the Sparkfun encoders…when I monitor the counts on the Raspberry Pi I am now seeing the expected number.

Problem is!..when I manually spin any of the other 3 wheels, and NOT the wheel with the mounted Sparkfun encoder…I can also get the counts to increase as registered by the Raspberry Pi.

It seems I may have some magnetic coupling issues here. I am wondering…how do your customers use multiple rotary encoders on a vehicle and prevent them from coupling into each other? Furthermore, how do you use the Sparkfun encoder on a multi-wheeled vehicle and prevent the magnetic field induced by the rotating motor(s) from coupling into the encoder readings?

All feedback encouraged/welcome. I nearing desperation at this point.

Thanks!

Steve

Hi Steve.

We’ve not encountered this before with these sensors. We’ve used them successfully in our Shadow Chassis with the motors and sensors mounted like this:

Redbot_Kit_Brian_Revisions-08.jpg

Can you send a photo showing how the sensors are mounted in relationship with your motors? I’m wondering if they are mounted too close together and the sensor is mounted too close to another motor.

Send a pic and I may be able to offer some suggestions.

Chris - thanks for your feedback.

Here are two images of my setup:

  1. I have one encoder mounted on the motor shaft of the front right motor, then the other diagonally mounted on the motor shaft of the back left motor.

  2. I am powering these two motors using an L298N H-bridge. The front left and back right motors are dummies, i.e. I’ve removed the gearboxes and they are free to rotate and they are not connected to the H-bridge.

http://www.terpconnect.umd.edu/~mitchels/temp/01.jpg

http://www.terpconnect.umd.edu/~mitchels/temp/02.jpg

After more debugging, I’ve narrowed down the issue as follows:

  1. If I leave the H-bridge powered OFF, I am able to spin the front right and back left motors by hand and get accurate readings on the Raspberry Pi from the Sparkfun motor encoders.

  2. HOWEVER…as soon as I power the H-bridge ON…when I spin the motors by hand I get coupling from one motor encoder reading into the next. Furthermore, I’m getting 2000-3000 encoder counts per wheel rotation when I should be seeing something like 960 (these motors have a 1:120 gear ratio).

Other notes: I am powering the H-bridge from a AA battery pack, while I am powering the Sparkfun encoders from 3.3V GPIO pins on the RPi. I have connected a ground pin from the RPi to the ground pin on the H-bridge. I am powering the RPi using a USB battery pack.

All feedback greatly encouraged! Thanks!!

Steve

Hi Steve.

I think two different things are happening here that are causing your trouble.

  • - The encoder discs for the opposite side motors are so close to one another that the sensor for the right hand motor is seeing input from the left hand motors encoder disc.
  • - You have the sensor mounted on the side of the motor and since the motor has and uses magnets to work the sensor is likely picking up some of that magnetic flux and mistaking it for the disc.
  • Because your chassis is so tight, the only solution I can think of would be to mount the encoder discs onto the part of the axle that’s inside the chassis. (see photo below) That would keep the sensors further away from the motor and space the discs out far enough that they shouldn’t interfere with each other. The discs will spin a lot slower and that will reduce your resolution a bit but this would allow you to use the same parts you have now.