AS726X NIR/VIS Spectral Sensor Hookup Guide
Contributors:
Englandsaurus
Library Overview
Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.
Before we get started, we'll need to download and install SparkFun's AS726X Arduino library. You can use the Arduino Library Manager by searching "SparkFun AS726X" to automatically install. Or you can download the library and install it using the button below.
Before we get started developing a sketch, let's look at the available functions of the library.
bool begin(TwoWire &wirePort, byte gain, byte measurementMode);
--- Initializes the sensor with user given values for the wire port, gain, and measurementvoid takeMeasurements();
--- Sensor writes spectral measurements to memory locations.void takeMeasurementsWithBulb();
--- Illuminates onboard bulb, callstakeMeasurements();
, then turns off the onboard bulb.byte getTemperature();
--- Fetches the temperature in degrees Celsius.float getTemperatureF();
--- Fetches the temperature in degrees Fahrenheit.void setMeasurementMode(byte mode);
--- Changes the measurement mode to 0, 1, 2, or 3- 0: Continuous reading of VBGY (Visible) / STUV (IR)
- 1: Continuous reading of GYOR (Visible) / RTUX (IR)
- 2: Continuous reading of all channels
- 3: One-shot reading of all channels (power-on default)
boolean dataAvailable();
--- Returnstrue
orfalse
based on whether or not data is available to be read.void enableIndicator();
--- Powers on the surface mounted blue indicator LED.void disableIndicator();
--- Powers off the surface mounted blue indicator LED.void setIndicatorCurrent(byte current);
--- Sets the current on the indicator LED. The default iscurrent = 3
, or 8 mA.- 0: 1 mA
- 1: 2 mA
- 2: 4 mA
- 3: 8 mA
void enableBulb();
--- Powers on the surface mounted blue indicator LED.void disableBulb();
--- Powers off the surface mounted blue indicator LED.void setBulbCurrent(byte current);
--- Sets the current limit on the indicator LED and optional bulb (They are connected in parallel) The default iscurrent = 0
or 12.5 mA.- 0: 12.5 mA
- 1: 25 mA
- 2: 50 mA
- 3: 100 mA
void softReset();
--- Gives the sensor a 1 second reset.void setGain(byte gain);
--- Pass in a 0, 1, 2 or 3 to change the gain.- 0: 1x
- 1: 3.7x
- 2: 16x
- 3: 64x (power-on default)
void setIntegrationTime(byte integrationValue);
--- This sets the time over which samples are taken.- Takes a value between 0 and 255.
- Integration time will be 2.8 ms *
integrationValue
.
void enableInterrupt();
--- Pulls the interrupt pin low. (Note: not yet implemented)void disableInterrupt();
--- Pulls the interrupt pin high.- If you'd like access to just one channel, getting uncalibrated and calibrated spectral readings for the AS7262 (Visible) sensor can be accomplished with the following commands:
int getViolet();
int getBlue();
int getGreen();
int getYellow();
int getOrange();
int getRed();
float getCalibratedViolet();
float getCalibratedBlue();
float getCalibratedGreen();
float getCalibratedYellow();
float getCalibratedOrange();
float getCalibratedRed();
- A similar set of functions is available for accessing individual channels on the AS7263 (Near Infrared) sensor.
int getR();
int getS();
int getT();
int getU();
int getV();
int getW();
float getCalibratedR();
float getCalibratedS();
float getCalibratedT();
float getCalibratedU();
float getCalibratedV();
float getCalibratedW();