Skip to content

Commit 71cfb8f

Browse files
committed
- Added support for the AS7261 CIE sensor.
- Added get fcns for gain and integration time. - Minor cleanup.
1 parent 2bb1c18 commit 71cfb8f

File tree

2 files changed

+90
-8
lines changed

2 files changed

+90
-8
lines changed

src/AS726X.cpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ bool AS726X::begin(TwoWire &wirePort, uint8_t gain, uint8_t measurementMode)
1212
{
1313
_i2cPort = &wirePort;
1414
_sensorVersion = virtualReadRegister(AS726x_HW_VERSION);
15-
if (_sensorVersion != 0x3E && _sensorVersion != 0x3F) //HW version for AS7262 and AS7263
15+
16+
//HW version for AS7262, AS7263 and AS7261
17+
if (_sensorVersion != 0x3E && _sensorVersion != 0x3F && _sensorVersion != 0x40)
1618
{
1719
return false;
1820
}
@@ -28,12 +30,8 @@ bool AS726X::begin(TwoWire &wirePort, uint8_t gain, uint8_t measurementMode)
2830

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

31-
setMeasurementMode(measurementMode); //One-shot reading of VBGYOR
33+
setMeasurementMode(measurementMode); //One-shot mode
3234

33-
if (_sensorVersion == 0)
34-
{
35-
return false;
36-
}
3735
return true;
3836
}
3937

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

59+
uint8_t AS726X::getMeasurementMode()
60+
{
61+
uint8_t value = virtualReadRegister(AS726x_CONTROL_SETUP); //Read
62+
return (value & 0b00001100); //Isolate BANK bits.
63+
}
64+
6165
//Sets the gain value
6266
//Gain 0: 1x (power-on default)
6367
//Gain 1: 3.7x
@@ -74,6 +78,12 @@ void AS726X::setGain(uint8_t gain)
7478
virtualWriteRegister(AS726x_CONTROL_SETUP, value); //Write
7579
}
7680

81+
uint8_t AS726X::getGain()
82+
{
83+
uint8_t value = virtualReadRegister(AS726x_CONTROL_SETUP); //Read
84+
return (value & 0b00110000); //Isolate GAIN bits.
85+
}
86+
7787
//Sets the integration value
7888
//Give this function a uint8_t from 0 to 255.
7989
//Time will be 2.8ms * [integration value]
@@ -82,6 +92,12 @@ void AS726X::setIntegrationTime(uint8_t integrationValue)
8292
virtualWriteRegister(AS726x_INT_T, integrationValue); //Write
8393
}
8494

