Skip to content

drivers: sensor: APDS9306: Lux conversion #91105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Kampi
Copy link
Contributor

@Kampi Kampi commented Jun 5, 2025

  • Add lux conversion to APDS-9306 driver
  • Change settings of gain, resolution and frequency to index-based settings
  • Add Device Tree overlay sample for APDS-9306
  • Fix wrong board name in light_polling README
  • Add value checks for the attribute set API call
  • Remove the reading of the sensor attributes from the sensor and use buffered values instead
  • Rename frequency property to measurement period

Closes #91104

@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch 12 times, most recently from 5f0816e to de5cd56 Compare June 5, 2025 10:31
@Kampi Kampi marked this pull request as ready for review June 5, 2025 10:31
@Kampi Kampi changed the title drivers: sensor: APDS9306: Lux conversion and sample drivers: sensor: APDS9306: Lux conversion Jun 5, 2025
@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch from de5cd56 to c11ac8b Compare June 5, 2025 17:27
@msalau
Copy link
Contributor

msalau commented Jun 20, 2025

There is a disconnect between gain property set in the devicetree and the ALS_GAIN register. Property defines the desired gain value, but register expects an index, not the value itself. The same issue exists for the ALS_MEAS_RATE register values (resolution and rate).

A possible solution:

  1. Reorder gain values in the yaml file to match the datasheet:
  gain:
    type: int
    default: 1
    enum:
      - 1
      - 3
      - 6
      - 9
      - 18
  1. Save the gain enum's index in config:
.gain_idx = DT_INST_ENUM_IDX(inst, gain), \
  1. Write index into the register:
	value = config->gain_idx;
	LOG_DBG("Write configuration 0x%x to register 0x%x", value, APDS9306_REGISTER_ALS_GAIN);
	if (i2c_reg_write_byte_dt(&config->i2c, APDS9306_REGISTER_ALS_GAIN, value)) {
		return -EFAULT;
	}

This should fix initialization, I believe.

I can't comment about the conversion part though.

@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch from 3763659 to e7adcf2 Compare June 23, 2025 10:52
@github-actions github-actions bot added the platform: nRF Nordic nRFx label Jun 23, 2025
@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch 2 times, most recently from 32d43b2 to cfc2176 Compare June 23, 2025 11:06
@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch from cfc2176 to 9145369 Compare June 23, 2025 11:15
@Kampi Kampi requested a review from msalau June 23, 2025 11:27
@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch from 9145369 to 0c8b007 Compare June 23, 2025 17:08
@kartben kartben dismissed their stale review June 24, 2025 08:51

addressed

@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch from 0c8b007 to 7b5baa1 Compare June 24, 2025 13:36
@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch 2 times, most recently from 6d60f42 to 1f2f3e1 Compare June 25, 2025 13:41
@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch from 1f2f3e1 to 90c9187 Compare June 27, 2025 20:22
- Add lux conversion to APDS-9306 driver
- Change settings of gain, resolution and
frequency to index-based settings
- Add Device Tree overlay sample for APDS-9306
- Fix wrong board name in light_polling README
- Add value checks for the attribute set API call
- Remove the reading of the sensor attributes
from the sensor and use buffered values instead
- Rename `frequency` property to `measurement period`

Closes zephyrproject-rtos#91104

Signed-off-by: Daniel Kampert <[email protected]>
@Kampi Kampi force-pushed the Add-Lux-conversion-for-APDS-9306 branch from 90c9187 to dc0c04a Compare June 27, 2025 20:26
Copy link

@Kampi

This comment was marked as outdated.

@kartben
Copy link
Contributor

kartben commented Jun 30, 2025

Hi, please wait a bit before accepting this PR. I want to check the results against a lux meter and I will do this this week.

It probably won't make it in 4.2 anyway as it's now entered feature freeze, so no rush :)

@MaureenHelm
Copy link
Member

please wait a bit before accepting this PR. I want to check the results against a lux meter and I will do this this week.

Adding the DNM label to prevent merge. Please remove the label when you're done testing

@MaureenHelm MaureenHelm added the DNM This PR should not be merged (Do Not Merge) label Jul 25, 2025
@Kampi
Copy link
Contributor Author

Kampi commented Jul 26, 2025

please wait a bit before accepting this PR. I want to check the results against a lux meter and I will do this this week.

Adding the DNM label to prevent merge. Please remove the label when you're done testing

Thanks :)
I´ve tested it already and compared it against a cheap luxmeter. The results are good.

Edit: How can I remove the label?

@kartben kartben removed the DNM This PR should not be merged (Do Not Merge) label Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add lux conversion and for APDS-9306 driver
5 participants