Measuring and Storing RPM of a motor with built in encoder

Hello,

I am a chemist who is trying to use a particle photon for research purposes. I am building a pump and I need to measure the speed of the pump. I am trying to use this motor (https://www.pololu.com/product/3269) I have been able to wire this motor up to run off of a 12V battery and and am using a L298N to control the motor speed. I have that code working with no problems. My next step is trying to interface the encoder that comes with the motor so I can calculate and plot the RPM as a function of time.

My problem I have no idea how to start this. I have found older example codes but I haven’t been able to get any to work. Is the motor to fast for the particle photon? Also, is there a way to store the motor speed so I can make some plots later on?

Thank you for any help or direction!

I guess this encoder provides you with one pulse per revolution, so I’d use an interrupt (see attachInterrupt()) and take the time between two events (see micros() or millis() depending on speed) to calculate the RPM from the revolution periode.

The encoder provides 2 pulse outputs for different revolution and direction sensing methods.

I’m guessing he only needs to measure the motor in 1 direction?

There should be an Arduino or Particle library already created for this purpose I would guess.

With two pulses, the easiest way to distinguish the direction is by reading the other pin in the ISR of the first pin HIGH will indicate one direction LOW the other, so you won’t need to attache two interrupts but only one.

And I guess (without actually reading thorugh all that blurb :wink: ) that per pin you’ll still only get one puls per revolution, right? Otherwise, the system will still be the same, just the math has to factor in the correct number of pulses per full rev.

1 Like

It signals 12 pulses per revolution up to 48 depending on how you read the state changes.

I would say this writeup is what he is looking for: https://www.pjrc.com/teensy/td_libs_Encoder.html

1 Like