Product Overview

1/31/2018 AS726X NIR/VIS Spectral Sensor Hookup Guide - learn.sparkfun.com
https://learn.sparkfun.com/tutorials/as726x-nirvi?_ga=2.149930550.1022152466.1517244327-204410570.1509632255 7/8
COPY CODE
COPY CODE
Example 1 — Basic Readings
The below sketch will get you up and running taking calibrated spectral readings on all 6 channels. Once this sketch
is uploaded, open the serial monitor with a baud rate of 115200 to display the spectral data from the sensor.
#include "AS726X.h"
AS726X sensor;
void setup() {
sensor.begin();
}
void loop() {
sensor.takeMeasurements();
sensor.printMeasurements();//Prints out all measurements (calibrated)
}
If we want, we can change the gain, measurement mode, and Wire that I C uses by calling the begin() function
with a few arguments. First, let’s look at what values we can assign to which characteristic.
Example 2 — Sensor Settings
The below example code will initialize our sensor with a gain of 16x, measurement mode of 0, and our regular I C
port (you can run the sensor on a different I C port if you have the right hardware, a Teensy perhaps?).
#include "AS726X.h"
AS726X sensor;
byte GAIN = 2;
byte MEASUREMENT_MODE = 0;
void setup() {
sensor.begin(Wire, GAIN, MEASUREMENT_MODE);
}
void loop() {
sensor.takeMeasurements();
sensor.printMeasurements();
}
Expected Output
Here is a picture of what to expect when bringing your AS726X online for either of the above sketches. (The program
will print “AS7263 online!” instead if you have that sensor)
2
2
2