Example Code for Arduino-SYNS Mode

Last revision 2026/01/16

In SYNS mode, it is necessary to give a falling edge signal to the sensor's GPIO to trigger the measurement.The chip will enter idle mode when the measurement is done, which could save power.

Hardware Preparation

Software Preparation

Wiring Diagram

Connection Diagram

Other Preparation Work

Give a falling edge signal to the sensor's GPIO to trigger the measurement.

Sample Code

/*!
 * @file synsMode.ino
 * @brief Read spectrum data by syns mode. The chip's measurement function needs to be activated by a level pulse for each measurement.
    The chip will enter idle mode when the measurement is done, which could save power.
 * 
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 
 * @author [fengli]([email protected])
 * @version  V1.0
 * @date  2020-07-16
 * @get from https://www.dfrobot.com
 * @url https://github.com/DFRobot/DFRobot_AS7341
 */
#include "DFRobot_AS7341.h"
/*!
 * @brief Construct the function
 * @param pWire IC bus pointer object and construction device, can both pass or not pass parameters, Wire in default.
 */
DFRobot_AS7341 as7341;

void setup(void)
{
  Serial.begin(115200);
  //Detect if IIC can communicate properly
  while (as7341.begin(as7341.eSyns) != 0) {
    Serial.println("IIC init failed, please check if the wire connection is correct");
    delay(1000);
  }
  //Integration time = (ATIME + 1) x (ASTEP + 1) x 2.78µs
  //Set the value of register ATIME, through which the value of Integration time can be calculated. The value represents the time that must be spent during data reading.
  as7341.setAtime(29);
  //Set the value of register ASTEP, through which the value of Integration time can be calculated. The value represents the time that must be spent during data reading.
  as7341.setAstep(599);
  //Set gain value(0~10 corresponds to X0.5,X1,X2,X4,X8,X16,X32,X64,X128,X256,X512)
  as7341.setAGAIN(7);
  as7341.startMeasure(as7341.eF1F4ClearNIR);
}

DFRobot_AS7341::sModeOneData_t data1;

void loop(void)
{
  //If the sensor has data to read, then read and print the data.
  if(as7341.measureComplete()){
    //Read the value of sensor data channel 0~5, under eF1F4ClearNIR
    data1 = as7341.readSpectralDataOne();
    Serial.print("F1(405-425nm):");
    Serial.println(data1.ADF1);
    Serial.print("F2(435-455nm):");
    Serial.println(data1.ADF2);
    Serial.print("F3(470-490nm):");
    Serial.println(data1.ADF3);
    Serial.print("F4(505-525nm):");   
    Serial.println(data1.ADF4);
    Serial.print("Clear:");
    Serial.println(data1.ADCLEAR);
    Serial.print("NIR:");
    Serial.println(data1.ADNIR);
  }
}

Result

SEN0365result3

Was this article helpful?

TOP