The spectrometer sends data for 6 (12 or 18) spectral bands using the I2C communication bus.
Preparing the Arduino IDE
Arduino nano uses A4 and A5 for I2C connections as outlined in this GitHub repo,
Adafruit or sparkfun
Breakout boards with the AMD AS72Sx sensor(s) are offered both by Adafruit and Sparkfun. Sparkfun is easier to work with if you use their Qwiic connect system for I2C devices. You can then use the Qwiic Cable - Breadboard Jumper (4-pin) for connecting the spectrometer to the board. If you use the Adafruit spectrometer you have to solder the breakout board.
Wiring
The wiring is (almost) the same regardless if you use the Adafruit or Sparkfun breakout boards. The Adafruit manual is here.
The difference between Adafruit and Sparkfun is that the Sparkfun breakout board requires 3.3 v power, whereas the Adafruit breakout board can be powered with either 3.3 or 5 v. The Adafruit breakout board also has an additional light source that must be individually wired.
Sketch
The sketch below works both with the Adafruit and Sparkfun breakout boards.
/******
Sketch for the AS7262 6-Channel Visible Light Sensor
This sketch is a slight modification of the
adafruit original sketch. The sketch also works for the Sparkfun AS726x breakout board.
These sensors use I2C to communicate. The device's I2C address is 0x49
******/
#include <Wire.h>
#include "Adafruit_AS726x.h"
//create the object
Adafruit_AS726x ams;
//buffer to hold raw values
uint16_t sensorValues[AS726x_NUM_CHANNELS];
//buffer to hold calibrated values (not used by default in this example)
//float calibratedValues[AS726x_NUM_CHANNELS];
void setup() {
Serial.begin(9600);
while(!Serial);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
//begin and make sure we can talk to the sensor
if(!ams.begin()){
Serial.println("could not connect to sensor! Please check your wiring.");
while(1);
}
}
void loop() {
//read the device temperature
uint8_t temp = ams.readTemperature();
ams.drvOn(); //uncomment this if you want to use the driver LED for readings
ams.startMeasurement(); //begin a measurement
//wait till data is available
bool rdy = false;
while(!rdy){
delay(5);
rdy = ams.dataReady();
}
ams.drvOff(); //uncomment this if you want to use the driver LED for readings
//read the values!
ams.readRawValues(sensorValues);
//ams.readCalibratedValues(calibratedValues);
Serial.print("Temp: "); Serial.print(temp);
Serial.print(" Violet: "); Serial.print(sensorValues[AS726x_VIOLET]);
Serial.print(" Blue: "); Serial.print(sensorValues[AS726x_BLUE]);
Serial.print(" Green: "); Serial.print(sensorValues[AS726x_GREEN]);
Serial.print(" Yellow: "); Serial.print(sensorValues[AS726x_YELLOW]);
Serial.print(" Orange: "); Serial.print(sensorValues[AS726x_ORANGE]);
Serial.print(" Red: "); Serial.print(sensorValues[AS726x_RED]);
Serial.println();
Serial.println();
}