gwfami
Posts: 45
Joined: Thu Oct 25, 2018 4:04 am

Hooking up a rotary encoder to raspberry pi 4

Fri Dec 08, 2023 9:28 pm

here are a ton of questions on this, and I'm pretty new at working with rotary encoders. I purchased this one Taiss E38S6-600-24G https://www.amazon.com/dp/B07MX1SYXB?th=1, thinking (incorrectly I might add) that it would be a simple thing to connect and read the position. The encoder itself will be used to measure the length of a cord pulled through a machine, allowing the machine to stop pulling when a length is reached. I'm planning on using a simple wheel system on the encode and connecting it to a separate power source.

I've since found that it the Pi will probably not read the correct counts and will more then likely miss some, due to other processes running on it.

I've seen where people use external counter boards then query them as to the position, or use the Pigpio system to get the counts.

I'll admit this is my mistake, as I didn't do enough research before purchasing it, although I have been working on it since.

My question is this, what is the best way to use the encoder and ensure that no counts are missed? Separate board, Pigio, something else?

Any and all help is appreciated.

ame
Posts: 8766
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Hooking up a rotary encoder to raspberry pi 4

Fri Dec 08, 2023 9:46 pm

It depends.

If you hook up the encoder to a Pi and run some tests you can determine if any pulses are dropped. The chances of losing a pulse depend on how fast the encoder is turning, and whether you are polling the sensor or using interrupts.

If you offload the task to a microcontroller you still have to test it, but in general the micro can be dedicated to the task and less likely to miss pulses.
Oh no, not again.

ghp
Posts: 3680
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: Hooking up a rotary encoder to raspberry pi 4

Fri Dec 08, 2023 11:26 pm

The encoder itself will be used to measure the length of a cord pulled through a machine
Is it possible to calculate the number of pulses and frequency created, perhaps you know the speed of the cord and the geometrics of the wheel ?

If you have an estimate on pulse frequency, then use a raspberry pico and let it create a well defined pulse train (signal generator) and check with your raspberry if results are the same. With such a setup you can do a proof of concept without modifying the machine.

Real live could be a bit more complicated especially if distance from encoder to Pi is more than some 30cm and electrical interference problems, noise, mechanical vibrations are involved. This could be a reason to place a microcontroller close to encoder and have the long distance with e.g. an RS485 line. Or with industrial plc type 24V data lines.

Return to “Automation, sensing and robotics”