0

I've the VCNL 4000 Proximity Sensor I use some sample code and at the very beginning

the following code hangs (never finishes)

 readVCNLByte(0x81); is called

Can this problem be caused because the contact of the pin isn't very good.

I only but the part with pins in the sensor without to solder it.

Is it likely that this may be the problem ? I have not many experince with solder and the sensor is really small so i'd like to avoid it for first tests ;)

Here the code. The last output in the Serial window is "pre product"

  Serial.println("VCNL");
  Wire.begin();
  Serial.println("pre product");
  uint8_t rev = read8(VCNL4000_PRODUCTID);
   Serial.println("post product");
  if ((rev & 0xF0) != 0x10) {
    Serial.println("Sensor not found :(");
    while (1);
  }

Before

After

enter image description here

1
  • Try applying some lateral force to the connection. Or just solder the headers. It's not that hard to desolder them, if you remove the black plastic, before desoldering. – Gerben Jan 14 '15 at 19:18
1

You really can't expect this to work unsoldered. The contacts will be at best intermittent, and poor contact. Even a 'dry joint' where the pin is mostly surrounded by solder doesn't work well, these are the ultimate examples! You could however use an edge-connector, if you can find one; not something you see often nowadays.

0

Sorry .. my answer comes late .. I had the same issue, this has nothing to do with bad connexion between wires (not only at least). But by playing with some parameter (current value > 60mA) I noticed that the module begin to freeze more often. To fix that : You need to add a small delay within your readbyte function after a i2c.stop()

I found that an issue had been written about that : https://github.com/adafruit/VCNL4000/issues/1 They recommand a 170us delay

I'm testing myself at full current and max speed (an since 30min it didn't freeze)... Before it could freeze in a second.

Hope it helps ;)


EDIT : In order to better understand where the freeze comes from, I re-write a simple I2C library. I could get rid of the freeze by simple add a small delay in the i2c_start function (that send the start condition along with the slave address)

uint8_t i2c_start(uint8_t i2c_slave_address){
       //reset TWI control register
       TWCR = 0;
       //transmit start condition 
       TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
       //wait for end of transmission
       while((TWCR & (1<<TWINT))==0){
              _delay_us(75); // <-- here is the trick
       }
       if( (TWSR & 0xF8)!= TW_START ){
              return -1;
       }
       // load slave address into data register
       TWDR = i2c_slave_address;
       //start address transmission
       TWCR = (1<<TWINT) | (1<<TWEN);
       //wait for transmission
       while ( (TWCR & (1<<TWINT))==0 );
       //check if the slave did acknoledge the Read/Write mode
       uint8_t twst = TW_STATUS & 0xF8;
       if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ){
               return -1;
       }
       return 0;
}

you will need to add these libraries : util/twi.h (for the macro TW_STATUS .. TTW_MT_SLA_ACK and so on)

util/delay.h

stdlib.h (for the uint8_t way of typing variable ..not actually 100% sure)

I'm still not fully satisfy by this solution, but it is still more effective that the one that adafruit propose.

I suggest you write you own i2c library (5 functions : init / start / read / write / stop) you now have the start already .. so 4 left ;)

If you're still to much afraid : in twi.c ( .\arduino\avr\libraries\Wire\utility\twi.c) and twi_readFrom(...) function. On line 155 and 159 you will see that arduino send the start condition, but do not wait / take care that the transmission as been done... you can add a while function as previously describe to ensure it.


MASTER EDIT :

My previous solution didn't solve the issue neither... Actually reading the application note (Designing VCNL4000 into an Application : google that) gives the solution (page 7) enter image description here

after you send the command to perform a single measurement, you need to wait. I put a delay of 500ms and have none anywhere else. This works like a charm.

But for energy efficiency I recommend to put the uC in sleep mode for that period of time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.