Skip to content

Conversation

@noqman
Copy link
Contributor

@noqman noqman commented Dec 3, 2025

Hi, I am from Cytron Technologies. We are preparing a guidebook for our upcoming Pico 2 extension board, which includes the OPT4048 sensor.

Our use case requires RGB output, not only the original XYZ tristimulus values. So we have modified the existing library to add features that provide RGB values as well.

Changes as follow:

  1. Separated the original cie() logic into two parts:
  • A function to get XYZ values after the transformation matrix
  • A function to compute CIE chromaticity values
    (RGB conversion requires the XYZ values)
  1. Added a normalization function to make XYZ values brightness-independent

  2. Added a function to convert normalized XYZ into sRGB values

We’d really appreciate if you could review and approve this PR, so our users can conveniently access the updated support via the official CircuitPython Community Bundle when following our guide.

Please me know if there is any I need to change.

Thanks

@tannewt tannewt requested a review from FoamyGuy December 3, 2025 17:11
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this functionality! also for cleaning up the lux calculation to make it clearer.

I pushed some commits to fix the pre-commit errors and rename normalizedtosum to normalized_xyz

Looks good me. I tested this successfully with https://www.adafruit.com/product/6335 on Feather TFT S2 10.1.0-beta.1 by pointing it at the boards built-in neopixel lit up various colors using this modified version of the simpletest script from this repo:

import time

import board

from adafruit_opt4048 import OPT4048, ConversionTime, Mode, Range
import neopixel

pixels = neopixel.NeoPixel(board.NEOPIXEL, 1, auto_write=True, brightness=0.2)
pixels.fill(0xff0000)

i2c = board.I2C()  # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
sensor = OPT4048(i2c)

sensor.range = Range.AUTO
sensor.conversion_time = ConversionTime.TIME_100MS
sensor.mode = Mode.CONTINUOUS
while True:
    try:
        x, y, lux = sensor.cie
        print(f"CIE x:{x}, y:{y}, lux: {lux}", end=" ")
        print(f"K: {sensor.calculate_color_temperature(x,y)}", end=" ")
        print(f"rgb: {sensor.rgb}")
        time.sleep(1)
    except RuntimeError:
        # CRC check failed while reading data
        pass

@FoamyGuy FoamyGuy merged commit b6a02e2 into adafruit:main Dec 3, 2025
1 check passed
adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 4, 2025
Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 11.1.0 from 11.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#226 from dhalbert/WL_STOPPED
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#225 from dhalbert/revert-examples

Updating https://github.com/adafruit/Adafruit_CircuitPython_OPT4048 to 1.1.0 from 1.0.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_OPT4048#4 from noqman/main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants