# Using gpiozero library and pimoroni ioexpander w/ ioexpander library

**URL:** <https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846>\
**Category:** Support\
**Created:** [September 1, 2020, 12:22pm UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846 "2020-09-01T12:22:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![callumfowler101](https://avatars.discourse-cdn.com/v4/letter/c/e274bd/32.png) [@callumfowler101](https://forums.pimoroni.com/u/callumfowler101)\
**Post date:** [September 1, 2020, 12:22pm UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846/1 "2020-09-01T12:22:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [September 1, 2020, 12:35pm UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846/2 "2020-09-01T12:35:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![callumfowler101](https://avatars.discourse-cdn.com/v4/letter/c/e274bd/32.png) [@callumfowler101](https://forums.pimoroni.com/u/callumfowler101)\
**Post date:** [September 1, 2020, 1:53pm UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846/3 "2020-09-01T13:53:08Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [September 1, 2020, 7:07pm UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846/4 "2020-09-01T19:07:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)\
**Post date:** [September 1, 2020, 7:15pm UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846/5 "2020-09-01T19:15:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![callumfowler101](https://avatars.discourse-cdn.com/v4/letter/c/e274bd/32.png) [@callumfowler101](https://forums.pimoroni.com/u/callumfowler101)\
**Post date:** [September 2, 2020, 10:52am UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846/6 "2020-09-02T10:52:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [September 2, 2020, 11:13am UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846/7 "2020-09-02T11:13:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)\
**Post date:** [September 2, 2020, 1:13pm UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846/8 "2020-09-02T13:13:56Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![callumfowler101](https://avatars.discourse-cdn.com/v4/letter/c/e274bd/32.png) [@callumfowler101](https://forums.pimoroni.com/u/callumfowler101)\
**Post date:** [September 2, 2020, 2:31pm UTC](https://forums.pimoroni.com/t/using-gpiozero-library-and-pimoroni-ioexpander-w-ioexpander-library/14846/9 "2020-09-02T14:31:43Z")

</div>

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 :)
