-->
Page 1 of 1

How to use two I2C buses

PostPosted: Sun Oct 08, 2017 7:52 pm
by Tigers
I am having trouble using two I2C buses on the ESP8266, it seems the Wire library implementation prevents using two I2C buses. I have five MPR121 touch sense controllers which only allow selection of four I2C addresses hence the need for two buses.

The issue is the last bus to be started is the only one which may be read or written.

When I query the MPR121s on bus A and bus B the values for both buses will only return the bus which was started last. So if I start bus A first and bus B second I will only get values on bus B when I try reading both buses. If I swap the order of setup and start bus B first and bus A second then the values returned for queries on bus A and bus B will only be the values on bus A. I confirmed the hardware output is on the last started bus only using a scope.

Thanks for the help.

Re: How to use two I2C buses

PostPosted: Wed Oct 11, 2017 12:26 pm
by tele_player
Switch buses by calling Wire.begin() as needed.

Re: How to use two I2C buses

PostPosted: Sun Oct 22, 2017 1:26 am
by brunofr
Hi
You may use the SlowSoftWire library to setup your 2nd I2C bus in addition to the I2C bus managed by the Wire library. The Wire library would default to using the I2C controled by pins D1/D2 while you would setup a 2nd I2C bus using pins D5/D6 with SlowSoftWire Wire2 = SlowSoftWire(D5, D6, true); .
I am currentlry testing I2C in slave mode with SlowSoftWire library.
Hope this helps
Bruno