Hello and first questions for encoder wiring

Hi everyone,

first I want to say hello to this lovely community, since I am totally new to the board and to RPi stuff in general. I managed to assemble a basic Zynthian using a RPi5 with a 8" Waveshare HDMI Touch connected to my Focusrite Scarlett 2i4 and was already able to play some music, pushing some gigabyte-ish Steinway D samples to the machine and already used it in my bands rehearsal.

Next I wanted to put everything in a nice wooden cigar box and am now in the process of ordering stuff for it. Plans are for now:

  • 4 Encoders to GPIO
  • replace Focusrite with Hifiberry DAC+/2 ADC and add stereo I/O Jacks

Like already mentioned, I am completely new to the topic and could need some help. You can imagine I have tons of questions already, but to not flood this forum I’ll start with the encoder subject. I promise, I already read through all threads you can find by search terms “encoder”, “GPIO”, “MCP23017” and so on.

I created this table for my own conciderations:

Notes BCM WPI Name Pin Pin Name WPI BCM Notes
Evtl. + All Enc 3.3v 1 2 5v
X HifiB 2 8 SDA.1 3 4 5v
X HifiB 3 9 SCL.1 5 6 GND 0v free GND
4 7 GPIO.7 7 8 TxD 15 14 X ZynMid
free GND GND 0v 9 10 RxD 16 15 X ZynMid
* 17 0 GPIO.0 11 12 GPIO.1 1 18 X HifiB
* 27 2 GPIO.2 13 14 GND 0v free GND
* 22 3 GPIO.3 15 16 GPIO.4 4 23 *
3.3v 17 18 GPIO.5 5 24 *
10 12 MOSI 19 20 GND 0v free GND
9 13 MISO 21 22 GPIO.6 6 25 *
11 14 SCLK 23 24 CE0 10 8
free GND GND 0v 25 26 CE1 11 7
0 30 SDA.0 27 28 SCL.0 31 1
* 5 21 GPIO.21 29 30 GND 0v free GND
* 6 22 GPIO.22 31 32 GPIO.26 26 12 *
* 13 23 GPIO.23 33 34 GND 0v free GND
X HifiB 19 24 GPIO.24 35 36 GPIO.27 27 16 *
* 26 25 GPIO.25 37 38 GPIO.28 28 20 X HifiB
free GND GND 0v 39 40 GPIO.29 29 21 X HifiB

While reading the corresponding thread about wiring encoders to RPi4 I cam across some wiring suggestions frim @wyleu . I noticed that both of them seem to use pins another post of the same thread recommends to avoid. As far as I understand from corresponding sources I should avoid Pins 3, 5, 8, 10, 12, 35, 38, 40 because of Zynthians Midi I/O and used Pins of the HifiBerry DACs. So I assume I could use the GPIOs marked with a “*” in any order. Do I get that right?

The other question is about the oftentimes mentioned capacitors. I understood from this forum that they might be needed, or not. From what I understood, I might consider to buy 4 100nF caps and 8 10nF caps and place them between the A(CLK), B(DT) and Switch(SW) pins of the encoder and the corresponding GPIO. My question would be if I can use any type of caps, like these. What I also learned by reading these threads is that I might or might not unsolder a resistor on the encoders pcb.

Ok, I’ll stop myself here. Thanks in advance for your kind help already.

Hi @hannesmenzel! A warm welcome.

I would avoid using pins: 12, 13, 15, 16, 18, 22, 35, 37, 38 & 40 which are the I2S (audio interface) pins on RPi5. You may not be using all of the I2S ports if you use the HifiBerry 2 in, 2 out device but if you want more audio inputs/outputs you might want to use these pins. Of course, if you are sure you only want 2x2 and cannot find sufficient other GPIO then you will need to use these. (There are only 12 spare GPIO that will all be required for 4 encoders plus switches.)

No, they need to go between the encoder/switch pins and ground.

ZynScreen_v1.5 schematics and V5 control schematics contain everything you need to wire the encoders using an i2c-I/O chip named MCP23017. These are available on complete breakouts and provide an elegant way to connect buttons and things to Pi and you don’t get into problems with GPIO usage. Run the chip at 3.3V (!) as Pi’s GPIO are only 3.3V tolerant.
Capacitors at ecoders and button switches are never in-series, but bypassing to ground, as sort of denoising (some call it debouncing, which it is not).
47nF on each pin to ground are quite enough. Larger capacities will provoke flatter slew, making even more transition noise on non-schmitt-triggered inputs, then causing flase triggers.

Thank you for your fast answer. I considered the direct gpio layout since for now the 4 clickable encoders will be enough for a while. But I guess sooner or later I’ll consider the MCP anyway for some button action.

For the capacitors capacity: It was suggested here to use different capacity for encoders and switches. So what would you recommend?

Oh no, the table I used might be on the basis of the wrong RPi. I have to slow down a bit. I referred to the mentioned thread and the HifiBerry GPIO documentation, I could have noticed the wrong numbers.

How would a newbee get that done? Is a bread board a legit alternative. Should I solder a 100nF capacitor from the SW to the GND pin?

You should use 10nF capacitors between each pin of each encoder and ground. That is 2 capacitors per encoder.

You should use 47nF capacitors between each switch and ground. That is 1 capacitor per switch.

How you practically do this depends on what components you purchase and how you intend to mount them. You ideally want the capacitors close to the switch/encoder. If you buy raw encoders like this:
image
then you could mount these on some veroboard and put the capacitors between each pair of pins. I think this would be the simplest way to DIY this.

Thanks for now! Like expected there are some considerations open. I’ll happily come back when I made some decisions.

Well done…!!

Course if we heard what you produced. . .