control vcnl4200 proximity sensor

21 views Asked by At

I develop vcnl4200 proximity sensor. When I read PROXIMITY_DATA (0x08), It always return 0 ~ 3 value. I thinks it is too small to get a distance.

Nothing = 0 Something in front of this = 1~3

I checked Ambient Light Sensor value. It looks good. 0~15000

Here is my code.

#define DEFAULT_I2C_ADDR    (0x51)
#define REG_PS_THDH         0x07
#define REG_ALS_DATA        0x09
#define REG_PS_DATA         0x08
#define REG_ALS_CONF        0x00
#define REG_PS_CONF_1_2     0x03
#define REG_PS_CONF_3       0x04

#define VCNL4200_PS_CANC_REG 0x05
#define VCNL4200_PS_THDL_REG 0x06 //Proximity Sensor Threshold Data Low
#define VCNL4200_PS_THDH_REG 0x07 //Proximity Sensor Threshold Data High
#define REG_PS_INT          0x0D

#define DEFAULT_ALS_CONF 0b00000000
#define DEFAULT_PS_CONF1 0b11001010
#define DEFAULT_PS_CONF2 0b00001000
#define DEFAULT_PS_CONF3 0b01110001
#define DEFAULT_PS_MS    0b00000111

VCNL4200_configure_proximity_sensor(DEFAULT_PS_CONF1, DEFAULT_PS_CONF2);
VCNL4200_configure_proximity_sensor2(DEFAULT_PS_CONF3, DEFAULT_PS_MS);
VCNL4200_write_register(VCNL4200_PS_THDL_REG, 1000);
VCNL4200_write_register(VCNL4200_PS_THDH_REG, 5000);
while (1) {
    interrupt = VCNL4200_read_int();
    value = VCNL4200_get_distance();
    DEBUG_PRINTF("Int: 0x%02X, Distance: %d\n", interrupt, value);
    // value = VCNL4200_get_ambient_light();
    // DEBUG_PRINTF("Light: %d\n", value);
}

Manual

What I'm missing? thanks to read.

0

There are 0 answers