Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino Uno Simultaneous Multiple Soft I2C Library

Status
Not open for further replies.

Athar Rasul

Newbie level 4
Joined
Mar 16, 2010
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,346
Hi,

There are a lot of I2C libraries for Arduino on internet but there is one problem - none of them supports multiple I2C to communicate to devices simultaneously. I needed a library of I2C that could communicate to multiple sensors (having same address) using a single Arduino and much to my disappointment, I couldn't find one. I kept on searching and the best closest thing I could find is 'softi2c' library by fat16lib.

https://forums.adafruit.com/viewtopic.php?f=25&t=13722

I tweaked it a little bit to be able to handle multiple I2C buses at the same time. All buses have software selectable pins and they can either have a shared or independent SCL pins, depending on user requirement. The example code is for VCNL4000. In the example I haven't written different functions for read and write but of course it can be modified. I did it because the sensor is in proximity mode and the Command Register needs to be written each time prior to a valid read. The code is tested for Arduino 1.0. Hopefully this helps.
 

Attachments

  • SoftI2cMaster.rar
    3.7 KB · Views: 85

Hi,
1. What do u mean, Do you want communicate to multiple slaves simultaneously?
I think this is not possible. I2C is Serial Communication based. You can have multiple slave but not at the same time.

Check the below link to know the basic of
https://www.best-microcontroller-projects.com/i2c-tutorial.html

2. I needed a library of I2C that could communicate to multiple sensors (having same address)
There are 2 methods by which you can do this.

1st method is listed in the below link, where in you enable and disable the sensor.

https://blogs.msdn.com/b/laurelle/a...identical-i2c-device-on-the-same-i2c-bus.aspx

2nd method is: There are user configurable data bits within your sensors. Most of the sensors have 2 user configurable bits. So you can have 4 similar sensors connected to the same bus. Just search for I2C with identical slaves.

Wrt to library my suggestion is 1st know the concept then dig into the library.

Cheers,
Pavan
 

Dear you didn't read the post carefully. I don't have any problem in understanding I2C or communicating with multiple sensors. I'm merely posting a library, for other people to use, that I modified to be able to communicate on multiple simultaneous I2C buses. Of course it is possible as the controller handles each bus sequentially. Using this library, you don't need to enable/disable any sensor (it's a neat idea though but not so neat when the sensor needs some settling time and configuration after each boot up - a lot of wastage in time critical applications.) And most of the sensors don't have user configurable I2C address so in that case, you're bound to use them on different I2C buses.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top