# RGB Encoder Breakout Address Change

**URL:** <https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051>\
**Category:** Electronics\
**Created:** [October 3, 2020, 5:03pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051 "2020-10-03T17:03:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjbussey](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@cjbussey](https://forums.pimoroni.com/u/cjbussey)\
**Post date:** [October 3, 2020, 5:03pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/1 "2020-10-03T17:03:00Z")

</div>

I have just purchased 2 \* RGB Encoder Breakout boards, the shop says it is possible to change the address to avoid conflicts but I cannot find any instructions to do so.

Any help?

---

<div class="post-metadata">

**Author:** ![major\_tomm](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/major_tomm/32/9044_2.png) [@major\_tomm](https://forums.pimoroni.com/u/major_tomm)\
**Post date:** [October 3, 2020, 6:20pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/2 "2020-10-03T18:20:34Z")

</div>

The product page it says it can be changed in software, rather than the usual solder-bridging.

Taking a look at the provided example it seems like you might be able to specify the address when you instantiate the device?

```
ioe = io.IOE(i2c_addr=0x18, interrupt_pin=4)
```

---

<div class="post-metadata">

**Author:** ![cjbussey](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@cjbussey](https://forums.pimoroni.com/u/cjbussey)\
**Post date:** [October 3, 2020, 8:48pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/3 "2020-10-03T20:48:37Z")

</div>

Thanks major\_tom,

So at boot up I have two RGB rotary encoders plugged in both on 0x0F, how do I set one of them to for example 0x0E so I can differentiate between them, furthermore how do I set this address in flash memory?

The shop page says:-  
“The default I2C address is 0x0F, but it’s possible to change this in software if you’d like to use multiple RGB Encoder Breakouts, or avoid conflicts with other I2C devices. The new address will be saved in flash memory, so will persist if unpowered.”

Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![major\_tomm](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/major_tomm/32/9044_2.png) [@major\_tomm](https://forums.pimoroni.com/u/major_tomm)\
**Post date:** [October 3, 2020, 8:54pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/4 "2020-10-03T20:54:26Z")

</div>

That bit sounded a bit like magic to me as well.

I can only guess that you’d be able to plug one in and change the address? The next time you tried to use it, it would still be on that new address? Then you could plug the second one in?

Ahah, here’s the magic function:

```
 def set_i2c_addr(self, i2c_addr):
    """Set the IOE i2c address."""
    self.set_bit(REG_CTRL, 4)
    self.i2c_write8(REG_ADDR, i2c_addr)
    self._i2c_addr = i2c_addr
    time.sleep(0.25) # TODO Handle addr change IOError better
    # self._wait_for_flash()
    self.clr_bit(REG_CTRL, 4)
```

---

<div class="post-metadata">

**Author:** ![cjbussey](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@cjbussey](https://forums.pimoroni.com/u/cjbussey)\
**Post date:** [October 3, 2020, 9:13pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/5 "2020-10-03T21:13:44Z")

</div>

Hi major\_tomm,

Sorry for the incorrect name last time.

My encoders have not arrived yet but I hope they will this week.

We are obviously on the same page. It has to be done one at a time.

Where did you get that code from?

Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![major\_tomm](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/major_tomm/32/9044_2.png) [@major\_tomm](https://forums.pimoroni.com/u/major_tomm)\
**Post date:** [October 4, 2020, 8:52am UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/6 "2020-10-04T08:52:22Z")

</div>

From the example linked on the product page I had a bit of a click through the git repository.

[This page contains all the functions available in the library.](https://github.com/pimoroni/ioe-python/blob/master/library/ioexpander/ __init__.py)

The IOE class is the one we’re interesting in I think.

---

<div class="post-metadata">

**Author:** ![cjbussey](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@cjbussey](https://forums.pimoroni.com/u/cjbussey)\
**Post date:** [October 9, 2020, 2:32pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/7 "2020-10-09T14:32:58Z")

</div>

Hi,

My encoders have arrived, they are both set on 0x0F (no surprise there) I can drive one of them quite happily but I cant drive both . My challenge is that I write normally in Javascript (Node Red) I now have two rotary encoders both on 0x0F and want to change one of them to 0x0E.

I have looked at the set\_i2c\_addr(self, i2c\_addr) function you sent me but dont really know how to use it.

#!/usr/bin/env python3  
import time  
import ioexpander as io

ioe = io.IOE(i2c\_addr=0x0f, interrupt\_pin=4)  
ioe.set\_i2c\_addr(ioe,0x0e)

A simple example would set me on my way, any chance of some help, what am I doing wrong?

Kind regards,  
Chris

---

<div class="post-metadata">

**Author:** ![major\_tomm](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/major_tomm/32/9044_2.png) [@major\_tomm](https://forums.pimoroni.com/u/major_tomm)\
**Post date:** [October 9, 2020, 3:03pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/8 "2020-10-09T15:03:07Z")

</div>

My guess would be something like this:

```
import time
import ioexpander as io

ioe = io.IOE(i2c_addr=0x0f, interrupt_pin=4)
ioe.set_i2c_addr(0x0e)
```

---

<div class="post-metadata">

**Author:** ![cjbussey](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@cjbussey](https://forums.pimoroni.com/u/cjbussey)\
**Post date:** [October 9, 2020, 3:28pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/9 "2020-10-09T15:28:04Z")

</div>

Your a bloody genius!!!

---

<div class="post-metadata">

**Author:** ![major\_tomm](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/major_tomm/32/9044_2.png) [@major\_tomm](https://forums.pimoroni.com/u/major_tomm)\
**Post date:** [October 9, 2020, 5:22pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/10 "2020-10-09T17:22:53Z")

</div>

I don’t know about that, I just work with Python a bit as part of my day job :)

Glad it’s working.

---

<div class="post-metadata">

**Author:** ![cjbussey](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@cjbussey](https://forums.pimoroni.com/u/cjbussey)\
**Post date:** [October 9, 2020, 6:18pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/11 "2020-10-09T18:18:27Z")

</div>

I am struggling to get my head around the “self” bit, to me the function “def set\_i2c\_addr(self, i2c\_addr):” requires two parameters one for self and one for i2c\_addr.  
If I had dropped off the ioe parameter in “ioe.set.addr(ioe,0x0e)” I would have got it right.  
How can a function specifying two parameters require only one?  
Thanks for all your help.  
Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![major\_tomm](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/major_tomm/32/9044_2.png) [@major\_tomm](https://forums.pimoroni.com/u/major_tomm)\
**Post date:** [October 9, 2020, 7:17pm UTC](https://forums.pimoroni.com/t/rgb-encoder-breakout-address-change/15051/12 "2020-10-09T19:17:12Z")

</div>

`self` represents an instance of the IOE class. When you call `set_addr` from an instance of the class that parameter gets automatically filled in for you.

I’m not quite sure _why_ that’s the case, someone else might have a better answer.

> **[Understanding self in Python](https://medium.com/quick-code/understanding-self-in-python-a3704319e5f0)**
>
> Once you start using Python, there is no escaping from this word “self”. It is seen in method definitions and in variable initialization…
