How to use multiple VCNL4000 on Arduino?

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
LeoC
 
Posts: 2
Joined: Mon Aug 11, 2014 6:35 pm

How to use multiple VCNL4000 on Arduino?

Post by LeoC »

I am doing a project which needs to use 4 VCNL4000 sensors on an Arduino. But I have searched for a long time, didn't find any example or solution to apply multiple vcnl4000. The post http://forums.adafruit.com/viewtopic.php?f=25&t=13722 seems to allow me use any two pins as SCL&SDA. I am trying to use it but how can I read different data from the sensors? I know the sensor is fixed single address, can I read the data according to the port number? Could anyone give me some help, I am new to Arduino... Any help would be appreciated. Thank you guys!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: How to use multiple VCNL4000 on Arduino?

Post by adafruit_support_mike »

Those breakouts don't expose any address pins, so you'll need separate I2C buses for each sensor.

The good news is that you need two lines for the first I2C bus (one for SDA and one for SCK), but only one for additional buses after that (a new SDA). You can use the same SCK line for any number of buses.

User avatar
LeoC
 
Posts: 2
Joined: Mon Aug 11, 2014 6:35 pm

Re: How to use multiple VCNL4000 on Arduino?

Post by LeoC »

adafruit_support_mike wrote:Those breakouts don't expose any address pins, so you'll need separate I2C buses for each sensor.

The good news is that you need two lines for the first I2C bus (one for SDA and one for SCK), but only one for additional buses after that (a new SDA). You can use the same SCK line for any number of buses.
Hi Mike,

Many thanks for your reply. According to the library, it seems to be possible to specify any port as SDA. But how can I read data from different SDA? For example, I want to get the reading from both sensor A and sensor B. Or I want to get the reading from sensor A and then sensor B?

Thank you.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: How to use multiple VCNL4000 on Arduino?

Post by adafruit_support_mike »

You'll need one SoftwareSerial object per bus:

Code: Select all

    SoftI2cMaster bus_1( 8, 9 );  // pin 8 is SCK, pin 9 is SDA
    SoftI2cMaster bus_2( 8, 10 );  // pin 8 is SCK, pin 10 is SDA

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”