95+
uint8_t AS726X::getIntegrationTime()
96+
{
97+
uint8_t value = virtualReadRegister(AS726x_INT_T); //Read
98+
return value;
99+
}
100+
85101
void AS726X::enableInterrupt()
86102
{
87103
//Read, mask/set, write
@@ -143,6 +159,14 @@ int AS726X::getU() { return(getChannel(AS7263_U)); }
143159
int AS726X::getV() { return(getChannel(AS7263_V)); }
144160
int AS726X::getW() { return(getChannel(AS7263_W)); }
145161

162+
//Get the various CIE readings
163+
int AS726X::getX() { return(getChannel(AS7261_X)); }
164+
int AS726X::getY() { return(getChannel(AS7261_Y)); }
165+
int AS726X::getZ() { return(getChannel(AS7261_Z)); }
166+
int AS726X::getNir() { return(getChannel(AS7261_NIR)); }
167+
int AS726X::getDark() { return(getChannel(AS7261_DARK)); }
168+
int AS726X::getClear() { return(getChannel(AS7261_CLEAR)); }
169+
146170
//A the 16-bit value stored in a given channel registerReturns
147171
int AS726X::getChannel(uint8_t channelRegister)
148172
{
@@ -166,6 +190,19 @@ float AS726X::getCalibratedU() { return(getCalibratedValue(AS7263_U_CAL)); }
166190
float AS726X::getCalibratedV() { return(getCalibratedValue(AS7263_V_CAL)); }
167191
float AS726X::getCalibratedW() { return(getCalibratedValue(AS7263_W_CAL)); }
168192

193+
float AS726X::getCalibratedX() { return(getCalibratedValue(AS7261_X_CAL)); }
194+
float AS726X::getCalibratedY() { return(getCalibratedValue(AS7261_Y_CAL)); }
195+
float AS726X::getCalibratedZ() { return(getCalibratedValue(AS7261_Z_CAL)); }
196+
float AS726X::getCalibratedX1931() { return(getCalibratedValue(AS7261_X1931_CAL)); }
197+
float AS726X::getCalibratedY1931() { return(getCalibratedValue(AS7261_Y1931_CAL)); }
198+
float AS726X::getCalibratedUPri1976() { return(getCalibratedValue(AS7261_UPRI_CAL)); }
199+
float AS726X::getCalibratedVPri1976() { return(getCalibratedValue(AS7261_VPRI_CAL)); }
200+
float AS726X::getCalibratedU1976() { return(getCalibratedValue(AS7261_U_CAL)); }
201+
float AS726X::getCalibratedV1976() { return(getCalibratedValue(AS7261_V_CAL)); }
202+
float AS726X::getCalibratedDUV1976() { return(getCalibratedValue(AS7261_DUV_CAL)); }
203+
int AS726X::getCalibratedLux() { return(getChannel(AS7261_LUX_CAL)); }
204+
int AS726X::getCalibratedCCT() { return(getChannel(AS7261_CCT_CAL)); }
205+
169206
//Given an address, read four uint8_ts and return the floating point calibrated value
170207
float AS726X::getCalibratedValue(uint8_t calAddress)
171208
{

src/AS726X.h

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AS726X {
1919
uint8_t getTemperature();
2020
float getTemperatureF();
2121
void setMeasurementMode(uint8_t mode);
22+
uint8_t getMeasurementMode();
2223
bool dataAvailable();
2324
void enableIndicator();
2425
void disableIndicator();
@@ -28,9 +29,12 @@ class AS726X {
2829
void setBulbCurrent(uint8_t current);
2930
void softReset();
3031
void setGain(uint8_t gain);
32+
uint8_t getGain();
3133
void setIntegrationTime(uint8_t integrationValue);
34+
uint8_t getIntegrationTime();
3235
void enableInterrupt();
3336
void disableInterrupt();
37+
3438
//Get the various color readings
3539
int getViolet();
3640
int getBlue();
@@ -47,6 +51,14 @@ class AS726X {
4751
int getV();
4852
int getW();
4953

54+
//get X, Y, Z, NIR, Dark, Clear readings.
55+
int getX();
56+
int getY();
57+
int getZ();
58+
int getNir();
59+
int getDark();
60+
int getClear();
61+
5062
//Returns the various calibration data
5163
float getCalibratedViolet();
5264
float getCalibratedBlue();
@@ -62,6 +74,19 @@ class AS726X {
6274
float getCalibratedV();
6375
float getCalibratedW();
6476

77+
float getCalibratedX();
78+
float getCalibratedY();
79+
float getCalibratedZ();
80+
float getCalibratedX1931();
81+
float getCalibratedY1931();
82+
float getCalibratedUPri1976();
83+
float getCalibratedVPri1976();
84+
float getCalibratedU1976();
85+
float getCalibratedV1976();
86+
float getCalibratedDUV1976();
87+
int getCalibratedLux();
88+
int getCalibratedCCT();
89+
6590
private:
6691
TwoWire *_i2cPort;
6792
int getChannel(uint8_t channelRegister);
@@ -72,9 +97,8 @@ class AS726X {
7297
void virtualWriteRegister(uint8_t virtualAddr, uint8_t dataToWrite);
7398
void writeRegister(uint8_t addr, uint8_t val);
7499
uint8_t readRegister(uint8_t addr);
100+
75101
#define AS726X_ADDR 0x49 //7-bit unshifted default I2C Address
76-
#define SENSORTYPE_AS7262 0x3E
77-
#define SENSORTYPE_AS7263 0x3F
78102

79103
//Register addresses
80104
#define AS726x_DEVICE_TYPE 0x00
@@ -117,11 +141,32 @@ class AS726X {
117141
#define AS7263_V_CAL 0x24
118142
#define AS7263_W_CAL 0x28
119143

144+
//AS7261 Registers
145+
#define AS7261_X 0x08 //16b
146+
#define AS7261_Y 0x0A //16b
147+
#define AS7261_Z 0x0C //16b
148+
#define AS7261_NIR 0x0E //16b
149+
#define AS7261_DARK 0x10 //16b
150+
#define AS7261_CLEAR 0x12 //16b
151+
#define AS7261_X_CAL 0x14
152+
#define AS7261_Y_CAL 0x18
153+
#define AS7261_Z_CAL 0x1C
154+
#define AS7261_X1931_CAL 0x20
155+
#define AS7261_Y1931_CAL 0x24
156+
#define AS7261_UPRI_CAL 0x28
157+
#define AS7261_VPRI_CAL 0x2C
158+
#define AS7261_U_CAL 0x30
159+
#define AS7261_V_CAL 0x34
160+
#define AS7261_DUV_CAL 0x38
161+
#define AS7261_LUX_CAL 0x3C //16b
162+
#define AS7261_CCT_CAL 0x3E //16b
163+
120164
#define AS72XX_SLAVE_TX_VALID 0x02
121165
#define AS72XX_SLAVE_RX_VALID 0x01
122166

123167
#define SENSORTYPE_AS7262 0x3E
124168
#define SENSORTYPE_AS7263 0x3F
169+
#define SENSORTYPE_AS7261 0x40
125170

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

0 commit comments

Comments
 (0)