Wire.available() always 0

Hi there,

I'm pretty new to the hardware part of technology, been programming a while. Now I've got this sparkfun VCNL4000 connected (or trying to) to my spark core. (https://www.sparkfun.com/products/10901)

I've hooked it up as follows at the moment:

Where the vcnl ports are as follows:

1 = IR+
4 = SDA
5 = SCL
6 = GND
7 = 3.3v

I run the example code linked to from the spark website but it keeps hanging up on

while(!Wire.available());

The value returned is always 0.

My current code is currently this: #define VCNL4000_ADDRESS 0x13 //I2C Address of the board// VCNL4000 Registe - Pastebin.com

The only other thing I can think of is that the 3.3v supply for the ir+ isn't enough, but the sparkfun website suggests anything between 2.5-5.5v or am I mis interpreting this? Or is that possibly not the problem at all.

As I said, I'm kind of lost of what it can be. Any ideas?

Thanks,

Benjamin

Hi @m0rph3v5

Wire.available() returns the number of bytes available to be read and I am not sure how your code is supposed to work. Are there supposed to be bytes to be read at the start of loop()? That would mean you are in the middle of an i2c read.

Does the call to initVCNL4000() succeed and print VNCL4000 Online…?

The module has no pull-up resistors on the i2c lines. You will need to add 4.7k to 10k pull-ups on the SDA and SCL lines. :slight_smile:

1 Like

@bko

It’s not supposed to work in it’s current state, I was just messing around to see where it was going wrong. It tells me ‘failed to initializeFF’.

@peekay123

can you link to something that explains what you are referring to? does the arduino uno differ from the spark in that way that it’s needed?

Hi @m0rph3v5

Yes the Arduino and the Spark are not exactly the same and the i2c library does not put the I/O pins into pull up mode when you are reading data, so you need two resistors around 4.7k ohm in value and you should connect them from the D0 and D1 pins to the 3V3 pin on the core.

1 Like

Even the Arduino’s internal pullup resistors don’t work after a certain point (more than one or two devices, long runs, that sort of thing).