This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

OPT3002: config800 2-byte code

Part Number: OPT3002

Hi Team, seeking for some assistance.

The customer have for opt3002. config[800] seems not to be working. N
 
config800 = [202,0]#this code is not working
#0xca00 which is 0b1100101000000000. first byte is 202, second is 0.
## 2-byte (hex) code for 800ms integration time, auto ranging

config100 = [196,0]#0xc400 which is 0b1100010000000000. first byte is 196,
second is 0 ## 2-byte (hex) code for 100ms integration, auto ranging.
"""detTest.py - program to test OPT3002 I2C detectors from Texas Instruments.
test for linearity by having 256 steps, all with bright2 as the intensity for r g b channels.
can adjust to make them similar intensities, i suppose. 2 readings are taken as the first reading is
indicative of the prior illumination condition. Thus, if changing colors between successive reads,
one will see a reading corresponding to illumination at a different color. Alternating illumination color
requires discarding the first reading, then the intensities are stable to within 1% or so. This program
controls both LED illumination color and intensity as well as reading out the detector. Currently only
1 detector, but will expand soon to 96.

note: works in testing virtual environment
source ~testing/bin/activate
see notes form 5/4/23"""

import time
import board # package for specifying input/outputs from raspberry pi board
from smbus import SMBus# package for i2c control
import neopixel # circuit python package for controlling LEDs
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

def intColor(color,pixNum):
    pixels[pixNum] = color
    pixels.show()
    #time.sleep(0.207)
    [b1,b2] = i2cbus.read_i2c_block_data(i2caddress,regR,2)#take first reading... wait and overwrite
    time.sleep(0.2) # the first reading is from the last illumination condition, so if swapping colors, this is bad - overwrite with next reading
    [b1,b2] = i2cbus.read_i2c_block_data(i2caddress,regR,2)#take second reading... use this one. Could take more and average, i suppose...
    b1Bin = format(b1,'#010b')
    b2Bin = format(b2,'#010b')
    exponent = int(b1Bin[:6],2)
    factor = int('0b'+b1Bin[6:]+b2Bin[2:],2)
    return int(1.2*factor*2**exponent)

def intens(b1,b2):#color,pix):
    b1Bin = format(b1,'#010b')
    b2Bin = format(b2,'#010b')
    exponent = int(b1Bin[:6],2)
    factor = int('0b'+b1Bin[6:]+b2Bin[2:],2)
    return int(2**exponent*1.2*factor)

pixel_pin = board.D12
num_pix = 96
dlay = 0.3
pixels = neopixel.NeoPixel(pixel_pin,num_pix,brightness = 1,auto_write=False)
pix = 43 # particular LED to be used for this test

i2cbus = SMBus(1)
i2caddress = 0x44 ## Address of detector on i2c bus
config800 = [202,0]#this code is not working... look into it. #0xca00 which is 0b1100101000000000. first byte is 202, second is 0. ## 2-byte (hex) code for 800ms integration time, auto ranging
config100 = [196,0]#0xc400 which is 0b1100010000000000. first byte is 196, second is 0 ## 2-byte (hex) code for 100ms integration, auto ranging
regW = 0x1 ## register which to configuration should be written. write as list of two integers (bytes), as above.
regR = 0x0 ## register to be read

data = pd.DataFrame(columns = ['red','green','blue']) # create dataframe to store intensities for each color

i2cbus.write_i2c_block_data(i2caddress,regW,config100)# write to config bufffer - telling detector to autorange, 100 ms integration, etc... detection conditions on this open channel for i2caddress

for bright in range(256):
    bright2 = 125
    red = (bright2,0,0)
    green = (0,bright2,0)
    blue = (0,0,bright2)
    #white = (bright,bright,bright)

    #if colr == 'r':
    data.loc[bright,'red'] = intColor(red,pix)#red,pix)
    #if colr == 'g':
    data.loc[bright,'green'] = intColor(green,pix)#green,pix)
    #if colr == 'b':
    data.loc[bright,'blue'] = intColor(blue,pix)#blue,pix)
    #data.loc[bright,'white'] = intColor(white,pix)#(b1,b2)#white,pix)
    print('Intensities (r,g,b): ',data.loc[bright,:])

pixels.fill((0,0,0)) # turn all pixels off/set to dark
pixels.show()
## Plot each color trace ##
data['blue'].plot()
#data['white'].plot()
data['red'].plot()
data['green'].plot()
plt.legend()
plt.show()



Thank you very much

Thank you.

-Mark