AS7262 Visible spectral sensor but I just need the Red

I’m attempting to retrieve only the red wavelength data off of the AS7262 Visible spectral sensor but not having the greatest luck modifying the sample code. Sample code 1 gives you a list of different functions that can be implemented and one of those include “int getRed();” but I cant figure out how to implement this into the existing sample . Thank you for the help


/*

This is a library written for the AS726X Spectral Sensor (Visible or IR) with I2C firmware

specially loaded. SparkFun sells these at its website: www.sparkfun.com

Written by Nathan Seidle & Andrew England @ SparkFun Electronics, July 12th, 2017

https://github.com/sparkfun/Qwiic_Spect … sor_AS726X

Do you like this library? Help support SparkFun. Buy a board!

Development environment specifics:

Arduino IDE 1.8.1

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program. If not, see <http://www.gnu.org/licenses/>.

—AVAILABLE FUNCTIONS—

AS726X(TwoWire &wirePort = Wire, byte gain = 3, byte measurementMode = 3);

void takeMeasurements();

void takeMeasurementsWithBulb();

void printMeasurements();

byte getTemperature();

float getTemperatureF();

void setMeasurementMode(byte mode);

boolean dataAvailable();

void enableIndicator();

void disableIndicator();

void setIndicatorCurrent(byte current);

void enableBulb();

void disableBulb();

void setBulbCurrent(byte current);

void softReset();

void setGain(byte gain);

void setIntegrationTime(byte integrationValue);

void enableInterrupt();

void disableInterrupt();

//Get the various color readings

int getViolet();

int getBlue();

int getGreen();

int getYellow();

int getOrange();

int getRed();

//Get the various NIR readings

int getR();

int getS();

int getT();

int getU();

int getV();

int getW();

//Returns the various calibration data

float getCalibratedViolet();

float getCalibratedBlue();

float getCalibratedGreen();

float getCalibratedYellow();

float getCalibratedOrange();

float getCalibratedRed();

float getCalibratedR();

float getCalibratedS();

float getCalibratedT();

float getCalibratedU();

float getCalibratedV();

float getCalibratedW();

*/

#include “AS726X.h”

AS726X sensor;

void setup() {

sensor.begin();

}

void loop() {

sensor.takeMeasurements();

sensor.printMeasurements();

}


It looks like the printMeasurements function prints everything. Has that worked for you?

You can try something like Serial.println(sensor.getRed());

programmer1200:
I’m attempting to retrieve only the red wavelength data off of the AS7262 Visible spectral sensor but not having the greatest luck modifying the sample code. Sample code 1 gives you a list of different functions that can be implemented and one of those include “int getRed();” but I cant figure out how to implement this into the existing sample . Thank you for the help


/*

This is a library written for the AS726X Spectral Sensor (Visible or IR) with I2C firmware

specially loaded. SparkFun sells these at its website: www.sparkfun.com

Written by Nathan Seidle & Andrew England @ SparkFun Electronics, July 12th, 2017

https://github.com/sparkfun/Qwiic_Spect … sor_AS726X

Do you like this library? Help support SparkFun. Buy a board!

Development environment specifics:

Arduino IDE 1.8.1

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program. If not, see <http://www.gnu.org/licenses/>.

—AVAILABLE FUNCTIONS—

AS726X(TwoWire &wirePort = Wire, byte gain = 3, byte measurementMode = 3);

void takeMeasurements();

void takeMeasurementsWithBulb();

void printMeasurements();

byte getTemperature();

float getTemperatureF();

void setMeasurementMode(byte mode);

boolean dataAvailable();

void enableIndicator();

void disableIndicator();

void setIndicatorCurrent(byte current);

void enableBulb();

void disableBulb();

void setBulbCurrent(byte current);

void softReset();

void setGain(byte gain);

void setIntegrationTime(byte integrationValue);

void enableInterrupt();

void disableInterrupt();

//Get the various color readings

int getViolet();

int getBlue();

int getGreen();

int getYellow();

int getOrange();

int getRed();

//Get the various NIR readings

int getR();

int getS();

int getT();

int getU();

int getV();

int getW();

//Returns the various calibration data

float getCalibratedViolet();

float getCalibratedBlue();

float getCalibratedGreen();

float getCalibratedYellow();

float getCalibratedOrange();

float getCalibratedRed();

float getCalibratedR();

float getCalibratedS();

float getCalibratedT();

float getCalibratedU();

float getCalibratedV();

float getCalibratedW();

*/

#include “AS726X.h”

AS726X sensor;

void setup() {

sensor.begin();

}

void loop() {

sensor.takeMeasurements();

sensor.printMeasurements();

}


Hi,

The simplest way of doing is:

#include "AS726X.h"

AS726X sensor;

int redColor =0;

void setup() {
  sensor.begin();
}

void loop() {
redColor = getRed();
Serial.println(redColor);
  sensor.takeMeasurements();
  sensor.printMeasurements();
}