ESPHome apds9960 register setting

Is it possible to read and set the registers of APDS9960 sensors from ESPHome?

I have some of them and am getting inconsistent results and now suspect that they are set differently. For example, some are far less sensitive than others and some the ambient light sensor seems to be disabled.

Thanks.

Richard

Not with the esphome implementation I think. However the i2c interface is documented, and no doubt there are libraries that you could add to esphome as a custom component.

Thanks, @nickrout - scratching around in the apds9960.cpp file in the ESPHome directories I found entries like this:

// Control (0x8F) ->
  uint8_t val = 0;
  APDS9960_ERROR_CHECK(this->read_byte(0x8F, &val));
  val &= 0b00111111;
  uint8_t led_drive = 0;  // led drive, 0 -> 100mA, 1 -> 50mA, 2 -> 25mA, 3 -> 12.5mA
  val |= (led_drive & 0b11) << 6;

  val &= 0b11110011;
  uint8_t proximity_gain = 2;  // proximity gain, 0 -> 1x, 1 -> 2X, 2 -> 4X, 4 -> 8X
  val |= (proximity_gain & 0b11) << 2;

  val &= 0b11111100;
  uint8_t ambient_gain = 1;  // ambient light gain, 0 -> 1x, 1 -> 4x, 2 -> 16x, 3 -> 64x
  val |= (ambient_gain & 0b11) << 0;
  APDS9960_WRITE_BYTE(0x8F, val);

  // Pers (0x8C) -> 0x11 (2 consecutive proximity or ALS for interrupt)
  APDS9960_WRITE_BYTE(0x8C, 0x11);
  // Config 2 (0x90) -> 0x01 (no saturation interrupts or LED boost)
  APDS9960_WRITE_BYTE(0x90, 0x01);
  // Config 3 (0x9F) -> 0x00 (enable all photodiodes, no SAI)
  APDS9960_WRITE_BYTE(0x9F, 0x00);
  // GPenTh (0xA0, gesture enter threshold) -> 0x28 (also 0x32)
  APDS9960_WRITE_BYTE(0xA0, 0x28);
  // GPexTh (0xA1, gesture exit threshold) -> 0x1E
  APDS9960_WRITE_BYTE(0xA1, 0x1E);

  // GConf 1 (0xA2, gesture config 1) -> 0x40 (4 gesture events for interrupt (GFIFO 3), 1 for exit)
  APDS9960_WRITE_BYTE(0xA2, 0x40);

  // GConf 2 (0xA3, gesture config 2) ->
  APDS9960_ERROR_CHECK(this->read_byte(0xA3, &val));
  val &= 0b10011111;
  uint8_t gesture_gain = 2;  // gesture gain, 0 -> 1x, 1 -> 2x, 2 -> 4x, 3 -> 8x
  val |= (gesture_gain & 0b11) << 5;

  val &= 0b11100111;
  uint8_t gesture_led_drive = 0;  // gesture led drive, 0 -> 100mA, 1 -> 50mA, 2 -> 25mA, 3 -> 12.5mA
  val |= (gesture_led_drive & 0b11) << 3;

I think I’ll play with those a bit and see what happens! I must say that I’m way out of my depth, this is just going to be a complete gamble! :wink:

Richard

Edited them in a text editor, based on the datasheet, recompiled and uploaded but seems to have not helped.

The entries seem to have reverted in the .cpp file, too, so not sure where they are being sourced from.

Richard