Nonsense data from rotary encoder on RPi 4b

Thread Starter

gwfami

Joined Jan 18, 2018
50
I have just purchased a Taiss rotary encoder (E38S6-600-24G) to use on a Pi 4b project running the latest Bookworm OS. It's a 4 wire system with red and black for the power and white for the A phase and green for the B phase. I've attempted to connect it up by using what I could google on hooking up a rotary encode. Here's some sites that I have used: https://thepihut.com/blogs/raspberry-pi-tutorials/how-to-use-a-rotary-encoder-with-the-raspberry-pi, https://ozeki.hu/p_3054-how-to-setup-a-rotary-encoder-on-raspberry-pi.html and
.
The only difference is that I used the internal pull up/down resistors in the Pi and the encoder was powered from a separate 12V power source. I have the A phase connected to pin 17, and the B phase connected to pin 27.
Running the code from the sites above, turning the rotor has no effect on the output, regardless of the speed and direction it's turned, the values are just more or less random.
Either I'm doing something wrong (most likely), this encoder is incompatible with the Pi (not as likely) or the 600 P/R is something that the Pi gets confused on (maybe likely).
Google hasn't been my friend on this.
I'm hoping someone out there has done something similar and got it to work.
All help (sarcasm excepted) is GREATLY NEEDED and APPRECIATED.
 

k1ng 1337

Joined Sep 11, 2020
960
Do you understand how a rotary encoder works? The pull resistors will definitely have an effect because the system is probably looking for specific changes on phases A & B.

I recommend using Thonny to monitor the pins directly. Write some code to set a variable to true when Phase A goes high as well as for Phase B. The time between these pulses can be reduced to frequency which is proportional to how fast the encoder is turned. Be sure to disable the pull resistors for this method.
 

Sensacell

Joined Jun 19, 2012
3,453
Firstly- do you have a way to verify the voltage levels at the input? it is making clean transitions?

Secondly, I don't know how this code is reading the inputs, but at 600 PPR, any software-based idea will choke on the speed if you spin the rotor at any significant RPMs.
 

MaxHeadRoom

Joined Jul 18, 2013
28,698
Why are you using two Pull ups?
Just a pull up on the open collector is required using 5v??
You would have been better off with a RS485 output version..
 

nsaspook

Joined Aug 27, 2009
13,312
The OP might have smoked the RPi inputs feeding 12V into them. Hope your pi didn't get damaged...

The link in the OP post: https://thepihut.com/blogs/raspberry-pi-tutorials/how-to-use-a-rotary-encoder-with-the-raspberry-pi shows a proper 3.3V supply and logic value encoder used. 5V devices with pullup resistors (10k Ohm) that limit current can be used but the RPi pins are not spec'd to be 5v tolerant. It's better to use a level converter or a simple resistor divider to convert signals to the proper 3.3V logic.
https://forums.raspberrypi.com/viewtopic.php?t=227262

However inputting a 5V signal on a GPIO pin (not a GPIO header power pin) will destroy your PI, as RPI's GPIO pins are NOT 5V COMPATIBLE OR TOLERANT.
 

Thread Starter

gwfami

Joined Jan 18, 2018
50
Firstly- do you have a way to verify the voltage levels at the input? it is making clean transitions?

Secondly, I don't know how this code is reading the inputs, but at 600 PPR, any software-based idea will choke on the speed if you spin the rotor at any significant RPMs.
No
 

Thread Starter

gwfami

Joined Jan 18, 2018
50
The OP might have smoked the RPi inputs feeding 12V into them. Hope your pi didn't get damaged...

The link in the OP post: https://thepihut.com/blogs/raspberry-pi-tutorials/how-to-use-a-rotary-encoder-with-the-raspberry-pi shows a proper 3.3V supply and logic value encoder used. 5V devices with pullup resistors (10k Ohm) that limit current can be used but the RPi pins are not spec'd to be 5v tolerant. It's better to use a level converter or a simple resistor divider to convert signals to the proper 3.3V logic.
https://forums.raspberrypi.com/viewtopic.php?t=227262
I hope not. I'll check out the pins to see if it did.
 

Thread Starter

gwfami

Joined Jan 18, 2018
50
According to gpiotest, nothing has been harmed.

./gpiotest
This program checks the Pi's (user) gpios.

The program reads and writes all the gpios. Make sure NOTHING
is connected to the gpios during this test.

The program uses the pigpio daemon which must be running.

To start the daemon use the command sudo pigpiod.

Press the ENTER key to continue or ctrl-C to abort...

Testing...
Skipped non-user gpios: 0 1 28 29 30 31
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Failed user gpios: None
 

nsaspook

Joined Aug 27, 2009
13,312
According to gpiotest, nothing has been harmed.

./gpiotest
This program checks the Pi's (user) gpios.

The program reads and writes all the gpios. Make sure NOTHING
is connected to the gpios during this test.

The program uses the pigpio daemon which must be running.

To start the daemon use the command sudo pigpiod.

Press the ENTER key to continue or ctrl-C to abort...

Testing...
Skipped non-user gpios: 0 1 28 29 30 31
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Failed user gpios: None
Cool! I would run the encoder (Taiss/Incremental Rotary Encoder DC 5-24v Wide Voltage Power Supply) with 5V instead of 12V if possible and connect the pull-up resistors to 3.3V
1702665900427.png
Example connection diagram, connect outputs (skip Z if the encoder has no Z zero output) to the GPIO pins required by your software driver. Connect a meter on the DC volts scale from output A or B to Gnd and see if the voltage toggles on/off (close to 3.3v and then close to 0V) as you slowly turn the encoder shaft.
 

Thread Starter

gwfami

Joined Jan 18, 2018
50
Anyway to run this from the 5v gpio pin, use the internal pullup/down resistors on the pi and eliminate the external resistors?

Cool! I would run the encoder (Taiss/Incremental Rotary Encoder DC 5-24v Wide Voltage Power Supply) with 5V instead of 12V if possible and connect the pull-up resistors to 3.3V
View attachment 310069
Example connection diagram, connect outputs (skip Z if the encoder has no Z zero output) to the GPIO pins required by your software driver. Connect a meter on the DC volts scale from output A or B to Gnd and see if the voltage toggles on/off (close to 3.3v and then close to 0V) as you slowly turn the encoder shaft.
 

nsaspook

Joined Aug 27, 2009
13,312
Anyway to run this from the 5v gpio pin, use the internal pullup/down resistors on the pi and eliminate the external resistors?
Yes, you could connect the encoder power to the 5V gpio power output pin. The internal RPi pull-ups (to the 3.3V supply) might work but they are in the range of 50K ohm-65K ohm. You need to check the voltage levels with a meter to see if the logic levels are good.
 

MisterBill2

Joined Jan 23, 2018
18,583
The very first step, prior to connecting the encoder to anything else, should have been to use a multimeter to check the output voltages from the encoder.
If information about operating voltages is available that will be quite handy. It is always useful to understand what one is connecting to inputs of a processor module.
I am guessing that the encoder A, B, and Z outputs are open collector transistors, but a voltage meter can quickly verify that. If the outputs ARE open collector, then pull-up resistors to the desired logic HIGH voltage will be required.
After reading the rest of the posts I see that the problem is apparently solved. My advice would still be the correct way to start.
 

MaxHeadRoom

Joined Jul 18, 2013
28,698
I am guessing that the encoder A, B, and Z outputs are open collector transistors, but a voltage meter can quickly verify that. If the outputs ARE open collector, then pull-up resistors to the desired logic
No need to guess! :(
The Spec. Plainly states "the circuit output is NPN open collector output type" 5v - 25v!
 
Top