AS726X NIR/VIS Spectral Sensor Hookup Guide

Pages
Contributors: Englandsaurus
Favorited Favorite 3

Introduction

The AS726X Spectral Sensors from AMS brings a field of study to consumers that was previously unavailable, spectroscopy! It’s now easier than ever to measure and characterize how different materials absorb and reflect different wavelengths of light. Don’t know what part of the spectrum you want to look at? You’re in luck! Sparkfun carries two different flavors of spectrometer. The AS7262 detects wavelengths in the visible range while the AS7263 detects wavelengths just below the visible range, in the Near Infrared (NIR) range.

SparkFun Spectral Sensor Breakout - AS7262 Visible (Qwiic)

SEN-14347
$24.95
1
SparkFun Spectral Sensor Breakout - AS7263 NIR (Qwiic)

SEN-14351
$24.95
1

Required Materials

To follow along with this hookup guide, you will need one of the following Qwiic shields to match your preference of microcontroller:

SparkFun Qwiic Shield for Arduino

DEV-14352
$5.95
SparkFun Qwiic HAT for Raspberry Pi

DEV-14459
$4.95
1
SparkFun Qwiic Shield for Photon

DEV-14477
$4.95

You will also need a Qwiic cable to connect the shield to your AS726X, choose a length that suits your needs.

Qwiic Cable - 100mm

PRT-14427
$1.50
Qwiic Cable - 200mm

PRT-14428
$1.50
Qwiic Cable - 500mm

PRT-14429
$1.95
Qwiic Cable - 50mm

PRT-14426
$0.95

Suggested Reading

If you aren’t familiar with our new Qwiic system, we recommend reading here for an overview. We would also recommend taking a look at the following tutorials if you aren’t familiar with them.

How to Solder: Through-Hole Soldering

This tutorial covers everything you need to know about through-hole soldering.

Serial Communication

Asynchronous serial communication concepts: packets, signal levels, baud rates, UARTs and more!

Light

Light is a useful tool for the electrical engineer. Understanding how light relates to electronics is a fundamental skill for many projects.

I2C

An introduction to I2C, one of the main embedded communications protocols in use today.

Qwiic Shield for Arduino & Photon Hookup Guide

Get started with our Qwiic ecosystem with the Qwiic shield for Arduino or Photon.

Hardware Overview

The AS7262 detects 450, 500, 550, 570, 600, and 650nm of light each with 40nm of full-width half-max detection. The AS7263 can detect 610, 680, 730, 760, 810, and 860nm of light each with 20nm of full-width half-max detection.

Communication

The AS726X is unique as it can communicate by both an I2C interface (through the onboard Qwiic connectors, or pins at the bottom of the board) and serial interface using AT commands (pins at the top of the board).

Serial Ports

While I2C is the default setting (The default I2C address is 0x49 for both AS7262 and AS7263), serial communication via UART can be enabled by removing solder from the jumpers labeled JP1, adding solder to the jumper labeled JP2 (on the back of the board), and using Sparkfun’s USB-to-Serial breakout to interface directly with the computer.

Solder Jumper 1 Solder Jumper 2

LED

The board also has multiple ways for you to illuminate the object that you are trying to measure for a more accurate spectroscopy reading. There is an onboard, 5700K LED that has been picked out specifically for this task. However, if you aren’t satisfied with the onboard LED, you can grab your own through hole incandescent. While you should find a bulb rated for 3.3V, a bulb rated for higher voltage, like 5V, will still work, but will not run as bright as it normally would with 5V. We’ve found that Mouser is a good place to look for these. If you are going to go that route and use your own bulb, be sure to disable the onboard LED by removing the solder from the JP4 jumper.

Solder Jumper 4

Hardware Assembly

The beauty of Sparkfun’s new Qwiic environment means that connecting the sensor could not be easier. Just plug one end of the Qwiic cable into the AS726X, the other into one of the Qwiic Shields, and stack the board on a development board. You’ll be ready to upload a sketch to start taking spectroscopy measurements. It seems too easy, but thats why we made it this way! Here’s an example using the RedBoard Programmed with Arduino.

alt text

Library Overview

Before we get started, we’ll need to download and install SparkFun’s AS726X Arduino library.

Download the SparkFun AS726X Library

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 developing a sketch, let’s look at the available functions of the library.

  • void begin(TwoWire &wirePort, byte gain, byte measurementMode); — Initializes the sensor with user given values for the wire port, gain, and measurement
  • void takeMeasurements(); — Sensor writes spectral measurements to memory locations.
  • void takeMeasurementsWithBulb(); — Illuminates onboard bulb, calls takeMeasurements();, then turns off the onboard bulb.
  • void printMeasurements(); — Fetches data from memory and outputs calibrated measurements using Serial.print();
  • void printUncalibratedMeasurements(); — Fetches data from memory and outputs uncalibrated measurements using Serial.print();
  • 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(); — Returns true or false 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 is current = 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 is current = 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();

Example 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.

language:c
#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 I2C 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 I2C port (you can run the sensor on a different I2C port if you have the right hardware, a Teensy perhaps?).

language:c
#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)

Example Output for AS7262

Resources and Going Further

Now that you’ve successfully got your AS726X up and running, it’s time to incorporate it into your own project!

For more information, check out the resources below:

Using both the AS7263 NIR and AS7262 VIS sensors in the same I2C bus? Try using the Qwiic MUX board since they have the same I2C address!

New!

Qwiic MUX Hookup Guide

July 19, 2018

Have a bunch of sensors with the same I2C address? Put them on the Qwiic MUX (TCA9548A) to get them all talking on the same bus!

Need some inspiration for your next project? Check out some of these related tutorials:

Qwiic Adapter Hookup Guide

Get started with your Qwiic adapter board. This adapter breaks out the I2C pins from the Qwiic connectors to pins that you can easily solder with your favorite I2C enabled device.

Qwiic HAT for Raspberry Pi Hookup Guide

Get started interfacing your Qwiic enabled boards with your Raspberry Pi. This Qwiic connects the I2C bus (GND, 3.3V, SDA, and SCL) on your Raspberry Pi to an array of Qwiic connectors.

Qwiic Magnetometer (MLX90393) Hookup Guide

Figure out how magnetic fields are oriented, all without having to solder a thing.
New!

Qwiic Flex Glove Controller Hookup Guide

Is your finger bent? is your finger straight? The Qwiic Flex Glove controller board will answer this age old question for you.