Skip to content

Added support for the AS7261 CIE sensor. #5

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

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions src/AS726X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ bool AS726X::begin(TwoWire &wirePort, uint8_t gain, uint8_t measurementMode)
{
_i2cPort = &wirePort;
_sensorVersion = virtualReadRegister(AS726x_HW_VERSION);
if (_sensorVersion != 0x3E && _sensorVersion != 0x3F) //HW version for AS7262 and AS7263

//HW version for AS7262, AS7263 and AS7261
if (_sensorVersion != 0x3E && _sensorVersion != 0x3F && _sensorVersion != 0x40)
{
return false;
}
Expand All @@ -28,12 +30,8 @@ bool AS726X::begin(TwoWire &wirePort, uint8_t gain, uint8_t measurementMode)

setGain(gain); //Set gain to 64x

setMeasurementMode(measurementMode); //One-shot reading of VBGYOR
setMeasurementMode(measurementMode); //One-shot mode

if (_sensorVersion == 0)
{
return false;
}
return true;
}

Expand All @@ -58,6 +56,12 @@ void AS726X::setMeasurementMode(uint8_t mode)
virtualWriteRegister(AS726x_CONTROL_SETUP, value); //Write
}

uint8_t AS726X::getMeasurementMode()
{
uint8_t value = virtualReadRegister(AS726x_CONTROL_SETUP); //Read
return (value & 0b00001100); //Isolate BANK bits.
}

//Sets the gain value
//Gain 0: 1x (power-on default)
//Gain 1: 3.7x
Expand All @@ -74,6 +78,12 @@ void AS726X::setGain(uint8_t gain)
virtualWriteRegister(AS726x_CONTROL_SETUP, value); //Write
}

uint8_t AS726X::getGain()
{
uint8_t value = virtualReadRegister(AS726x_CONTROL_SETUP); //Read
return (value & 0b00110000); //Isolate GAIN bits.
}

//Sets the integration value
//Give this function a uint8_t from 0 to 255.
//Time will be 2.8ms * [integration value]
Expand All @@ -82,6 +92,12 @@ void AS726X::setIntegrationTime(uint8_t integrationValue)
virtualWriteRegister(AS726x_INT_T, integrationValue); //Write
}

uint8_t AS726X::getIntegrationTime()
{
uint8_t value = virtualReadRegister(AS726x_INT_T); //Read
return value;
}

