Using gpiozero library and pimoroni ioexpander w/ ioexpander library

Hello,

Is there a way to use the gpiozero library with the ioexpander module and library? I am struggling to translate the gpiozero code into ioexpander library code. I was wondering if there was a way to point gpiozero to read the ioexpander pins as opposed to the main pins on the Pi. I am using it with a Hyperpixel display.

Thanks

The IO expander uses i2c. And if your using it with a hyperpixel, you’ll need to connect it to the hyperpixel’s i2c connector on its back side. Then do the alternate software i2c thing.
I think you’ll have a real struggle getting gpiozero to work via i2c?

Yeh so I have the i2c thing all connected up and I am able to get data through it. Ideally though I want to use the gpiozero library to script the hardware controls…

Don’t take this the wrong way but why?
Can gpiozero do i2c?
Plus, the pins on the io expander aren’t GPIO pins, they don’t have any BCM numbers etc to reference too.
I’m far from being any type of expert on this but my gut feeling is, you can’t get there from here.

Gpiozero apparently doesn’t support i2c at the moment, and even if it did, you’d need a library written for the IO expander. So I’m afraid you’re stuck with the official Python library or the Arduino library someone wrote.

Thanks for your responses. Nothing taken the wrong way :) still a newbie to Pi hardware!
I found the ioexpander library from pimoroni and managed to get some components working. However I am struggling to get two rotary encoders working at the same time.

I can setup a single one using ioe.setup_rotary_encoder(1,pinA,pinB). But when I try to initialise the second one it doesn’t work. I’m struggling with what to put for the first argument on the second encoder, ioe.setup_rotary_encoder(2,pinC,pinD) does not work.

Have either of you had experience with this library/this issue?

I don’t own an IO expander. I have lots of Breakout Garden stuff, but not that breakout.

I don’t have it either, but at a glance ioe.setup_rotary_encoder is a function which is part of the first encoder, so running it again doesn’t set up a second encoder, it tries to configure the first.

Your code might need something like:

ioe = io.IOE(i2c_addr=0x18)
ioe.setup_rotary_encoder(1, pinA, pinB)

ioe2 = io.IOE(i2c_addr=0x18)
ioe2.setup_rotary_encoder(1, pinC, pinD)

I have to say, I’m not quite sure what the 1 is meant to indicate, the library talks about channels but I’ve no idea how this relates to how the device works. I really wish Pimoroni would document these things better.

Yeh the library could do with some documentation…
So I fixed it by doing:
ioe.setup_rotary_encoder(1, pinA, pinB)
ioe.setup_rotary_encoder(2, pinC, pinD)
I had tried this before but this time it seems to be working. I have no idea if it is meant to accend… but I think it could be to do with what pinB/D is.
pinB = 2, pinD=3
Anyway for now this seems to be working if others are struggling :)