Menu

AS7262 Visible Light 6-channel spectral (visible) sensor

Anobium
2024-04-26
2024-06-09
  • Anobium

    Anobium - 2024-04-26

    A new library that uses the new float capability, but, you can use this sensor with out having to use floats.

    The library supports:

    AS7262 Visible Light 6-channel spectral (visible) sensor
    AS7263 Near Infrared Spectral Sensor

    These sensors detects six distinct channels of visible light with this spectral sensor.
    Unlike normal RGB colour sensors, with the AS7262 provides six bands of colour readings that roughly translate to red, orange, yellow, green, blue, and violet. The rainbow.

    The two onboard white LEDs provides illumination to give more accurate spectral readings and also measure the reflectivity of surfaces.

    The LEDs are typically high-quality ones with a CRI of >=90 and a colour temperature of 4,000K for consistent and accurate colour rendering.

    With this sensor, like analysing different light sources, measuring the transmission of light through materials or solutions (with an additional light source).

    The AS7262 6-Channel Spectral Sensor Breakout is an I2C interface and is 3.3V or 5V compatible.

    Demonstration program is here: https://github.com/GreatCowBASIC/Demonstration_Sources/blob/main/Spectral_Sensor_Solutions/Spectral_Sensor_AS726X/AS7262_Spectral_Sensor.gcb

    See this video

    Enjoy


    Documentation

    I2C interface (address: 0x49)
    6 spectral channels (450, 500, 550, 570, 600, 650nm)
    2 onboard illumination LEDs
    3.3V or 5V compatible
    Reverse polarity protection
    
    *************************************************************************
    
    ! Utility methods
    Sub AS726X_Init( ( optional AS726XGain as Byte = 3, optional AS726XMeasurementMode as Byte = 3 )     )
        Sets up the sensor for constant read
        Returns the sensor version (AS7262 or AS7263)
        Returns the sensor error number
    
        Set to 12.5mA (minimum)
        Turn off to avoid heating the sensor
        Set to 8mA (maximum)
        Turn off lights to save power
        setIntegrationTime 50 * 2.8ms = 140ms. 0 to 255 is valid.
        If you use Mode 2 or 3 (all the colors) then integration time is double. 140*2 = 280ms between readings.
        Set gain to 64x
        One-shot reading of VBGYOR
    
    Sub AS726X_SetGain( in AS726XSetGain = 0b00..0b11 )
        Sets the measurement mode
        Mode 0: Continuous reading of VBGY (7262) / STUV (7263)
        Mode 1: Continuous reading of GYOR (7262) / RTUX (7263)
        Mode 2: Continuous reading of all channels (power-on default)
        Mode 3: One-shot reading of all channels
    
    Sub AS726X_TakeMeasurements()
        Tells IC to take measurements and polls for data ready flag
        Clear DATA_RDY flag when using Mode 3
        Set mode 3 for one shot measurement of all channels
        Wait for data to be ready
        Readings can now be accessed via getViolet(), getBlue(), etc
    
    Function AS726X_getVersion()
        Return version value
    
    Sub AS726X_TakeMeasurementsWithBulb()
        Turns on bulb, takes measurements, turns off bulb
    
    Function AS726X_GetTemperature()
        Returns the temperature in C
        Pretty inaccurate: +/-8.5C
    
    Sub AS726X_SetMeasurementMode( in AS726XMeasurementMode = 0b00..0b11 )
        Sets the measurement mode
        Mode 0: Continuous reading of VBGY (7262) / STUV (7263)
        Mode 1: Continuous reading of GYOR (7262) / RTUX (7263)
        Mode 2: Continuous reading of all channels (power-on default)
        Mode 3: One-shot reading of all channels
    
    Function AS726X_DataAvailable()
        Checks to see if DRDY flag is set in the control setup register
    
    Sub AS726X_ClearDataAvailable()
        Clears the DRDY flag
        Normally this should clear when data registers are read
    
    Sub AS726X_EnableIndicator()
        Enable the onboard indicator LED
    
    Sub AS726X_DisableIndicator()
        Disable the onboard indicator LED
    
    Sub AS726X_SetIndicatorCurrent( in AS726xCurrent = 0b00..0b11 )
        Set the current limit of onboard LED. Default is max 8mA = 0b11.
    
    Sub AS726X_EnableBulb()
        Enable the onboard 5700k or external incandescent bulb
    
    Sub AS726X_DisableBulb()
        Disable the onboard 5700k or external incandescent bulb
    
    Sub AS726X_SetBulbCurrent( in AS726xCurrent = 0b00..0b11 )
        Set the current limit of bulb/LED.
        Current 0: 12.5mA
        Current 1: 25mA
        Current 2: 50mA
        Current 3: 100mA
    
    Sub AS726X_SoftReset()
        Does a soft reset
        Delays sensor operations for 1000ms to reset
    
    Sub AS726X_SetIntegrationTime( in AS726XValue as Byte)
        Sets the integration value
        Give this function a from 0 to 255.
        Time will be 2.8ms * [AS726XValue]
    
    Sub AS726X_enableInterrupt()
    Sub AS726X_disableInterrupt()
    
    !Get the various color readings - the 16-bit value stored in a given channel register
    
    Function AS7262_getViolet()
    Function AS7262_getBlue()
    Function AS7262_getGreen()
    Function AS7262_getYellow()
    Function AS7262_getOrange()
    Function AS7262_getRed()
    
    !Get the various NIR readings - the 16-bit value stored in a given channel register
    Function AS7263_getR()
    Function AS7263_getS()
    Function AS7263_getT()
    Function AS7263_getU()
    Function AS7263_getV()
    Function AS7263_getW()
    
    !AS7263 specific - returns the various calibration data as float
    Function AS7262_getCalibratedViolet()
    Function AS7262_ggetCalibratedBlue()
    Function AS7262_ggetCalibratedGreen()
    Function AS7262_ggetCalibratedYellow()
    Function AS7262_ggetCalibratedOrange()
    Function AS7262_ggetCalibratedRed()
    
    ! AS7263 specific - returns the various calibration data as float
    Function AS7263_getCalibratedR()
    Function AS7263_getCalibratedS()
    Function AS7263_getCalibratedT()
    Function AS7263_getCalibratedU()
    Function AS7263_getCalibratedV()
    Function AS7263_getCalibratedW()
    
    !Private methods
    Function AS726X_GetCalibrated ( AS726XCalAddress as Byte ) as Single
        Given an address, read four uint8_ts and return the floating point calibrated value
    
     
    ❤️
    3
  • Anobium

    Anobium - 2024-06-09

    Maybe. This is a very sophisticated device. A clone from AliExpress may not work as expected.

    Sound too cheap to real to me.

     
  • stan cartwright

    stan cartwright - 2024-06-09

    The sensor is probably real. Others are £21 eg adafruit etc.
    I'll order the ae one. useful project. a bar graph display maybe?

     
    • Anobium

      Anobium - 2024-06-09

      I have implemented Floats for PIC, but, you can use the Integer scheme for the sensor when using AVR.

       
  • stan cartwright

    stan cartwright - 2024-06-09

    thanks Evan. see in 2 weeks £7.65 but £11.69 with tax and postage.
    still, beer money. a useful project. integers fine and better really.

     

Log in to post a comment.