Help with Encoders and MCP23017 on Custom Zynthian

Hi everyone, I’m new to Zynthian having watching a few of Floyd Steinberg’s excellent videos. I have a fair bit of amateur experience with electronics and software, I’ve built my own modular analogue synthesizer from scratch amongst other things and I feel like the Zynthian would be a perfect polyphonic, digital synth to add to my setup.

I have already got a Raspberry Pi 4B and so I sourced a DAC Hat and 3.5" Touch Display display and got it all up and running - it’s truly excellent! Thank you to all involved in creating and sharing this project.

The next logical step is to add some encoders because interacting with the resistive touch screen is a bit of a pain. So I have sourced a MCP23017 board, it has a default address 0x27:
Zynthian I2C Address

I am trying to get something to work - even just a push button - but without success so far. I am running the zyncoder_test script to see if I can understand what is happening.

Can this run at the same time as the main Zynthian application?

This is the output I get without any interactions - this repeats infinitely and quickly:

ZynCoder->update_polled_zynswitches(0): Wrong pin number 108 in zynswitch 2!
ZynCoder->update_polled_zynswitches(0): Wrong pin number 111 in zynswitch 3!

Zynthian Zyncoder Test

I have tried various different configurations, but here is what I used for the above test:

It’s like 108 and 111 are floating and don’t have a pull-up resistor or something like that? Although I don’t understand the message: “Wrong pin number…”

Something I’m not quite clear about is the Interrupt PINs and the labelling in the configuration. “WPI-GPIO 27 (pin 36)” - does this mean physical pin 36 (which is now GPIO 16) or is it actually GPIO 27 (pin 13). I’m realising now that these conventions have changed with the different releases of the Raspberry Pis. Not confusing at all is it!? I have tried both pins without success.

I have also tried setting all unused PINs to ‘-1’ to disable them for now. With 100, 103, -1, -1 in the ‘Switches Pins’ and then touching PA0 or PA3 to ground does not seem to achieve anything. Removing 108 and 111 has stopped the messages:

ZynCoder->update_polled_zynswitches(0): Wrong pin number 111 in zynswitch 3!
ZynCoder->update_polled_zynswitches(0): Wrong pin number 108 in zynswitch 2!

Any guidance from here would be greatly appreciated!

Hi @JamesPearson welcome on board. You’re close for doing some noise :innocent:

You will have to double check your wiring. The numbers 100 to 115 refers to the mcp23017 GPIOs:
100 for the first GPIO of bank A, 115 for the last one of bank B. So carefully look at your 2nd and 3rd encoders (and especially the switch pin, the one wired on the encoder side where there is only 2 pins).

BTW FYI, you can add four momentary push buttons on the mcp23017 free GPIO pins, just add them in the “Switches pins” form field, after the 4 numbers for encoders switches pins.
And if encoders behave reversely, just swap Encoder-A pin and Encoder-B pin in the corresponding form fields.
Lastly, I guess (I’m not sure) that, even with your errors, encoder 1 and 4 should work. And encoders 2 and 3 should work when rotating them. Did you try this ?

Hi @JamesPearson !

Welcome to zynthianland!

Be aware that you must specify the “pin numbers” using wiringPi numbering convention, that differs from the BCM numbering:

Regards,

Thank you for the welcome and for the help… good news I think I’m finally making some progress! So I’m pretty sure I had the interrupt pins connected incorrectly. I am now using physical pins 36 and 16 (ignoring the GPIO labels in the web config as I think they misled me).

Also, my latest discovery is that I don’t think I should be selecting ‘Custom’ wiring. I have finally had some success with ‘Mcp23017 Encoders’. Also, I think it seems to be necessary to reboot (not just application restart) for this to take effect.

Strangely I’m getting no output from the zyncoder_test tool - that remains a mystery… but for the very first time I was able to connect an encoder (not just the switch) to pins 111, 112 and 113 and see some action on the screen!!

This is such a relief as I’ve been going round in circles for hours and days getting nowhere. I knew this day would finally come when the penny drops. I’ll need to attempt to dig into the code to understand what all these wiring configurations actually mean.

Yes. You have to use the “mcp23017 encoders”. The custom wiring is for connecting encoders and switches directly to the RBPi, without any GPIO expander. Perhaps this should be better explained somewhere.

Regards,

Wonderful, thank you so much José for the information - very enlightening. Also, thank you so much for creating such an amazing open source product, the reward of such a great platform is constantly giving the encouragement to push through the challenges! :slight_smile:

May I ask how the zyncoder_test tool works please? I still can’t see any output from it. Do I need to somehow kill the application first? Are they both competing for the same Interrupt?

For running zyncoder_test you have to stop zynthian service before:

systemctl stop zynthian

Access to GPIO lines can be concurrent. Only one program at once.
Same is valid for most low level hardware interfaces. Imagine 2 computers trying to control the same USB-printer at once :wink:

Regards,

2 Likes

Perfect, thanks for the command. I was attempting to kill it from ‘htop’ and it was automatically restarting :slight_smile:

I’ve got all four encoders wired and tested now. Now I need to read the manual to understand what each knob does in the interface. Then make some more sounds.

Longer term - build a box for it.

Thanks again!!

2 Likes