void AS726X::enableInterrupt()
{
//Read, mask/set, write
Expand Down Expand Up @@ -143,6 +159,14 @@ int AS726X::getU() { return(getChannel(AS7263_U)); }
int AS726X::getV() { return(getChannel(AS7263_V)); }
int AS726X::getW() { return(getChannel(AS7263_W)); }

//Get the various CIE readings
int AS726X::getX() { return(getChannel(AS7261_X)); }
int AS726X::getY() { return(getChannel(AS7261_Y)); }
int AS726X::getZ() { return(getChannel(AS7261_Z)); }
int AS726X::getNir() { return(getChannel(AS7261_NIR)); }
int AS726X::getDark() { return(getChannel(AS7261_DARK)); }
int AS726X::getClear() { return(getChannel(AS7261_CLEAR)); }

//A the 16-bit value stored in a given channel registerReturns
int AS726X::getChannel(uint8_t channelRegister)
{
Expand All @@ -166,6 +190,19 @@ float AS726X::getCalibratedU() { return(getCalibratedValue(AS7263_U_CAL)); }
float AS726X::getCalibratedV() { return(getCalibratedValue(AS7263_V_CAL)); }
float AS726X::getCalibratedW() { return(getCalibratedValue(AS7263_W_CAL)); }

float AS726X::getCalibratedX() { return(getCalibratedValue(AS7261_X_CAL)); }
float AS726X::getCalibratedY() { return(getCalibratedValue(AS7261_Y_CAL)); }
float AS726X::getCalibratedZ() { return(getCalibratedValue(AS7261_Z_CAL)); }
float AS726X::getCalibratedX1931() { return(getCalibratedValue(AS7261_X1931_CAL)); }
float AS726X::getCalibratedY1931() { return(getCalibratedValue(AS7261_Y1931_CAL)); }
float AS726X::getCalibratedUPri1976() { return(getCalibratedValue(AS7261_UPRI_CAL)); }
float AS726X::getCalibratedVPri1976() { return(getCalibratedValue(AS7261_VPRI_CAL)); }
float AS726X::getCalibratedU1976() { return(getCalibratedValue(AS7261_U_CAL)); }
float AS726X::getCalibratedV1976() { return(getCalibratedValue(AS7261_V_CAL)); }
float AS726X::getCalibratedDUV1976() { return(getCalibratedValue(AS7261_DUV_CAL)); }
int AS726X::getCalibratedLux() { return(getChannel(AS7261_LUX_CAL)); }
int AS726X::getCalibratedCCT() { return(getChannel(AS7261_CCT_CAL)); }

//Given an address, read four uint8_ts and return the floating point calibrated value
float AS726X::getCalibratedValue(uint8_t calAddress)
{
Expand Down
49 changes: 47 additions & 2 deletions src/AS726X.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AS726X {
uint8_t getTemperature();
float getTemperatureF();
void setMeasurementMode(uint8_t mode);
uint8_t getMeasurementMode();
bool dataAvailable();
void enableIndicator();
void disableIndicator();
Expand All @@ -28,9 +29,12 @@ class AS726X {
void setBulbCurrent(uint8_t current);
void softReset();
void setGain(uint8_t gain);
uint8_t getGain();
void setIntegrationTime(uint8_t integrationValue);
uint8_t getIntegrationTime();
void enableInterrupt();
void disableInterrupt();

//Get the various color readings
int getViolet();
int getBlue();
Expand All @@ -47,6 +51,14 @@ class AS726X {
int getV();
int getW();

//get X, Y, Z, NIR, Dark, Clear readings.
int getX();
int getY();
int getZ();
int getNir();
int getDark();
int getClear();

//Returns the various calibration data
float getCalibratedViolet();
float getCalibratedBlue();
Expand All @@ -62,6 +74,19 @@ class AS726X {
float getCalibratedV();
float getCalibratedW();

float getCalibratedX();
float getCalibratedY();
float getCalibratedZ();
float getCalibratedX1931();
float getCalibratedY1931();
float getCalibratedUPri1976();
float getCalibratedVPri1976();
float getCalibratedU1976();
float getCalibratedV1976();
float getCalibratedDUV1976();
int getCalibratedLux();
int getCalibratedCCT();

private:
TwoWire *_i2cPort;
int getChannel(uint8_t channelRegister);
Expand All @@ -72,9 +97,8 @@ class AS726X {
void virtualWriteRegister(uint8_t virtualAddr, uint8_t dataToWrite);
void writeRegister(uint8_t addr, uint8_t val);
uint8_t readRegister(uint8_t addr);

#define AS726X_ADDR 0x49 //7-bit unshifted default I2C Address
#define SENSORTYPE_AS7262 0x3E
#define SENSORTYPE_AS7263 0x3F

//Register addresses
#define AS726x_DEVICE_TYPE 0x00
Expand Down Expand Up @@ -117,11 +141,32 @@ class AS726X {
#define AS7263_V_CAL 0x24
#define AS7263_W_CAL 0x28

//AS7261 Registers
#define AS7261_X 0x08 //16b
#define AS7261_Y 0x0A //16b
#define AS7261_Z 0x0C //16b
#define AS7261_NIR 0x0E //16b
#define AS7261_DARK 0x10 //16b
#define AS7261_CLEAR 0x12 //16b
#define AS7261_X_CAL 0x14
#define AS7261_Y_CAL 0x18
#define AS7261_Z_CAL 0x1C
#define AS7261_X1931_CAL 0x20
#define AS7261_Y1931_CAL 0x24
#define AS7261_UPRI_CAL 0x28
#define AS7261_VPRI_CAL 0x2C
#define AS7261_U_CAL 0x30
#define AS7261_V_CAL 0x34
#define AS7261_DUV_CAL 0x38
#define AS7261_LUX_CAL 0x3C //16b
#define AS7261_CCT_CAL 0x3E //16b

#define AS72XX_SLAVE_TX_VALID 0x02
#define AS72XX_SLAVE_RX_VALID 0x01

#define SENSORTYPE_AS7262 0x3E
#define SENSORTYPE_AS7263 0x3F
#define SENSORTYPE_AS7261 0x40

#define POLLING_DELAY 5 //Amount of ms to wait between checking for virtual register changes

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy