-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Multiple I2C ports #3063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There shouldn't be any problem, just call Wire.begin(SDA,SCA) before each
call to the respective device
Though if you expect some callback from the device - it may not work
|
Does instancing another Wire object, and initing that to different pins work? |
@abouillot did you try any of the comments here? |
No feedback in over a month, closing. |
This issue should be reopened since i can confirm that creating two instances will not work. The latest call to TwoWire::begin will set the pins used, no matter which object that are used and how they are configured. That since Wire.h is using an underlying twi in a non object oriented way.
And twi_init uses one global twi object:
Every TwoWire object should keep its own twi object, but the twi object is not exposed in the twi.h. Fore some reason the only thing that is exposed is a C wrapper over the object. The twi class itself calls those wrapper functions also, which is kind of strange. (The twi class is a bit of a hack, if you ask me.) The Wire library looks like it is object oriented, but creating more than one TwoWire objects does not make sense with this implementation. This should be corrected or explained in the documentation. The best solution imho is to expose the twi class in the twi.h file and redo the implementation of that class so it uses class functions instead of the exposed C-interface. This might however break some compatiblity with the twi.h file (not sure now). The solution suggested by @vlast3k works but gives rather cluttered code if you like to communicate with devices on both i2c channels since you have to do a Wire.begin before each call to an i2c communication. Most libraries for i2c devices supports initializing their object with a TwoWire object to support multiple i2c channels, wich is necessary if you like to use more devices than there are possible adress configurations for that device. This support is now useless since this implementation prevents multiple TwoWire ojbjects. |
I agree with kartom, the issue should be reopened. |
@devyte I'm running into this as well. |
Please open a new issue, follow the template instructions, explain the problem with the addresses, and reference this issue. |
Have you solve? can I help? I need more than one i2c on same board? |
@abouillot In case your sensors have the same I2C address, use a TCA9548A multiplexer. I use it and it works great |
Now it works....it's not very beautiful code but seams to work... |
comunque grazie.... mi sa che è la soluzione piu pulita visto che se aggiornano la release perdo tutto.... |
more than not so good code.... the problem was using c++ classes with c timer in rom that want a c callback.... so I do the first thing that I thought that was create 5 function and from there call c++ ... the same thing was happen in twi but there I could use std:bind but with ets_timer and so I was not able to do it.... so I solve in very brutal way.... but works like a charm |
This is really cool. I tried it with two SSD1306 breakout modules that hide the "D/C#" address select pin so have identical I2C addresses. I have been able to use them simultaneously on separate SDA/SCL pins on an ESP8285 dev module. However, I have two other I2C modules (an MCP23016 gpio expander and AT42QT1070 touch sensor module) that do not work properly with this version of Wire/twi, even if there's just one device on one I2C bus and only the one global Wire instance. I can get their addresses with some "i2cdetect" code, but writing to them does not seem to work. I've tried adjusting the clock freq and pullups, but basically they work fine when I reset framework-arduinoespressif8266 and do a clean build, but stop responding when I switch back to your version and do a clean build. I'll try to investigate further, but any guesses would be helpful. Thanks. |
The I2C implementation on ESP8266 is soft based. It can set the pin to use.
However, I had no success in getting two I2C bus running together. The issue I have is that the I2C device I want to use only have one address and I need two instances of it connected to the ESP. I was planing to open two Wire ports and connect each of the peripheral to one.
Is it possible with today's implementation? Is there any guide on how to achieve this?
The text was updated successfully, but these errors were encountered: