Encoders directly to the GPIO of the Pi 4?

First, I apologise for misinterpreting the photo of the Raspberry Pi header the wrong way round. I have drawn out a table that I think represents your wiring:

Use GPIO Rpi Header Encoder pin Colour
Encoder 1 A-pin 10 24 DT White
Encoder 1 B-pin 11 26 CLK Black
Encoder 1 Switch-pin 14 23 SW Slate
Encoder 1 Common Ground 25 GND Violet
Encoder 2 A-pin 21 29 DT Green
Encoder 2 B-pin 22 31 CK Blue
Encoder 2 Switch-pin 26 32 SW Yellow
Encoder 2 Common Ground 30 GND Orange
Encoder 3 A-pin 23 33 DT Slate
Encoder 3 B-pin 24 35 CK Violet
Encoder 3 Switch-pin 27 36 SW White
Encoder 3 Common Ground 34 GND Black
Encoder 4 A-pin 28 38 DT Slate
Encoder 4 B-pin 29 40 CLK Red
Encoder 4 Switch-pin 25 37 SW Black
Encoder 4 Common Ground 39 GND White

Please confirm this is correct. (I had to predict some because they were not visible within photos.)

The rotary encoder will close its two switches in a quadrature manner as you rotate it. In any rest position both switches will be open, i.e. there will be no contact between DT or CLK and GND. As you rotate from one detent to the next the switches change: First DT will close then CLK will close then DT will open then CLK will open as you return to the next detent rest position. Rotating in opposite direction will cause opposite behaviour. This means that to detect encoder rotation you must run the gpio command whilst holding the encoder partially between detents. I found this tricky to get reliable results . Also, the GPIO must be configured as input with pull-up which may not be the case if Zynthian is not running. (You could do this manually with some code.) I wouldn’t try to test encoder rotation with gpio command unless you are desperate! With the wiring in this table and the webconf from your last posted screenshot have you tried Zynthian and what is its behaviour? It should work assuming you are not using these pins for other purposes for example you should configure soundcard to USB or internal sound and display to HDMI.

2 Likes