Encoders made EASY?

OK, I’m old school, when I see + connect it on source power and GRD on ground.

Hi @ToFF!
The answer is no. Simply I followed the @riban recommendation:

"Ignore + pin.
Connect GND pin to a common ground / OV.
Connect the SW pin as the switch.
CLK & DT are the two encoder pins."

2 Likes

Go with this.

1 Like

Of course. Thanks

Okay - I have a few minutes at lunch so I will try to diagnose the issue. This is what I have done so far:

  • Flashed the latest test image to uSD
  • Booted RPi400 to Zynthian and waited for it to finish setup
  • Note: The RPi400 does not have audio so the default settings fail
  • Connected USB audio device
  • Connected network and logged into webconf
  • Used webconf terminal to find the name of my soundcard: aplay -l and found the USB audio interface is called “Device” (it is a cheap thing I have for adhoc testing like this)
  • Changed “Kit” to “Custom”
  • Changed “Jackd Options” to “-P 70 -t 2000 -s -d alsa -d hw:Device -r 44100 -p 256 -n 2 -X raw”
  • Asserted “Disable RBPi Audio”
  • Rebooted
  • Zynthian now starts up because it has a valid soundcard for JACK to use
  • Enabled VNC (so that I don’t need a screen hanging off the RPi400 - makes it easier to access the 40-way header
  • Changed “Wiring Layout” to “Custom” and set GPI pins:
    • Encoders A-pins : 0,4,6,26
    • Encoders B-pins : 2,5,21,23
    • Switches pins : 3,12,22,27
  • Reboot and Zynthian starts okay and switches seem to work - I haven’t tested all as I don’t have time to wire up but the few I tested worked.

The issue you seem to be having is using pins that are not available / free, i.e. in use for some other purpose. (The OS and drivers use some of these pins.)

The physical pin connection on the 40-way header becomes:

ENC_A ENC_B SWITCH GND
11 13 15 9
16 18 19 14
22 29 31 30
32 33 36 34

I tried to keep away from pins that may be used by some Zynthian builds, e.g. I2S, Tx/Rx, etc. I hope this helps.

2 Likes

Thank you @riban for your tests!

Yesterday, @Keeze101 provided me a new wiring diagram. I tested it and… it works almost well.
I have done some minor corrections (i.e. encoder 3 was labelled as GND pin 19, when in reality the nearer and real GND is the 9 pin) and have added some clarifying details for newbies like me

My main problem now is that I cannot navigate in the MAIN screen with the encoders (of course I can do it touching the keyboard arrow-keys).
When I touch any encoder, jumps to other screen but is impossible to displace up and down in MAIN screen with short, bold or any kind of touches (or I am missing something I cannot figure out as the odd pinning in raspberry :fearful:)

In next video you can make an idea:

1 Like

Be methodical.
Firstly make sure every encoder works by substituting each one on a set of GPIO pins you know work. So work throu each encoder in turn on the selct pins if you know those are ok…

Once you know your hardware is ok, proceed to enable each encoder in turn.

The important thing is you make sure the hardware is all ok before trying to fault find the software side.

1 Like

Hi @wyleu!

I am trying to be as methodical as possible.
All the hardware was working fine, until the encoders arrival.
All my prior questions were answered and as a result, my pi400 + UMC404HD + 7"screen are performing really well.

But the @Keeze101 wiring signalled a before and after.
Until yesterday all the tests gave me red flags. Now you can see no red alerts and encoders working in the video.

I guess I am facing a minor issue, but as you can imagine, I have no idea why. In my case, all the wiring schemes I used until yesterday, might be outdated when using with a PI400 (the most recent in fact, If I´m not mistaken)

It looks like the config doesn’t match the wiring so encoder rotation is triggering button pressed. You have to check that the physical wiring matches the configuration in webconf wiring page, like I showed earlier.

1 Like

I will investigate. Thanks

@riban can it be that the caps and resistors on the KY040 encoders are interfering? Because if @erasmo wired everything correct, I think it should work… (I provided a slightly different layout yesterday, so it can also be that I made a woopsy)

Anything is possible but let’s confirm that the encoders and switches are connected as per the chart and that webconf is configured with the correct settings, which for @Keeze101’s layout would be:

Encoders A-pins: 22,21,0,4
Encoders B-pins: 23,26,2,5
Switches Pins: 25,27,3,6
MCP23017 I2C Address : Leave blank
MCP23017 INT-A Pin: Leave as Default
MCP23017 INT-B Pin: Leave as Default
Zynaptik Config: Leave blank
ADS1115 I2C Address: Leave blank
MCP4728 I2C Address: Leave blank
Customization Profile: V4 Studio

1 Like

When I disconnect the + pin of the KY-040 encoders, my Zynthian behaves exactly like this. With the + pins connected, the encoders rotate without any problems.

1 Like

Ah! Maybe the onboard pull-up resistors are too small and effectively connect the DT & CLK pins. I think some have removed these resistors but connecting to 3.3V should also work.

1 Like

My encoders rotate without any problems, but the switches are problematic:

Update: I use the onscreen buttons instead of the switches.

1 Like

Hi @riban,

A minutes ago I tested your suggested wiring as reflected in next chart

I have got the same I had with the @Keeze101 wiring. Again, when in MAIN screen, I give any turn to any encoder, the same erratic behaviour appears sending me immediately to other screens/functions, making displacement by menu of MAIN screen impossible

1 Like

Now I have changed in zynthian.local, the encoders A with encoders B and the response is practically identical. Quite a bit strange, does not?

Moreover: may this have any connection with the fact than raspi400 comes with a default enabled keyboard?

The keyboard is internaly connected to the usb controller (via a Holtek HT45R0072 mcu) so it should not interfere with the GPIO’s Can you try to connect the 3.3v line to the + of the encoders?

I have never used the KY040 encoders. Perhaps get hold of some plain (but good) encoders (like the ALPS STEC12E08)

A new approach?

erasmo4:22 pm

Today I just discovered that in the zynthian shop are selling still “Zynaptik-3 module” and though I initially discarded it as is intended to implement midi, after reading more carefully I have seen this: " The Zynaptik-3 MIDI module integrates the 3 x standard MIDI ports only (IN/OUT/THRU). The parts for extended input/output are not soldered on, so, unless you solder the parts by hand, it can’t be used as a CV-Gate interface or for connecting rotaries & switches." –Unless you solder by hand…"

Does anybody think than this may be a way to implement encoders instead of GPIO direct?
I yes, what should I need, besides encoders, to make it work?

1 Like

Of course, in fact it’s designed for this. But the version we have for selling (MIDI version) does not have soldered the MCP23017 chip needed for managing the encoders. You could solder it, but be warned that this chip is not easy to solder by hand. Pin pitch is 0.5mm! I’ve soldered a few ones and my skin start sweating only by thinking of it. The good part is that if you get it soldered on, you can connect the official controllers and everything would work nicely out the box.

I’ve marked in red the parts you have to solder. I could send you the parts with the Zynaptik-MIDI, but please, don’t ask me to solder them :sweat_smile:

Up to you!

1 Like