# Compatible USB\>I2C adapter for RPi4

**URL:** <https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690>\
**Category:** Home Automation\
**Tags:** openhab2\
**Created:** [February 27, 2020, 11:37am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690 "2020-02-27T11:37:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [February 27, 2020, 11:37am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/1 "2020-02-27T11:37:36Z")

</div>

Hi,

I’d like to attach 18 or more GPIO panels 1-3meter away from Raspberry 4, so I will need 2-3 USB\>I2C adapters. _(All together I need 128 I/O ports or more for my house.)_

Is there any recommendation what USB adapter board should I buy to get more I2C buses?  
What IC of that is OpenHABian will be compatible with?  
Thanks for any recommendation!

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [February 27, 2020, 11:49am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/2 "2020-02-27T11:49:43Z")

</div>

I would use a different tech - Modbus over RS485 wired serial. Dozens of devices over hundreds of metres.

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [February 27, 2020, 12:04pm UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/3 "2020-02-27T12:04:10Z")

</div>

I’ve already bought lots of I2C boards: 😊  
-8x 8IO and  
-2x of 16IO  
They were cheap and directly available from stock at Hungary. _(Sadly I don’t have time to wait 3 weeks for a shipment from China… my smarthome system died by a lightning and I can not control ANYthing in my house now ☹ )_

Currently I need a quick solution to screw everything together within 1-2 meter distance.  
(My Pi4 is in the room near the ceiling to keep it in 25C enviroment, but **all** the cables are at the attick above.)  
…  
Later, I’d like to enhance the system with 1-Wire temp sensors, and maybe other things…  
…  
RS485 seems to be a really good choice, but did not find too much special sensors yet other than I2C.  
(IR, movement, NFC, nearing, …)

---

<div class="post-metadata">

**Author:** ![seeers](https://community.openhab.org/user_avatar/community.openhab.org/seeers/32/19547_2.png) [@seeers](https://community.openhab.org/u/seeers)\
**Post date:** [February 27, 2020, 8:17pm UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/4 "2020-02-27T20:17:42Z")

</div>

I can recommend this firmware on a Digispark. Is recognized as a normal i2c device under Linux.  
And are very cheap to build 🙂

> **[I2C-Tiny-USB/digispark at master · harbaum/I2C-Tiny-USB](https://github.com/harbaum/I2C-Tiny-USB/tree/master/digispark)**
>
> Cheap and simple I²C to USB interface. Contribute to harbaum/I2C-Tiny-USB development by creating an account on GitHub.

or a DIY Version:

> **[GitHub - harbaum/I2C-Tiny-USB: Cheap and simple I²C to USB interface](https://github.com/harbaum/I2C-Tiny-USB)**
>
> Cheap and simple I²C to USB interface

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [February 28, 2020, 10:32am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/5 "2020-02-28T10:32:39Z")

</div>

Thank you very much for the links!  
I’ve found those too yesterday, but didn’t believe it would be stable / possible to do this way…  
I’ve digged into it a bit more, and found 2 problems with this solution:

- There are no ATTiny45 boards available any more, only ATTiny85 ones. (ca. 4$ inc. VAT)
- it gives 5V output, instead of **3.3V**!!!  
… So I would also need a 5V\>3.3V I2C conversion board from a shop which has this on stock. (Usually sold for **10$**!)

I wonder why isn’t there any robust, “ready to use” = Plug&Play version of this in Europe at all?

---

<div class="post-metadata">

**Author:** ![CrazyIvan359](https://community.openhab.org/user_avatar/community.openhab.org/crazyivan359/32/83351_2.png) [@CrazyIvan359](https://community.openhab.org/u/CrazyIvan359)\
**Post date:** [February 28, 2020, 10:59am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/6 "2020-02-28T10:59:57Z")

</div>

I assume from the information you have given that you are using Mcp23017 and MCP23008 devices. These have 8 addresses that are usable, so you don’t need any external hardware to connect them.

I recommend you use some kind of buffer or level shifter for this. 1-3m of wire could draw high amounts of current and damage your Pi. Though you have already stated you don’t want to buy such things, but I have warned you.

There are 2 I2C buses on a Raspberry Pi, I2C0 is used for the HAT memory chip but can still be used by software. Just connect some to one bus and some to the other and make sure your addresses are set correctly.

You will need to pay special attention when making your cables. Bring only the SDA and SCL lines from the Pi, along with ground. Twist SDA and a ground wire together the whole length, and do the same with SCL with a different ground wire. You will need to connect the ground wires at the remote end as well. Use power at the remote end, don’t bring it from the Pi.

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [February 28, 2020, 11:34am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/7 "2020-02-28T11:34:55Z")

</div>

> [@CrazyIvan359](#):
>
> 1-3m of wire could draw high amounts of current and damage your Pi

Thank you for all those tips, but I think you have misunderstood me. Such things are exactly what I would like to avoid! 😊

What I meant is, that I’d like to use a SAFE, nearly “industrial solution”: 👌

- No tiny wires, twisted and soldered
- No direct Pi4\<\>GPIO pins  
etc…

but a simple USB cable with a Plug&Play adapter at the end with standard 3.3V output to plug all those board one after the other. (To connect to Opto-couplers.)

This way, If something goes wrong, (like an other lightning,) I could simply unplug the device, and replace it in 5 seconds. (Instead of 3 weeks.)  
Something like [this one: (Click link)](https://www.tindie.com/products/kel/usb-i2c-module/).  
if I would get confirmation that such a device would work out of the box without special Firmware flashing or wiring or any other complication. 🙂

---

<div class="post-metadata">

**Author:** ![CrazyIvan359](https://community.openhab.org/user_avatar/community.openhab.org/crazyivan359/32/83351_2.png) [@CrazyIvan359](https://community.openhab.org/u/CrazyIvan359)\
**Post date:** [February 28, 2020, 5:46pm UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/8 "2020-02-28T17:46:37Z")

</div>

Now I understand the goal. The board you like will work if you write some software for it. You might look at my [MQTTany](https://github.com/CrazyIvan359/mqttany) software, you could write a module for USB-I2C devices like this. I can assist, or write it if I have time.

---

<div class="post-metadata">

**Author:** ![seeers](https://community.openhab.org/user_avatar/community.openhab.org/seeers/32/19547_2.png) [@seeers](https://community.openhab.org/u/seeers)\
**Post date:** [March 1, 2020, 7:41pm UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/9 "2020-03-01T19:41:19Z")

</div>

Maybe this product would still be something for you. Also recognized as an I2c device under linux and the voltage can be set.

> **[I2C-MP-USB - USB to I2C Interface - fischl.de](https://www.fischl.de/i2c-mp-usb/)**
>
> I2C-MP-USB is an USB to I2C interface

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [March 2, 2020, 1:21am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/10 "2020-03-02T01:21:32Z")

</div>

Many thanks you looked for it! 🙂  
Currently I’m waiting for delivery for 3 Digispark USB panels based on ATTiny85 chip.  
They are really cheap ($4). [link…](https://www.hestore.hu/prod_10036419.html)  
So I will try to flash that firmware you have suggested earlier.  
I’ve convinced myself, that a bit of soldering and flashing is not the end of the word… 🕶

What does it mean “DIY” version?

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [March 8, 2020, 11:11am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/11 "2020-03-08T11:11:22Z")

</div>

failures…

Just to save time for others who find this topic:

1.) `gpio readall`  
will not work on Openhabian out of the box.

2.) Even if you success to install it from the original author:  
[http://wiringpi.com/the-gpio-utility/](http://wiringpi.com/the-gpio-utility/)  
… you will realized, it’s not maintained since 2019.aug:  
[http://wiringpi.com/wiringpi-deprecated/](http://wiringpi.com/wiringpi-deprecated/)  
So it will NOT work with newest RPi boards, like my Pi4B version 17.

3.) Found an alternative:

> **[pigpio library](http://abyz.me.uk/rpi/pigpio/download.html)**
>
> Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links.

… but the newest version (74) can not be installed (compile error)

4.) Standard (repo) install works:  
`sudo apt-get update`  
`sudo apt-get install pigpio python-pigpio python3-pigpio`  
… but that’s only version 71

5.) Found a Phyton script that should list my available ports:

> **[GPIO Readall Code - Raspberry Pi Forums](https://forums.raspberrypi.com/viewtopic.php?f=66&t=254071)**

… but is does not, because it has a `syntax error at line 41`.

☹

* * *

That I’ve decided to give a try to MQTT … see my next post…

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [March 8, 2020, 11:41am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/12 "2020-03-08T11:41:19Z")

</div>

> [@CrazyIvan359](#):
>
> [MQTTany](https://github.com/CrazyIvan359/mqttany)

Dear Ivan,

I’m extremely impressed by your code and documentation! 🕶

- I wonder: Why isn’t it listed as ‘1 click installable binding’ at OH2 ?
- What is the difference between the other MQTT bindings listed there?

After reading everything I had to realize:

- it does not seem to support [PCF8574](https://www.waveshare.com/pcf8574-io-expansion-board.htm) 8GPIO I2C expansion boards. ☹

So I did not install it yet.

How much work would it be to enhance your code to be able to handle this board too?

> **[Raspberry Pi Tutorial Series: I2C - Waveshare Wiki](https://www.waveshare.com/wiki/Raspberry_Pi_Tutorial_Series:_I2C#Control_PCF8574_IO_using_i2c-tools)**

Is it possible that you could do it and I would **pay for it**? If yes, how much would it cost me?  
_I’m not a rich guy at all (my programming rate is 10-15$/hour) but I don’t like to ask for favours for free._

**Why those boards?**

1. Very cheap
2. easy to connect 8 of them in a row
3. has jumpers easy to change Address IDs 0-7
4. Available at my County from stock
5. Already bought 8 (need 64+48 I+O port. Later maybe more…)

---

<div class="post-metadata">

**Author:** ![CrazyIvan359](https://community.openhab.org/user_avatar/community.openhab.org/crazyivan359/32/83351_2.png) [@CrazyIvan359](https://community.openhab.org/u/CrazyIvan359)\
**Post date:** [March 8, 2020, 12:15pm UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/13 "2020-03-08T12:15:12Z")

</div>

> [@SzakiLaci](#):
>
> I’m extremely impressed by your code and documentation!

Thank you! This is the first piece of software I’ve shared so I’m still learning, but I wanted to do it right.

* * *

> [@SzakiLaci](#):
>
> - I wonder: Why isn’t it listed as ‘1 click installable binding’ at OH2 ?
> - What is the difference between the other MQTT bindings listed there?

It is not a binding, and not meant to be. It started as a small script to allow me to read and control GPIO pins on a Pi that was not running openHAB and has grown from there.

* * *

> [@SzakiLaci](#):
>
> it does not seem to support [PCF8574](https://www.waveshare.com/pcf8574-io-expansion-board.htm) 8GPIO I2C expansion boards.

> [@SzakiLaci](#):
>
> How much work would it be to enhance your code to be able to handle this board too?

Probably not much. The code already exists for the MCP230xx chips so I would just need to copy that and change the parts that actually communicate with the chip.

* * *

> [@SzakiLaci](#):
>
> Is it possible that you could do it and I would **pay for it**? If yes, how much would it cost me?

I can do it no problem, but as for payment your help in testing the code will be enough. I probably won’t have time to do it until next weekend though.

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [March 10, 2020, 12:01am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/14 "2020-03-10T00:01:52Z")

</div>

Dear Seers,  
Today I was finally able to flash all 3 of the USBs.

I’ve plugged in 1 of them so far + a PCF8563 real-time-clock board + 1 pcf8574 board (8 I/O ports)

- what’s next?

1. Tried to edit /etc/modules-load.d/modules.conf
2. but could not upload it back via SFTP ☹
3. is that enough ? `dtparam=i2c=on`  
`dtoverlay=i2c-rtc,pcf8563`
4. also tried to type into SSH promt:  
`icdetect`  
but “command not found”

out of ideas… toooo many infos on google, but all of them use RPi built-in pins.  
Do not know how to step forward, please help! 😉

---

<div class="post-metadata">

**Author:** ![CrazyIvan359](https://community.openhab.org/user_avatar/community.openhab.org/crazyivan359/32/83351_2.png) [@CrazyIvan359](https://community.openhab.org/u/CrazyIvan359)\
**Post date:** [March 10, 2020, 12:32am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/15 "2020-03-10T00:32:09Z")

</div>

> [@SzakiLaci](#):
>
> also tried to type into SSH promt:  
> `icdetect`

The command is `i2cdetect` 😉

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [March 10, 2020, 12:38am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/16 "2020-03-10T00:38:54Z")

</div>

😊 yes, I know.! Mistyped here… but I’ve tried with the right syntax.  
Can you maybe help me with the real problem? 😉

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [March 10, 2020, 12:42am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/17 "2020-03-10T00:42:50Z")

</div>

… also I wanted to ask you about:

- isn’t this MQTT thing slow?

Because I would like to use my 64 swiches for

- dimmer LEDs up-down-up in real time by pressing it continouosly!
- and use long-click on other things to execute different logic/behavior.  
(Maybe also double-click.)

For example:

1. short click =\> FAN on for 10 minutes
2. long click (\>800ms) =\> FAN on forever

So it has to be able to handle these things in realtime on multiple Input ports on the same bus.

---

<div class="post-metadata">

**Author:** ![CrazyIvan359](https://community.openhab.org/user_avatar/community.openhab.org/crazyivan359/32/83351_2.png) [@CrazyIvan359](https://community.openhab.org/u/CrazyIvan359)\
**Post date:** [March 10, 2020, 3:03am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/18 "2020-03-10T03:03:38Z")

</div>

> [@SzakiLaci](#):
>
> Can you maybe help me with the real problem?

I’m not sure why the program wasn’t found, I thought it came pre installed in raspbian. Google would be the best place to find installation instructions for it.

* * *

> [@SzakiLaci](#):
>
> isn’t this MQTT thing slow?

Relatively speaking, yes. What you describe will not be possible. MQTT is not real-time like you need for that, but then again neither is openHAB.

---

<div class="post-metadata">

**Author:** ![SzakiLaci](https://community.openhab.org/user_avatar/community.openhab.org/szakilaci/32/50939_2.png) [@SzakiLaci](https://community.openhab.org/u/SzakiLaci)\
**Post date:** [March 10, 2020, 11:22am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/19 "2020-03-10T11:22:32Z")

</div>

> [@CrazyIvan359](#):
>
> Relatively speaking, yes. What you describe will not be possible. MQTT is not real-time like you need for that, but then again neither is openHAB.

That sound very bad! Obviously that would be the most important thing to accomplish.  
Everything else is just “extra”.  
Do you know about any “real scenarios”, how much delay it takes to handle long-dimming?

---

<div class="post-metadata">

**Author:** ![Alien](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@Alien](https://community.openhab.org/u/Alien)\
**Post date:** [March 10, 2020, 11:45am UTC](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690/20 "2020-03-10T11:45:04Z")

</div>

sudo apt install i2c-tools  
The answer to your next questions is no, OH is not a real-time system. To handle long, short, double clicks etc. you may use microcontrollers or PLC.

[Next page](https://community.openhab.org/t/compatible-usb-i2c-adapter-for-rpi4/93690.md?page=2)
